mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
45 lines
1.0 KiB
Python
45 lines
1.0 KiB
Python
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()
|