def test_read_mixed_case_options(): updater = ConfigUpdater() updater.read_string(test15_cfg_in) assert updater.has_option('section', 'OptionA') assert updater.has_option('section', 'optiona') assert updater['section']['OptionA'].value == '2' assert updater['section']['optiona'].value == '2'
def test_read_mixed_case_options(): updater = ConfigUpdater() updater.read_string(test15_cfg_in) assert updater.has_option("section", "OptionA") assert updater.has_option("section", "optiona") assert updater["section"]["OptionA"].value == "2" assert updater["section"]["optiona"].value == "2"
def write_config_updater(path: Path, config: ConfigUpdater) -> None: """Write the config file.""" to_write_config = copy.deepcopy(config) # Do not save the pwd if that's not wanted! if (config.has_option("discovergy_account", "save_password") and not config.get("discovergy_account", "save_password").value): to_write_config.set("discovergy_account", "password", value="") with os.fdopen(os.open(path.as_posix(), os.O_WRONLY | os.O_CREAT, 0o600), "w") as fh: to_write_config.write(fh)
def test_has_option(setup_cfg_path): updater = ConfigUpdater() updater.read(setup_cfg_path) assert updater.has_option('metadata', 'author') assert not updater.has_option('metadata', 'coauthor') assert not updater.has_option('nonexistent_section', 'key')
def test_has_option(setup_cfg_path): updater = ConfigUpdater() updater.read(setup_cfg_path) assert updater.has_option("metadata", "author") assert not updater.has_option("metadata", "coauthor") assert not updater.has_option("nonexistent_section", "key")
continue for key in values[sec]: if values[sec][key] == 'comment_out' and updater[sec].get(key): logger.debug('commenting out [{}]->{}={}'.format( sec, key, updater[sec][key].value)) updater[sec][key].key = '#{}'.format(key) else: logger.debug('setting [{}]->{}={}'.format(sec, key, values[sec][key])) updater[sec][key] = values[sec][key] if values.get('_global_'): for key in values.get('_global_'): for secname in updater.sections(): if updater.has_option(secname, key): if values['_global_'][key] == 'comment_out' and updater[ secname].get(key): logger.debug('commenting out [{}]->{}={}'.format( secname, key, updater[secname][key].value)) updater[secname][key].key = '#{}'.format(key) else: updater[secname][key] = values['_global_'][key] logger.debug('{} found in [{}] setting to {}'.format( key, secname, values['_global_'][key])) if args.get('output'): logger.debug('writing output: {}'.format(args.get('output'))) output_file_handle = open(args['output'], 'w') else: logger.debug('writing output: stdout')