Python six.moves.configparser.SafeConfigParser() Examples
The following are 19
code examples of six.moves.configparser.SafeConfigParser().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
six.moves.configparser
, or try the search function
.
Example #1
Source File: conf.py From osbs-client with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, conf_file=DEFAULT_CONFIGURATION_FILE, conf_section=DEFAULT_CONFIGURATION_SECTION, cli_args=None, **kwargs): """ sample initialization: Configuration("./osbs.conf", "fedora", openshift_uri="https://localhost:8443/", username="admin", password="something") :param conf_file: str, path to configuration file, or None for no configuration file :param conf_section: str, name of section with configuration for requested instance :param cli_args: instance of argument parser of argparse :param kwargs: keyword arguments, which have highest priority: key is cli argument name """ self.scp = configparser.SafeConfigParser() if conf_file and os.path.isfile(conf_file) and os.access(conf_file, os.R_OK): self.scp.read(conf_file) if not self.scp.has_section(conf_section): logger.warning("Specified section '%s' not found in '%s'", conf_section, conf_file) self.conf_section = conf_section self.args = cli_args self.kwargs = kwargs
Example #2
Source File: parser.py From pipenv with MIT License | 6 votes |
def parse(self): """ :return: """ parser = SafeConfigParser() parser.readfp(StringIO(self.obj.content)) for section in parser.sections(): try: content = parser.get(section=section, option="deps") for n, line in enumerate(content.splitlines()): if self.is_marked_line(line): continue if line: req = RequirementsTXTLineParser.parse(line) if req: req.dependency_type = self.obj.file_type self.obj.dependencies.append(req) except NoOptionError: pass
Example #3
Source File: utils.py From zget with MIT License | 6 votes |
def config(): """ Reads config values from zget.cfg or zget.ini """ config = configparser.SafeConfigParser( defaults={ 'port': '0', 'interface': None, }, allow_no_value=True ) config.read([ '.zget.cfg', os.path.expanduser('~/.zget.cfg'), os.path.join(os.getenv('APPDATA', ''), 'zget', 'zget.ini'), ]) return config
Example #4
Source File: test_util.py From keras-lambda with MIT License | 5 votes |
def config_from_ini(self, ini): config = {} parser = configparser.SafeConfigParser() ini = textwrap.dedent(six.u(ini)) parser.readfp(io.StringIO(ini)) for section in parser.sections(): config[section] = dict(parser.items(section)) return config
Example #5
Source File: test_util.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def config_from_ini(self, ini): config = {} parser = configparser.SafeConfigParser() ini = textwrap.dedent(six.u(ini)) parser.readfp(io.StringIO(ini)) for section in parser.sections(): config[section] = dict(parser.items(section)) return config
Example #6
Source File: cli.py From bazarr with GNU General Public License v3.0 | 5 votes |
def __init__(self, path): #: Path to the configuration file self.path = path #: The underlying configuration object self.config = configparser.SafeConfigParser() self.config.add_section('general') self.config.set('general', 'languages', json.dumps(['en'])) self.config.set('general', 'providers', json.dumps(sorted([p.name for p in provider_manager]))) self.config.set('general', 'refiners', json.dumps(sorted([r.name for r in refiner_manager]))) self.config.set('general', 'single', str(0)) self.config.set('general', 'embedded_subtitles', str(1)) self.config.set('general', 'age', str(int(timedelta(weeks=2).total_seconds()))) self.config.set('general', 'hearing_impaired', str(1)) self.config.set('general', 'min_score', str(0))
Example #7
Source File: __main__.py From c4ddev with MIT License | 5 votes |
def load_cfg(): cfg = SafeConfigParser() if os.path.isfile(cfg_filename): cfg.read([cfg_filename]) return cfg
Example #8
Source File: runtime.py From treadmill with Apache License 2.0 | 5 votes |
def _load_config(config_file): """Load the linux runtime configuration. """ cp = configparser.SafeConfigParser() with io.open(config_file) as f: cp.readfp(f) # pylint: disable=deprecated-method conf = { 'host_mount_whitelist': cp.get( 'linux', 'host_mount_whitelist', fallback='' ).split(',') } return utils.to_obj(conf)
Example #9
Source File: diskbenchmark.py From treadmill with Apache License 2.0 | 5 votes |
def write(benchmark_result_file, result): """Write benchmark result. Sample output file format: [device0] device = 589d88bd-8098-4041-900e-7fcac18abab3 write_bps = 314572800 read_bps = 314572800 write_iops = 64000 read_iops = 4000 :param benchmark_result_file: benchmark result file :param result: {device: {metric: value, }, } """ config = configparser.SafeConfigParser() device_count = 0 for device, metrics in six.iteritems(result): section = _DEVICE + six.text_type(device_count) device_count += 1 config.add_section(section) config.set(section, _DEVICE, device) for metric, value in six.iteritems(metrics): config.set(section, metric, six.text_type(value)) fs.write_safe( benchmark_result_file, config.write, permission=0o644 )
Example #10
Source File: diskbenchmark.py From treadmill with Apache License 2.0 | 5 votes |
def read(benchmark_result_file): """ Read benchmark :param benchmark_result_file: benchmark result file :return: {device: {metric: value, }, } """ result = {} config = configparser.SafeConfigParser() with io.open(benchmark_result_file) as fp: config.readfp(fp) # pylint: disable=deprecated-method for section in config.sections(): try: device = config.get(section, _DEVICE) result[device] = {} for metric in Metrics: result[device][metric.value] = config.get( section, metric.value ) except configparser.NoOptionError: _LOGGER.error( 'Incorrect section in %s', benchmark_result_file ) return result
Example #11
Source File: scrapyd_deploy.py From scrapydweb with GNU General Public License v3.0 | 5 votes |
def get_config(sources): """Get Scrapy config file as a SafeConfigParser""" # sources = get_sources(use_closest) cfg = SafeConfigParser() cfg.read(sources) return cfg
Example #12
Source File: cos_cmd.py From coscmd with MIT License | 5 votes |
def config(args): logger.debug("config: " + str(args)) conf_path = os.path.expanduser(config_path) with open(conf_path, 'w+') as f: cp = SafeConfigParser() cp.add_section("common") cp.set('common', 'secret_id', args.secret_id) cp.set('common', 'secret_key', args.secret_key) if args.token != "": cp.set('common', 'token', args.token) cp.set('common', 'bucket', args.bucket) if args.region: cp.set('common', 'region', args.region) else: cp.set('common', 'endpoint', args.endpoint) cp.set('common', 'max_thread', str(args.max_thread)) cp.set('common', 'part_size', str(args.part_size)) cp.set('common', 'retry', str(args.retry)) cp.set('common', 'timeout', str(args.timeout)) if args.appid != "": cp.set('common', 'appid', args.appid) if args.use_http: cp.set('common', 'schema', 'http') else: cp.set('common', 'schema', 'https') cp.set('common', 'verify', args.verify) if args.anonymous: cp.set('common', 'anonymous', 'True') else: cp.set('common', 'anonymous', 'False') cp.write(f) logger.info("Created configuration file in {path}".format(path=to_printable_str(conf_path)))
Example #13
Source File: kernel.py From ansible-jupyter-kernel with Apache License 2.0 | 5 votes |
def do_ansible_cfg(self, code): self.ansible_cfg = str(code) # Test that the code for ansible.cfg is parsable. Do not write the file yet. try: config = configparser.SafeConfigParser() if self.ansible_cfg is not None: config.readfp(six.StringIO(self.ansible_cfg)) except configparser.ParsingError as e: return self.send_error(e, 0) logger.info("ansible.cfg set to %s", code) return {'status': 'ok', 'execution_count': self.execution_count, 'payload': [], 'user_expressions': {}}
Example #14
Source File: kernel.py From ansible-jupyter-kernel with Apache License 2.0 | 5 votes |
def start_helper(self): self.queue = queue.Queue() self.helper = AnsibleKernelHelpersThread(self.queue) self.helper.start() self.process_widgets() logger.info("Started helper") config = configparser.SafeConfigParser() if self.ansible_cfg is not None: config.readfp(six.StringIO(self.ansible_cfg)) if not os.path.exists(os.path.join(self.temp_dir, 'project')): os.mkdir(os.path.join(self.temp_dir, 'project')) if not config.has_section('defaults'): config.add_section('defaults') if config.has_option('defaults', 'roles_path'): roles_path = config.get('defaults', 'roles_path') roles_path = ":".join([os.path.abspath(x) for x in roles_path.split(":")]) roles_path = "{0}:{1}".format(roles_path, os.path.abspath(pkg_resources.resource_filename('ansible_kernel', 'roles'))) config.set('defaults', 'roles_path', roles_path) else: config.set('defaults', 'roles_path', os.path.abspath( pkg_resources.resource_filename('ansible_kernel', 'roles'))) logger.debug("vault_password? %s", self.vault_password and not config.has_option('defaults', 'vault_password_file')) if self.vault_password and not config.has_option('defaults', 'vault_password_file'): vault_password_file = os.path.join(self.temp_dir, 'project', 'vault-secret') with open(vault_password_file, 'w') as vpf: vpf.write(self.vault_password) config.set('defaults', 'vault_password_file', vault_password_file) if not config.has_section('callback_ansible_kernel_helper'): config.add_section('callback_ansible_kernel_helper') config.set('callback_ansible_kernel_helper', 'status_port', str(self.helper.status_socket_port)) with open(os.path.join(self.temp_dir, 'project', 'ansible.cfg'), 'w') as f: config.write(f) logger.info("Wrote ansible.cfg")
Example #15
Source File: kojibuild.py From rdopkg with Apache License 2.0 | 5 votes |
def get_fedpkg_config(): fedpkg_conf = '/etc/rpkg/fedpkg.conf' config = configparser.SafeConfigParser() config.read(fedpkg_conf) return config
Example #16
Source File: config.py From aliyun-log-cli with MIT License | 5 votes |
def load_kv_from_file(section, key, default=None): # load key value from file config = configparser.SafeConfigParser() config.read(LOG_CREDS_FILENAME) return _get_section_option(config, section, key, default)
Example #17
Source File: parser.py From pipenv with MIT License | 5 votes |
def parse(self): parser = SafeConfigParser() parser.readfp(StringIO(self.obj.content)) for section in parser.values(): if section.name == 'options': options = 'install_requires', 'setup_requires', 'test_require' for name in options: content = section.get(name) if not content: continue self._parse_content(content) elif section.name == 'options.extras_require': for content in section.values(): self._parse_content(content)
Example #18
Source File: diskbenchmark.py From treadmill with Apache License 2.0 | 4 votes |
def benchmark(directory, volume=BENCHMARK_VOLUME, rw_type=BENCHMARK_RW_TYPE, job_number=BENCHMARK_JOB_NUMBER, thread_number=BENCHMARK_THREAD_NUMBER, block_size=BENCHMARK_IOPS_BLOCK_SIZE, max_seconds=BENCHMARK_MAX_SECONDS): """Use fio to do benchmark. """ result = {} config_file = os.path.join(directory, _BENCHMARK_CONFIG_FILE) result_file = os.path.join(directory, _BENCHMARK_RESULT_FILE) # prepare fio config config = configparser.SafeConfigParser() global_section = 'global' config.add_section(global_section) config.set(global_section, 'group_reporting', '1') config.set(global_section, 'unlink', '1') config.set(global_section, 'time_based', '1') config.set(global_section, 'direct', '1') config.set(global_section, 'size', volume) config.set(global_section, 'rw', rw_type) config.set(global_section, 'numjobs', job_number) config.set(global_section, 'iodepth', thread_number) config.set(global_section, 'bs', block_size) config.set(global_section, 'runtime', max_seconds) drive_section = 'drive' config.add_section(drive_section) config.set(drive_section, 'directory', directory) fs.write_safe( config_file, lambda f: config.write(EqualSpaceRemover(f)) ) # start fio ret = subproc.call( ['fio', config_file, '--norandommap', '--minimal', '--output', result_file] ) # parse fio terse result # http://fio.readthedocs.io/en/latest/fio_doc.html#terse-output if ret == 0: with io.open(result_file) as fp: metric_list = fp.read().split(';') result[Metrics.READ_BPS.value] = int( float(metric_list[6]) * 1024 ) result[Metrics.READ_IOPS.value] = int(metric_list[7]) result[Metrics.WRITE_BPS.value] = int( float(metric_list[47]) * 1024 ) result[Metrics.WRITE_IOPS.value] = int(metric_list[48]) return result
Example #19
Source File: bless_config.py From python-blessclient with Apache License 2.0 | 4 votes |
def parse_config_file(self, config_file): config = SafeConfigParser(self.DEFAULT_CONFIG) config.readfp(config_file) blessconfig = { 'CLIENT_CONFIG': { 'domain_regex': config.get('CLIENT', 'domain_regex'), 'cache_dir': config.get('CLIENT', 'cache_dir'), 'cache_file': config.get('CLIENT', 'cache_file'), 'mfa_cache_dir': config.get('CLIENT', 'mfa_cache_dir'), 'mfa_cache_file': config.get('CLIENT', 'mfa_cache_file'), 'ip_urls': [s.strip() for s in config.get('CLIENT', 'ip_urls').split(",")], 'update_script': config.get('CLIENT', 'update_script'), 'user_session_length': int(config.get('CLIENT', 'user_session_length')), 'usebless_role_session_length': int(config.get('CLIENT', 'usebless_role_session_length')), 'update_sshagent': config.getboolean('CLIENT', 'update_sshagent'), }, 'BLESS_CONFIG': { 'ca_backend': config.get('MAIN', 'ca_backend'), 'userrole': config.get('LAMBDA', 'user_role'), 'accountid': config.get('LAMBDA', 'account_id'), 'functionname': config.get('LAMBDA', 'functionname'), 'functionversion': config.get('LAMBDA', 'functionversion'), 'certlifetime': config.getint('LAMBDA', 'certlifetime'), 'ipcachelifetime': config.getint('LAMBDA', 'ipcachelifetime'), 'timeoutconfig': { 'connect': config.getint('LAMBDA', 'timeout_connect'), 'read': config.getint('LAMBDA', 'timeout_read') } }, 'AWS_CONFIG': { 'bastion_ips': config.get('MAIN', 'bastion_ips'), 'remote_user': config.get('MAIN', 'remote_user') }, 'REGION_ALIAS': {} } if blessconfig['BLESS_CONFIG']['ca_backend'].lower() == 'hashicorp-vault': blessconfig['VAULT_CONFIG'] = { 'vault_addr': config.get('VAULT', 'vault_addr'), 'auth_mount': config.get('VAULT', 'auth_mount'), 'ssh_backend_mount': config.get('VAULT', 'ssh_backend_mount'), 'ssh_backend_role': config.get('VAULT', 'ssh_backend_role'), } regions = config.get('MAIN', 'region_aliases').split(",") regions = [region.strip() for region in regions] for region in regions: region = region.upper() kms_region_key = 'KMSAUTH_CONFIG_{}'.format(region) blessconfig.update({kms_region_key: self._get_region_kms_config(region, config)}) blessconfig['REGION_ALIAS'].update({region: blessconfig[kms_region_key]['awsregion']}) return blessconfig