Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.log.info('Loading config: %s', filename)
if config_type in ("machine", "mode"):
self._check_sections(config, config_type, filename, ignore_unknown_sections)
try:
if 'config' in config:
path = os.path.split(filename)[0]
for file in Util.string_to_list(config['config']):
full_file = os.path.join(path, file)
subfiles.append(full_file)
subconfig, subsubfiles = self._load_config_file_and_return_loaded_files(full_file, config_type)
subfiles.extend(subsubfiles)
config = Util.dict_merge(config, subconfig)
return config, subfiles
except TypeError:
return dict(), []
def load_config_file(filename, verify_version=True, halt_on_error=True):
config = FileManager.load(filename, verify_version, halt_on_error)
try:
if 'config' in config:
path = os.path.split(filename)[0]
for file in Util.string_to_list(config['config']):
full_file = os.path.join(path, file)
config = Util.dict_merge(config,
Config.load_config_file(
full_file))
return config
except TypeError:
return dict()
def _load_config_from_files(self):
self.log.info("Loading config from original files")
self.config = self._get_mpf_config()
self.config['_mpf_version'] = __version__
for num, config_file in enumerate(self.options['configfile']):
if not (config_file.startswith('/') or
config_file.startswith('\\')):
config_file = os.path.join(self.machine_path, self.config['mpf']['paths']['config'], config_file)
self.log.info("Machine config file #%s: %s", num + 1, config_file)
self.config = Util.dict_merge(self.config,
ConfigProcessor.load_config_file(
config_file,
config_type='machine'))
self.machine_config = self.config
if self.options['create_config_cache']:
self._cache_config()
load_from_cache = False
self.log.warning('Config file in cache changed: %s', configfile)
break
# Step 4: Return cache
if load_from_cache:
return config
config = dict()
loaded_files = []
for configfile in filenames:
self.log.info('Loading config from file %s.', configfile)
file_config, file_subfiles = self._load_config_file_and_return_loaded_files(configfile, config_type,
ignore_unknown_sections)
loaded_files.extend(file_subfiles)
config = Util.dict_merge(config, file_config)
# Step 5: Store to cache
if store_to_cache:
with open(cache_file, 'wb') as f:
pickle.dump((config, loaded_files), f, protocol=4)
self.log.info('Config file cache created: %s', cache_file)
return config
except KeyError:
pass
# Now figure out if there's a machine-specific config for this mode,
# and if so, merge it into the config
try:
mode_config_file = os.path.join(
self.machine.machine_path,
self.machine.config['mpf']['paths']['modes'],
self._machine_mode_folders[mode_string],
'config',
self._machine_mode_folders[mode_string] + '.yaml')
if os.path.isfile(mode_config_file):
config = Util.dict_merge(config,
ConfigProcessor.load_config_file(
mode_config_file, 'mode'))
if self.debug:
self.log.debug("Loading config from %s", mode_config_file)
except KeyError:
pass
# validate config
if 'mode' not in config:
config['mode'] = dict()
return config
def _load_config_from_files(self):
self.log.info("Loading config from original files")
self.config = self._get_mpf_config()
self.config['_mpf_version'] = __version__
for num, config_file in enumerate(self.options['configfile']):
if not (config_file.startswith('/') or
config_file.startswith('\\')):
config_file = os.path.join(self.machine_path, self.config['mpf']['paths']['config'], config_file)
self.log.info("Machine config file #%s: %s", num + 1, config_file)
self.config = Util.dict_merge(self.config,
ConfigProcessor.load_config_file(
config_file,
config_type='machine'))
self.machine_config = self.config
if self.options['create_config_cache']:
self._cache_config()
if result_type == 'list':
processed_config = self.validate_config_item2(
this_spec[k],
validation_failure_info=(
validation_failure_info,
k))
else:
processed_config[k] = self.validate_config_item2(
this_spec[k],
validation_failure_info=(
validation_failure_info,
k))
if target:
processed_config = Util.dict_merge(target, processed_config)
return processed_config