logger.info(f"Loaded template config from {template_config_path}.")
# Check if config contains required fields in example config
for key in template_config:
if key != 'optional':
assert key in config
except FileNotFoundError:
logger.error(f"No config file found at {template_config_path}! ")
raise
except AssertionError:
logger.error(f"Required config fields from {template_config_path} do not match {config.keys()}")
raise
# Check if config contains required fields in example config
missing = [key for key in template_config if key not in config and key != 'optional']
if missing:
err_msg = f"Required keys missing: {missing}"
logger.error(err_msg)
raise ValueError(err_msg)
# Check if optional field available
if 'optional' not in config:
if 'optional' not in config or config['optional'] != dict:
logger.info(f'No "optional" field found or no valid configuration for config.yaml.')
config['optional'] = {}
# Check optional fields and include in config if not present
for optkey, value in template_config['optional'].items():
if optkey not in config['optional']:
config['optional'][optkey] = value
logger.info(f"Added optional field: \"{optkey}\" with value: \"{value}\" to config.")
logger.info(f'Set default value for optional parameter "{optkey}" to : "{value}"')
# Parse YAML rule config file
if 'rule_config' in config['optional'] and config['optional']['rule_config']:
try:
with open(config['optional']['rule_config']) as _file:
rule_config = yaml.safe_load(_file)
logger.info(f"Loaded rule_config from {config['optional']['rule_config']}.")
except FileNotFoundError:
logger.error(f"No rule config file found at {config['optional']['rule_config']}. Either provide file or remove rule_config parameter from config.yaml! ")
raise
else:
try:
with open(config['optional']['rule_config']) as _file:
rule_config = yaml.safe_load(_file)
logger.info(f"Loaded rule_config from {config['optional']['rule_config']}.")
except TypeError:
logger.error(f'No string supplied at field "rule_config", but: {config["optional"]["rule_config"]}')
except FileNotFoundError:
logger.error(f"No rule config file found at {config['optional']['rule_config']}. Either provide file or remove rule_config parameter from config.yaml! ")
raise
except KeyError:
rule_config = {}
logger.warning(f"No rule config specified: using default values for all tools.")