Corrected double-type verification, changed % evaluation to f-strings
parent
eb0fa85d77
commit
365dee3c2b
32
verify.py
32
verify.py
|
@ -9,26 +9,19 @@ def verifyConfig(cfg: dict):
|
|||
if "aliases" in cfg:
|
||||
aliases = cfg.pop("aliases")
|
||||
for key, data in aliases.items():
|
||||
errMessages = validBind(key, data)
|
||||
errMessages = validBind(key, data, alias = True)
|
||||
if len(errMessages) > 0:
|
||||
for msg in errMessages:
|
||||
aliasErrors.append("Error in aliases: %s" % (msg))
|
||||
aliasErrors.append(f"Error in aliases: {msg}")
|
||||
|
||||
errors = []
|
||||
|
||||
for cclass in cfg:
|
||||
for key, data in cfg[cclass].items():
|
||||
# Replace aliases with their expansion
|
||||
if aliases is not None:
|
||||
# this no work: fix pls
|
||||
if "alias" in data:
|
||||
data["alias"] = aliases
|
||||
pass
|
||||
|
||||
errMessages = validBind(key, data)
|
||||
if len(errMessages) > 0:
|
||||
for msg in errMessages:
|
||||
errors.append("Error in %s: %s" % (cclass, msg))
|
||||
errors.append(f"Error in {cclass}: {msg}")
|
||||
|
||||
errors += aliasErrors
|
||||
|
||||
|
@ -37,11 +30,11 @@ def verifyConfig(cfg: dict):
|
|||
|
||||
return cfg
|
||||
|
||||
def validBind(key, data) -> list:
|
||||
def validBind(key, data, alias = False) -> list:
|
||||
"""Check for valid key and valid binding"""
|
||||
ret = []
|
||||
if not validKey(key):
|
||||
ret.append('Invalid key "%s"' % (key))
|
||||
if (not alias and not validKey(key)):
|
||||
ret.append(f'Invalid key "{key}"')
|
||||
|
||||
data, errMsgs = validBindType(key, data)
|
||||
if len(errMsgs) > 0:
|
||||
|
@ -51,7 +44,7 @@ def validBind(key, data) -> list:
|
|||
extras = data.keys()
|
||||
if len(extras) > 0:
|
||||
extrasString = "\n\t".join(extras)
|
||||
ret.append('Unused fields in "%s":\n\t%s' % (key, extrasString))
|
||||
ret.append(f'Unused fields in "{key}":\n\t{extrasString}')
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -83,7 +76,7 @@ def validBindType(key, data: dict):
|
|||
break
|
||||
|
||||
if not validType:
|
||||
errMsgs.append('Key "%s" has no known bind type' % (key))
|
||||
errMsgs.append(f'Key "{key}" has no known bind type')
|
||||
|
||||
return data, errMsgs
|
||||
|
||||
|
@ -94,11 +87,14 @@ def removeRelaventFields(data, bindType):
|
|||
data.pop(bindType)
|
||||
|
||||
elif bindType == "double":
|
||||
if "primary" not in data["double"]:
|
||||
content = data.pop("double")
|
||||
if "primary" not in content:
|
||||
errMsgs.append("Double requires primary action")
|
||||
if "secondary" not in data["double"]:
|
||||
else:
|
||||
errMessages = validBind("primary", content)
|
||||
if "secondary" not in content:
|
||||
errMsgs.append("Double requires secondary action")
|
||||
if "condition" not in data:
|
||||
if "condition" not in content:
|
||||
errMsgs.append("Double requires condition to toggle")
|
||||
|
||||
return data, errMsgs
|
||||
|
|
Loading…
Reference in New Issue