Compare commits
2 Commits
d504156123
...
eac4e8785f
Author | SHA1 | Date |
---|---|---|
Nicholas Hope | eac4e8785f | |
Nicholas Hope | 15b737a5c8 |
6
cli.py
6
cli.py
|
@ -11,12 +11,8 @@ import verify
|
|||
|
||||
def parseFile(inputFile):
|
||||
"""Parse, verify, and do the conversion."""
|
||||
config = {}
|
||||
|
||||
config = yaml.safe_load(inputFile)
|
||||
|
||||
aliases = bool("aliases" in config)
|
||||
|
||||
# See verify.py
|
||||
config = verify.verifyConfig(config)
|
||||
if "errors" in config:
|
||||
|
@ -52,6 +48,6 @@ if __name__ == "__main__":
|
|||
help="Parse input file, but don't write anything.")
|
||||
# positional argument: first non-hyphenated argument is input file
|
||||
parser.add_argument( 'infile', type=argparse.FileType('r'),
|
||||
help='File containing YAML to convert. Default: "example.yaml"')
|
||||
help='File containing YAML to convert.')
|
||||
args = parser.parse_args()
|
||||
parseFile(args.infile)
|
41
verify.py
41
verify.py
|
@ -1,12 +1,36 @@
|
|||
def verifyConfig(cfg: dict):
|
||||
|
||||
# Do aliases first
|
||||
aliasErrors = []
|
||||
|
||||
aliases = None
|
||||
|
||||
if "aliases" in cfg:
|
||||
aliases = cfg.pop("aliases")
|
||||
for key, data in aliases.items():
|
||||
errMessages = validBind(key, data)
|
||||
if len(errMessages) > 0:
|
||||
for msg in errMessages:
|
||||
errors.append("Error in aliases: %s" % (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 += aliasErrors
|
||||
|
||||
if len(errors) > 0:
|
||||
cfg.update({"errors": errors})
|
||||
|
||||
|
@ -17,15 +41,15 @@ def validBind(key, data) -> list:
|
|||
if not validKey(key):
|
||||
ret.append('Invalid key "%s"' % (key))
|
||||
|
||||
data, errMsgs = validBindType(data)
|
||||
data, errMsgs = validBindType(key, data)
|
||||
if len(errMsgs) > 0:
|
||||
for msg in errMsgs:
|
||||
ret.append(msg)
|
||||
|
||||
extras = extraFields(data)
|
||||
extras = data.keys()
|
||||
if len(extras) > 0:
|
||||
extrasString = "\n\t".join(extras)
|
||||
ret.append('Extra fields in "%s":\n\t%s' % (key, extrasString))
|
||||
ret.append('Unused fields in "%s":\n\t%s' % (key, extrasString))
|
||||
|
||||
return ret
|
||||
|
||||
|
@ -39,7 +63,7 @@ def validKey(key):
|
|||
return False
|
||||
return True
|
||||
|
||||
def validBindType(data: dict) -> (dict, list):
|
||||
def validBindType(key, data: dict) -> (dict, list):
|
||||
validType = False
|
||||
types = [
|
||||
"impulse",
|
||||
|
@ -54,6 +78,9 @@ def validBindType(data: dict) -> (dict, list):
|
|||
validType = True
|
||||
data, errMsgs = removeRelaventFields(data, potentialType)
|
||||
break
|
||||
|
||||
if not validType:
|
||||
errMsgs.append('Key "%s" has no known bind type' % (key))
|
||||
|
||||
return data, errMsgs
|
||||
|
||||
|
@ -71,8 +98,4 @@ def removeRelaventFields(data, bindType) -> (dict, list):
|
|||
if "condition" not in data:
|
||||
errMsgs.append("Double requires condition to toggle")
|
||||
|
||||
return data, errMsgs
|
||||
|
||||
def extraFields(data) -> list:
|
||||
return data.keys()
|
||||
|
||||
return data, errMsgs
|
Loading…
Reference in New Issue