2022-03-23 11:28:42 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
PROJECT_DIR = str(Path(__file__).parents[1])
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-23 11:28:42 +00:00
|
|
|
def project_path():
|
|
|
|
return PROJECT_DIR
|
|
|
|
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def cache(func):
|
2022-03-26 23:00:09 +00:00
|
|
|
"""check if recently cached was an updated value"""
|
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
# setup cache check
|
|
|
|
res = func(*args, **kwargs)
|
|
|
|
# update cache
|
|
|
|
return res
|
2022-03-26 23:00:09 +00:00
|
|
|
|
|
|
|
return wrapper
|
2022-04-27 14:50:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
def script(func):
|
|
|
|
"""Convert dictionary to script"""
|
|
|
|
|
|
|
|
def wrapper(*args):
|
|
|
|
remote, script = args
|
|
|
|
if isinstance(script, dict):
|
|
|
|
params = ""
|
|
|
|
for key, val in script.items():
|
|
|
|
obj, m2, *rem = key.split("-")
|
|
|
|
index = int(m2) if m2.isnumeric() else int(*rem)
|
|
|
|
params += ";".join(
|
|
|
|
f"{obj}{f'.{m2}stream' if not m2.isnumeric() else ''}[{index}].{k}={int(v) if isinstance(v, bool) else v}"
|
|
|
|
for k, v in val.items()
|
|
|
|
)
|
|
|
|
params += ";"
|
|
|
|
script = params
|
|
|
|
return func(remote, script)
|
|
|
|
|
|
|
|
return wrapper
|