本文整理汇总了Python中six.moves.configparser.RawConfigParser.sections方法的典型用法代码示例。如果您正苦于以下问题:Python RawConfigParser.sections方法的具体用法?Python RawConfigParser.sections怎么用?Python RawConfigParser.sections使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.configparser.RawConfigParser
的用法示例。
在下文中一共展示了RawConfigParser.sections方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CredentialStore
# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import sections [as 别名]
class CredentialStore(object):
def __init__(self, **kwargs):
self.credential_search_path = [
os.path.join(os.path.sep, "etc", "cbdefense", "credentials"),
os.path.join(os.path.expanduser("~"), ".cbdefense", "credentials"),
os.path.join(".", ".cbdefense", "credentials"),
]
if "credential_file" in kwargs:
if isinstance(kwargs["credential_file"], six.string_types):
self.credential_search_path = [kwargs["credential_file"]]
elif type(kwargs["credential_file"]) is list:
self.credential_search_path = kwargs["credential_file"]
self.credentials = RawConfigParser(defaults=default_profile)
self.credential_files = self.credentials.read(self.credential_search_path)
def get_credentials(self, profile=None):
credential_profile = profile or "default"
if credential_profile not in self.get_profiles():
raise CredentialError("Cannot find credential profile '%s' after searching in these files: %s." %
(credential_profile, ", ".join(self.credential_search_path)))
retval = {}
for k, v in six.iteritems(default_profile):
retval[k] = self.credentials.get(credential_profile, k)
if not retval["api_key"] or not retval["conn_id"] or not retval["cbd_api_url"]:
raise CredentialError("API Key and Connector ID not available for profile %s" % credential_profile)
return Credentials(retval)
def get_profiles(self):
return self.credentials.sections()
示例2: update_providers
# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import sections [as 别名]
def update_providers(args, verbose=False):
filepath = args.data_dir.joinpath('references', 'bibtex', 'BIBFILES.ini')
p = RawConfigParser()
with io.open(filepath, encoding='utf-8-sig') as fp:
p.readfp(fp)
provider_map = get_map(Provider)
for section in p.sections():
sectname = section[:-4] if section.endswith('.bib') else section
id_ = slug(sectname)
attrs = {
'name': p.get(section, 'title'),
'description': p.get(section, 'description'),
'abbr': p.get(section, 'abbr'),
}
if id_ in provider_map:
provider = provider_map[id_]
for a in list(attrs):
before, after = getattr(provider, a), attrs[a]
if before == after:
del attrs[a]
else:
setattr(provider, a, after)
attrs[a] = (before, after)
if attrs:
args.log.info('updating provider %s %s' % (slug(id_), sorted(attrs)))
if verbose:
for a, (before, after) in attrs.items():
before, after = (' '.join(_.split()) for _ in (before, after))
if before != after:
args.log.info('%s\n%r\n%r' % (a, before, after))
else:
args.log.info('adding provider %s' % slug(id_))
DBSession.add(Provider(id=id_, **attrs))
示例3: check_buildout
# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import sections [as 别名]
def check_buildout(script_path):
""" Are we running from within a buildout which supplies 'zopepy'?
"""
buildout_cfg = os.path.join(os.path.dirname(script_path), 'buildout.cfg')
if os.path.exists(buildout_cfg):
parser = RawConfigParser()
try:
parser.read(buildout_cfg)
return 'zopepy' in parser.sections()
except ParsingError:
# zc.buildout uses its own parser and it allows syntax that
# ConfigParser does not like. Here's one really stupid workaround.
# The alternative is using the zc.buildout parser, which would
# introduce a hard dependency.
zope_py = os.path.join(os.path.dirname(script_path),
'bin', 'zopepy')
if os.path.isfile(zope_py) and os.access(zope_py, os.X_OK):
return True
示例4: GOAProvidersLoader
# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import sections [as 别名]
class GOAProvidersLoader(object):
"""
GOA providers reader
"""
def __init__(self, providers_file):
"""
Class initialization
"""
self.path = providers_file
self._providers = {}
self._configparser = RawConfigParser()
try:
self._configparser.read(providers_file)
except IOError as e:
logging.error(
'Could not find GOA providers file %s' % providers_file)
raise e
except ParsingError as e:
logging.error(
'There was an error parsing %s' % providers_file)
raise e
except Exception as e:
logging.error(
'There was an unknown error parsing %s' % providers_file)
raise e
self.read_data()
def read_data(self):
for section in self._configparser.sections():
if section.startswith('Provider '):
provider = section.split()[1]
self._providers[provider] = {
'name': self.generate_readable_name(provider),
'services': {}
}
for option in self._configparser.options(section):
if option == 'providername':
name = self._configparser.get(
section, option)
self._providers[provider]['name'] = name
elif option.endswith('enabled'):
service = option[:-7].title() + 'Enabled'
name = self.generate_readable_name(service[:-7])
enabled = self._configparser.getboolean(
section, option)
# Generate readable name
self._providers[provider]['services'][service] = {
'name': name,
'enabled': enabled
}
def generate_readable_name(self, identifier):
"""
Generates readable names for providers and services
"""
stripped = identifier.strip()
if stripped:
return stripped.title().replace('_', ' ')
else:
return 'Enabled'
def get_providers(self):
return self._providers