vban-cmd-python/vbancmd/util.py
onyx-and-iris 3aebd90920 refactor meta functions
add channel_bool_prop and channel_label_prop to strip/bus
self.identifier in strip bus now returning only class name

add psuedo decorators cache_bool and cache_string to util.

fix bug with cache
todo. add to cache on multi-set
2022-04-29 02:57:47 +01:00

57 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:
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"""
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 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