本文整理汇总了Python中six.moves.configparser.ConfigParser.get方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.get方法的具体用法?Python ConfigParser.get怎么用?Python ConfigParser.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.configparser.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handleSection
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def handleSection(self, section, items):
locales = items['locales']
if locales == 'all':
inipath = '/'.join((
items['repo'], items['mozilla'],
'raw-file', 'default',
items['l10n.ini']
))
ini = ConfigParser()
ini.readfp(urlopen(inipath))
allpath = urljoin(
urljoin(inipath, ini.get('general', 'depth')),
ini.get('general', 'all'))
locales = urlopen(allpath).read()
locales = locales.split()
obs = (Active.objects
.filter(run__tree__code=section)
.exclude(run__locale__code__in=locales)
.order_by('run__locale__code'))
obslocs = ' '.join(obs.values_list('run__locale__code', flat=True))
if not obslocs:
self.stdout.write(' OK\n')
return
s = input('Remove %s? [Y/n] ' % obslocs)
if s.lower() == 'y' or s == '':
obs.delete()
示例2: log_in
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def log_in(client):
"""Authorizes ImgurClient to use user account"""
config = ConfigParser()
config.read('auth.ini')
access_token = config.get('credentials', 'access_token')
refresh_token = config.get('credentials', 'refresh_token')
if len(access_token) > 0 and len(refresh_token) > 0:
client.set_user_auth(access_token, refresh_token)
return client
authorization_url = client.get_auth_url('pin')
webbrowser.open(authorization_url)
pin = input('Please input your pin\n>\t')
credentials = client.authorize(pin) # grant_type default is 'pin'
access_token = credentials['access_token']
refresh_token = credentials['refresh_token']
config.set('credentials', 'access_token', access_token)
config.set('credentials', 'refresh_token', refresh_token)
save_config(config)
client.set_user_auth(access_token, refresh_token)
return client
示例3: _load_object_post_as_copy_conf
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def _load_object_post_as_copy_conf(self, conf):
if ('object_post_as_copy' in conf or '__file__' not in conf):
# Option is explicitly set in middleware conf. In that case,
# we assume operator knows what he's doing.
# This takes preference over the one set in proxy app
return
cp = ConfigParser()
if os.path.isdir(conf['__file__']):
read_conf_dir(cp, conf['__file__'])
else:
cp.read(conf['__file__'])
try:
pipe = cp.get("pipeline:main", "pipeline")
except (NoSectionError, NoOptionError):
return
proxy_name = pipe.rsplit(None, 1)[-1]
proxy_section = "app:" + proxy_name
try:
conf['object_post_as_copy'] = cp.get(proxy_section,
'object_post_as_copy')
except (NoSectionError, NoOptionError):
pass
示例4: loadConfigs
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def loadConfigs(self):
"""Entry point to load the l10n.ini file this Parser refers to.
This implementation uses synchronous loads, subclasses might overload
this behaviour. If you do, make sure to pass a file-like object
to onLoadConfig.
"""
cp = ConfigParser(self.defaults)
cp.read(self.inipath)
depth = self.getDepth(cp)
self.base = mozpath.join(mozpath.dirname(self.inipath), depth)
# create child loaders for any other l10n.ini files to be included
try:
for title, path in cp.items('includes'):
# skip default items
if title in self.defaults:
continue
# add child config parser
self.addChild(title, path, cp)
except NoSectionError:
pass
# try to load the "dirs" defined in the "compare" section
try:
self.dirs.extend(cp.get('compare', 'dirs').split())
except (NoOptionError, NoSectionError):
pass
# try to set "all_path" and "all_url"
try:
self.all_path = mozpath.join(self.base, cp.get('general', 'all'))
except (NoOptionError, NoSectionError):
self.all_path = None
return cp
示例5: setUp
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def setUp(self):
rid = '60754-10'
config = ConfigParser()
p = '/Users/ross/Sandbox/pychron_validation_data.cfg'
config.read(p)
signals = [list(map(float, x.split(','))) for x in [config.get('Signals-{}'.format(rid), k)
for k in ['ar40', 'ar39', 'ar38', 'ar37', 'ar36']]]
blanks = [list(map(float, x.split(','))) for x in [config.get('Blanks-{}'.format(rid), k)
for k in ['ar40', 'ar39', 'ar38', 'ar37', 'ar36']]]
irradinfo = [list(map(float, x.split(','))) for x in [config.get('irrad-{}'.format(rid), k) for k in ['k4039', 'k3839', 'ca3937', 'ca3837', 'ca3637', 'cl3638']]]
j = config.get('irrad-{}'.format(rid), 'j')
j = [float(x) for x in j.split(',')]
baselines = [(0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
backgrounds = [(0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]
ar37df = config.getfloat('irrad-{}'.format(rid), 'ar37df')
t = math.log(ar37df) / (constants.lambda_37.nominal_value * 365.25)
irradinfo.append(t)
# load results
r = 'results-{}'.format(rid)
self.age = config.getfloat(r, 'age')
self.rad4039 = config.getfloat(r, 'rad4039')
self.ca37k39 = config.getfloat(r, 'ca37k39')
self.age_dict = calculate_arar_age(signals, baselines, blanks, backgrounds, j, irradinfo,
)
示例6: _populate_config_from_old_location
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def _populate_config_from_old_location(self, conf):
if ('rate_limit_after_segment' in conf or
'rate_limit_segments_per_sec' in conf or
'max_get_time' in conf or
'__file__' not in conf):
return
cp = ConfigParser()
if os.path.isdir(conf['__file__']):
read_conf_dir(cp, conf['__file__'])
else:
cp.read(conf['__file__'])
try:
pipe = cp.get("pipeline:main", "pipeline")
except (NoSectionError, NoOptionError):
return
proxy_name = pipe.rsplit(None, 1)[-1]
proxy_section = "app:" + proxy_name
for setting in ('rate_limit_after_segment',
'rate_limit_segments_per_sec',
'max_get_time'):
try:
conf[setting] = cp.get(proxy_section, setting)
except (NoSectionError, NoOptionError):
pass
示例7: read_config_file
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def read_config_file(cfgfile, options):
config = ConfigParser()
config.readfp(open(cfgfile))
if config.has_option('testflo', 'skip_dirs'):
skips = config.get('testflo', 'skip_dirs')
options.skip_dirs = [s.strip() for s in skips.split(',') if s.strip()]
if config.has_option('testflo', 'num_procs'):
options.num_procs = int(config.get('testflo', 'num_procs'))
示例8: __init__
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def __init__(self):
config_file = os.environ.get('CONFIG')
if config_file is None:
print('Environment variable "CONFIG" not defined.')
sys.exit(0)
config = ConfigParser()
config.read(config_file)
self.ABBREVIATION_MODEL = config.get('MODEL', 'ABBREVIATION_MODEL')
self.WORD2VEC_MODEL = config.get('MODEL', 'WORD2VEC_MODEL')
示例9: from_file
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def from_file(cls, filename, logger):
config = ConfigParser(_check_defaults)
if not config.read([filename]):
raise CheckLoadError('Failed reading file', filename)
_section = 'check'
try:
_ok_criteria = config.get(_section, 'ok')
_warning_criteria = config.get(_section, 'warning')
except Exception as exc:
logger.exception(exc)
raise CheckLoadError('Failed loading file', filename)
return cls(_ok_criteria, _warning_criteria, filename, logger)
示例10: get_anon_client
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def get_anon_client():
"""Simple ImgurClient that only has client credentials.
An anonymous IgmurClient is not linked to a user account.
"""
config = ConfigParser()
config.read('auth.ini')
client_id = config.get('credentials', 'client_id')
client_secret = config.get('credentials', 'client_secret')
# removed for compatibility with python 2.7
# client_id = config.get('credentials', 'CLIENT_ID', fallback=None)
# client_secret = config.get('credentials', 'CLIENT_SECRET', fallback=None)
return ImgurClient(client_id, client_secret)
示例11: load_theme
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def load_theme(struct, path, colors, default_colors):
theme = ConfigParser()
with open(path, 'r') as f:
theme.readfp(f)
for k, v in chain(theme.items('syntax'), theme.items('interface')):
if theme.has_option('syntax', k):
colors[k] = theme.get('syntax', k)
else:
colors[k] = theme.get('interface', k)
# Check against default theme to see if all values are defined
for k, v in iteritems(default_colors):
if k not in colors:
colors[k] = v
示例12: load
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def load(self):
schemes = [defaultScheme]
parser = ConfigParser()
parser.read(settings.DASHBOARD_CONF)
for option, default_value in defaultUIConfig.items():
if parser.has_option('ui', option):
try:
self.ui_config[option] = parser.getint('ui', option)
except ValueError:
self.ui_config[option] = parser.get('ui', option)
else:
self.ui_config[option] = default_value
if parser.has_option('ui', 'automatic_variants'):
self.ui_config['automatic_variants'] = parser.getboolean('ui', 'automatic_variants')
else:
self.ui_config['automatic_variants'] = True
self.ui_config['keyboard_shortcuts'] = defaultKeyboardShortcuts.copy()
if parser.has_section('keyboard-shortcuts'):
self.ui_config['keyboard_shortcuts'].update( parser.items('keyboard-shortcuts') )
for section in parser.sections():
if section in ('ui', 'keyboard-shortcuts'):
continue
scheme = parser.get(section, 'scheme')
fields = []
for match in fieldRegex.finditer(scheme):
field = match.group(1)
if parser.has_option(section, '%s.label' % field):
label = parser.get(section, '%s.label' % field)
else:
label = field
fields.append({
'name' : field,
'label' : label
})
schemes.append({
'name' : section,
'pattern' : scheme,
'fields' : fields,
})
self.schemes = schemes
示例13: get_config
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def get_config(p):
"""Read a config file.
:return: dict of ('section.option', value) pairs.
"""
cfg = {}
parser = ConfigParser()
if hasattr(parser, 'read_file'):
parser.read_file(Path(p).open(encoding='utf8'))
else: # pragma: no cover
assert PY2
# The `read_file` method is not available on ConfigParser in py2.7!
parser.readfp(Path(p).open(encoding='utf8'))
for section in parser.sections():
getters = {
'int': partial(parser.getint, section),
'boolean': partial(parser.getboolean, section),
'float': partial(parser.getfloat, section),
'list': lambda option: parser.get(section, option).split(),
}
default = partial(parser.get, section)
for option in parser.options(section):
type_ = option.rpartition('_')[2] if '_' in option else None
value = getters.get(type_, default)(option)
cfg['{0}.{1}'.format(section, option)] = value
return cfg
示例14: getfloat
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def getfloat(self, section, option, default = None):
try:
v = ConfigParser.get(self, section, option)
return float(v) if v is not None else default
except (NoSectionError, NoOptionError):
return default
示例15: _get_attach_points
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import get [as 别名]
def _get_attach_points(self, info, size_request):
has_attach_points_, attach_points = info.get_attach_points()
attach_x = attach_y = 0
if attach_points:
# this works only for Gtk < 3.14
# https://developer.gnome.org/gtk3/stable/GtkIconTheme.html
# #gtk-icon-info-get-attach-points
attach_x = float(attach_points[0].x) / size_request
attach_y = float(attach_points[0].y) / size_request
elif info.get_filename():
# try read from the .icon file
icon_filename = info.get_filename().replace('.svg', '.icon')
if icon_filename != info.get_filename() and \
os.path.exists(icon_filename):
try:
with open(icon_filename) as config_file:
cp = ConfigParser()
cp.readfp(config_file)
attach_points_str = cp.get('Icon Data', 'AttachPoints')
attach_points = attach_points_str.split(',')
attach_x = float(attach_points[0].strip()) / 1000
attach_y = float(attach_points[1].strip()) / 1000
except Exception as e:
logging.exception('Exception reading icon info: %s', e)
return attach_x, attach_y