def read(system_path: str, user_path: str) -> dict: """Reads specified yaml configuration files Args: system_path: Full path to system wide YAML config file user_path: Full path to users YAML config file Returns: A dictionary filled with system settings, overlapped with the user specific settings """ ret = {} if system_path: ret = merge_dictionaries( ret, fops.file_read_convert(system_path, 'yaml', True)) if user_path: ret = merge_dictionaries( ret, fops.file_read_convert(user_path, 'yaml', True)) return ret
def run() -> None: """Run functionality.""" # pylint: disable=global-statement global _DEBUG args = do_args() _DEBUG = args.debug_log setup_app_logging(args.debug_log) if args.version_out: do_version() if args.setup: do_setup() files, licenses = load_files_and_licenses() if args.list_file_types: do_print_file_types(files) if args.list_licenses: do_print_license_types(licenses) config = merge_dictionaries(DEFAULTS, fops.file_read_convert(CONFIG_FILE_PATH, fops.YAML, True)) config = verify_config(config, args) if not files.get(config.get('file_type')): LOGGER.error("unsupported file type: %s", config.get('file_type')) raise SystemExit(-1) if not licenses.get(config.get('license')): LOGGER.error("unsupported license type: %s", config.get('license)')) raise SystemExit(-1) license_obj = licenses.get(config.get('license')) new_file = files.get(config.get('file_type')).new(config, license_obj) new_file.write()
def load_config(path: str, defaults: dict) -> DictObj: """Loads the configuration file and any project files loaded in projects_folder if defined Args: path: full path to config file defaults: dictionary filled with default settings Returns: DictObj filled with settings from config files """ try: settings = Settings(defaults, path, '').get_all() except FileNotFoundError as exception_object: raise FileNotFoundError( "{0!s}: not found".format(path)) from exception_object except IOError as exception_object: raise IOError("{0!s}: not a file".format(path)) from exception_object return DictObj( merge_dictionaries( settings, load_projects_folder( path, settings.get('backup', dict()).get('projects_folder'))))
def __init__(self, defaults: dict, user_path: str = None, sys_path: str = None) -> None: self._settings = merge_dictionaries(defaults, self.read(sys_path, user_path))
def test_merge_dictionaries(self): tests = [ { 'dict_a': dict(), 'dict_b': { 'test': 'test' }, 'want': { 'test': 'test' } }, { 'dict_a': { 'test': 'test2' }, 'dict_b': { 'test': 'test' }, 'want': { 'test': 'test' } }, { 'dict_a': { 'test': { 'test2': dict(), } }, 'dict_b': { 'test': { 'test2': ['test', 'test'] } }, 'want': { 'test': { 'test2': ['test', 'test'] } } }, { 'dict_a': { 'test': { 'test2': { 'test3': 'test4' } } }, 'dict_b': { 'test': { 'test2': { 'test5': { 'test6': 'test7' } } }, 'test8': { 'test9': 'test10' } }, 'want': { 'test': { 'test2': { 'test3': 'test4', 'test5': { 'test6': 'test7' }, }, }, 'test8': { 'test9': 'test10' } } } ] for test in tests: got = merge.merge_dictionaries(test['dict_a'], test['dict_b']) self.assertDictEqual(got, test['want'])