本文整理汇总了Python中six.moves.configparser.SafeConfigParser方法的典型用法代码示例。如果您正苦于以下问题:Python configparser.SafeConfigParser方法的具体用法?Python configparser.SafeConfigParser怎么用?Python configparser.SafeConfigParser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.configparser
的用法示例。
在下文中一共展示了configparser.SafeConfigParser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
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
示例2: parse
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
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
示例3: config
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
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
示例4: config_from_ini
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
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
示例5: load_kv_from_file
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
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)
示例6: get_fedpkg_config
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
def get_fedpkg_config():
fedpkg_conf = '/etc/rpkg/fedpkg.conf'
config = configparser.SafeConfigParser()
config.read(fedpkg_conf)
return config
示例7: start_helper
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
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")
示例8: do_ansible_cfg
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
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': {}}
示例9: config
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
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)))
示例10: get_config
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
def get_config(sources):
"""Get Scrapy config file as a SafeConfigParser"""
# sources = get_sources(use_closest)
cfg = SafeConfigParser()
cfg.read(sources)
return cfg
示例11: read
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
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
示例12: write
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
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
)
示例13: _load_config
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
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)
示例14: load_cfg
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
def load_cfg():
cfg = SafeConfigParser()
if os.path.isfile(cfg_filename):
cfg.read([cfg_filename])
return cfg
示例15: __init__
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import SafeConfigParser [as 别名]
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))