Added warnings
parent
ace0af7101
commit
0bbca21fea
|
@ -38,6 +38,12 @@ def parseFile(inputFile) -> (dict, dict):
|
||||||
|
|
||||||
# See verify.py
|
# See verify.py
|
||||||
config, defaults = verify.verifyConfig(config)
|
config, defaults = verify.verifyConfig(config)
|
||||||
|
if 'warnings' in config:
|
||||||
|
for cclass, messages in config.pop('warnings').items():
|
||||||
|
print(f'Warning in {cclass}:', file=stderr)
|
||||||
|
for msg in messages:
|
||||||
|
print(f' {msg}', file=stderr)
|
||||||
|
|
||||||
if 'errors' in config:
|
if 'errors' in config:
|
||||||
for cclass, messages in config['errors'].items():
|
for cclass, messages in config['errors'].items():
|
||||||
print(f'Error in {cclass}:', file=stderr)
|
print(f'Error in {cclass}:', file=stderr)
|
||||||
|
|
|
@ -6,6 +6,7 @@ def verifyConfig(cfg: dict) -> (dict, dict):
|
||||||
verifiedConfig = {}
|
verifiedConfig = {}
|
||||||
|
|
||||||
errors = {}
|
errors = {}
|
||||||
|
warnings = {}
|
||||||
|
|
||||||
# Do defaults first
|
# Do defaults first
|
||||||
defaults = []
|
defaults = []
|
||||||
|
@ -26,28 +27,27 @@ def verifyConfig(cfg: dict) -> (dict, dict):
|
||||||
for isclass, class_ in enumerate(classList):
|
for isclass, class_ in enumerate(classList):
|
||||||
|
|
||||||
classCFG = None
|
classCFG = None
|
||||||
classBinds = []
|
|
||||||
className = class_
|
className = class_
|
||||||
|
|
||||||
if isinstance(class_, str) and class_ in cfg:
|
if isinstance(class_, str) and class_ in cfg:
|
||||||
classCFG = cfg.pop(class_)
|
classCFG = cfg.pop(class_)
|
||||||
|
|
||||||
elif isinstance(class_, tuple):
|
elif isinstance(class_, tuple):
|
||||||
for tupClass in class_:
|
for tupClass in class_:
|
||||||
if tupClass in cfg:
|
if tupClass in cfg:
|
||||||
classCFG = cfg.pop(tupClass)
|
classCFG = cfg.pop(tupClass)
|
||||||
className = class_[0]
|
className = class_[0]
|
||||||
break
|
break
|
||||||
|
|
||||||
if classCFG is None:
|
if classCFG is None:
|
||||||
# Invalid class, this gets caught later.
|
# Invalid class, this gets caught later.
|
||||||
# It may be less efficient this way, but
|
# It may be less efficient this way, but
|
||||||
# it makes for more descriptive error messages
|
# it makes for more descriptive error messages
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
classBinds = []
|
||||||
errMessages = []
|
errMessages = []
|
||||||
|
warnMessages = []
|
||||||
for key, data in classCFG.items():
|
for key, data in classCFG.items():
|
||||||
bind = tftypes.bind(key, data)
|
bind = tftypes.Bind(key, data)
|
||||||
|
|
||||||
bind = bind.toTargetType()
|
bind = bind.toTargetType()
|
||||||
if isclass:
|
if isclass:
|
||||||
|
@ -56,9 +56,12 @@ def verifyConfig(cfg: dict) -> (dict, dict):
|
||||||
defaults.append(bind)
|
defaults.append(bind)
|
||||||
|
|
||||||
errMessages.extend(bind.errors)
|
errMessages.extend(bind.errors)
|
||||||
|
warnMessages.extend(bind.warnings)
|
||||||
|
|
||||||
if len(errMessages) > 0:
|
if len(errMessages) > 0:
|
||||||
errors.update( {className: errMessages} )
|
errors.update( {className: errMessages} )
|
||||||
|
if len(warnMessages) > 0:
|
||||||
|
warnings.update( {className: warnMessages} )
|
||||||
|
|
||||||
verifiedConfig.update({className: classBinds})
|
verifiedConfig.update({className: classBinds})
|
||||||
|
|
||||||
|
@ -82,6 +85,8 @@ def verifyConfig(cfg: dict) -> (dict, dict):
|
||||||
|
|
||||||
if len(errors) > 0:
|
if len(errors) > 0:
|
||||||
verifiedConfig.update({'errors': errors})
|
verifiedConfig.update({'errors': errors})
|
||||||
|
if len(warnings) > 0:
|
||||||
|
verifiedConfig.update({'warnings': warnings})
|
||||||
|
|
||||||
return verifiedConfig, defaults
|
return verifiedConfig, defaults
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue