mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
修改环境变量加载逻辑
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import os
|
||||
import re
|
||||
import env
|
||||
|
||||
|
||||
def try_parse_int(value):
|
||||
try:
|
||||
return int(value)
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def expand_range(range_str, max_value):
|
||||
temp_range_str = (
|
||||
range_str.strip()
|
||||
.replace("-max", f"-{max_value}")
|
||||
.replace("max-", f"{max_value}-")
|
||||
)
|
||||
|
||||
result = []
|
||||
for part in temp_range_str.split(" "):
|
||||
range_match = re.match(r"^(\d+)([-~_])(\d+)$", part)
|
||||
if range_match:
|
||||
start, _, end = map(try_parse_int, range_match.groups())
|
||||
result.extend(range(start, end + 1))
|
||||
else:
|
||||
result.append(int(part))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def run():
|
||||
env_param = os.getenv("envParam")
|
||||
num_param = os.getenv("numParam")
|
||||
|
||||
if env_param and num_param:
|
||||
array = (os.getenv(env_param) or "").split("&")
|
||||
run_arr = expand_range(num_param, len(array))
|
||||
array_run = [array[i - 1] for i in run_arr if i - 1 < len(array) and i > 0]
|
||||
env_str = "&".join(array_run)
|
||||
os.environ[env_param] = env_str
|
||||
|
||||
|
||||
run()
|
||||
Reference in New Issue
Block a user