mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2024-11-16 01:10:48 +00:00
b9db01c8f4
now packaged with poetry. added to pypi. major version bump due to dependency change. interface reworked to match the remote-api interface. readme updated with changes to installation pre-commit hook temporarily removed
52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
def cache_bool(func, param):
|
|
"""Check cache for a bool prop"""
|
|
|
|
def wrapper(*args, **kwargs):
|
|
self, *rem = args
|
|
cmd = f"{self.identifier}.{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}.{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
|