mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2024-11-15 17:10:46 +00:00
ce48136cdb
sub apply func now using sendtext depth func added to util apply_profile now using sub apply (which uses sendtext)
62 lines
1.5 KiB
Python
62 lines
1.5 KiB
Python
from pathlib import Path
|
|
|
|
|
|
PROJECT_DIR = str(Path(__file__).parents[1])
|
|
|
|
|
|
def project_path():
|
|
return PROJECT_DIR
|
|
|
|
|
|
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:
|
|
return self._remote.cache.pop(cmd) == 1
|
|
return func(*args, **kwargs)
|
|
|
|
return wrapper
|
|
|
|
|
|
def cache_string(func, param):
|
|
"""Check cache for a string prop"""
|
|
|
|
def wrapper(*args, **kwargs):
|
|
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)
|
|
|
|
return wrapper
|
|
|
|
|
|
def depth(d):
|
|
if isinstance(d, dict):
|
|
return 1 + (max(map(depth, d.values())) if d else 0)
|
|
return 0
|
|
|
|
|
|
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
|