2022-03-23 11:28:42 +00:00
|
|
|
from pathlib import Path
|
|
|
|
|
2022-04-29 02:57:47 +01:00
|
|
|
|
2022-03-23 11:28:42 +00:00
|
|
|
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-04-29 02:57:47 +01:00
|
|
|
def cache_bool(func, param):
|
|
|
|
"""Check cache for a bool prop"""
|
|
|
|
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
self, *rem = args
|
|
|
|
cmd = f"{self.identifier}[{self.index}].{param}"
|
|
|
|
if cmd in self._remote.cache:
|
|
|
|
print(self._remote.cache[cmd] == 1)
|
|
|
|
return self._remote.cache.pop(cmd) == 1
|
|
|
|
return func(*args, **kwargs)
|
|
|
|
|
|
|
|
return wrapper
|
|
|
|
|
|
|
|
|
|
|
|
def cache_string(func, param):
|
|
|
|
"""Check cache for a string prop"""
|
2022-03-26 23:00:09 +00:00
|
|
|
|
2022-03-20 12:25:50 +00:00
|
|
|
def wrapper(*args, **kwargs):
|
2022-04-29 02:57:47 +01:00
|
|
|
self, *rem = args
|
|
|
|
cmd = f"{self.identifier}[{self.index}].{param}"
|
|
|
|
if cmd in self._remote.cache:
|
|
|
|
return self._remote.cache.pop(cmd)
|
|
|
|
return func(*args, **kwargs)
|
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
|