本文整理汇总了Python中six.moves.configparser.NoSectionError方法的典型用法代码示例。如果您正苦于以下问题:Python configparser.NoSectionError方法的具体用法?Python configparser.NoSectionError怎么用?Python configparser.NoSectionError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.configparser
的用法示例。
在下文中一共展示了configparser.NoSectionError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: config_default
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def config_default(option, default=None, type=None, section=cli.name):
"""Guesses a default value of a CLI option from the configuration.
::
@click.option('--locale', default=config_default('locale'))
"""
def f(option=option, default=default, type=type, section=section):
config = read_config()
if type is None and default is not None:
# detect type from default.
type = builtins.type(default)
get_option = option_getter(type)
try:
return get_option(config, section, option)
except (NoOptionError, NoSectionError):
return default
return f
示例2: config_flag
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def config_flag(option, value, default=False, section=cli.name):
"""Guesses whether a CLI flag should be turned on or off from the
configuration. If the configuration option value is same with the given
value, it returns ``True``.
::
@click.option('--ko-kr', 'locale', is_flag=True,
default=config_flag('locale', 'ko_KR'))
"""
class x(object):
def __bool__(self, option=option, value=value,
default=default, section=section):
config = read_config()
type = builtins.type(value)
get_option = option_getter(type)
try:
return get_option(config, section, option) == value
except (NoOptionError, NoSectionError):
return default
__nonzero__ = __bool__
return x()
示例3: new_build
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def new_build(watch=True):
modules_check()
flog = setup_fedpkg_logger() # NOQA
fcmd = get_fedpkg_commands()
task_id = fcmd.build()
if watch:
print('')
try:
cli = get_fedpkg_cli()
# TODO: might be good to push this return data back up
# or check the status of the return
r = cli._watch_koji_tasks(fcmd.kojisession, [task_id])
except configparser.NoSectionError:
# <C-C> causes this for some reason
print('')
except Exception as ex:
log.warn(str(type(ex).__name__))
log.warn("Failed to get build status: %s" % ex)
return fcmd.nvr
示例4: load
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def load(self, name=None):
config = configparser.ConfigParser()
config.read(self._get_config_file())
try:
if name is None:
sections = config.sections()
if len(sections) < 1:
self.credentials = None
return
section_name = sections[-1]
else:
section_name = self._section_name(name)
username = config.get(section_name, "username")
session_id = config.get(section_name, "session_id")
database = config.get(section_name, "database")
server = config.get(section_name, "server")
self.credentials = mygeotab.Credentials(username, session_id, database, server)
except configparser.NoSectionError:
self.credentials = None
except configparser.NoOptionError:
self.credentials = None
示例5: get_configured_defaults
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def get_configured_defaults():
config = _reload_config()
try:
defaults_section = config.defaults_section_name if hasattr(config, 'defaults_section_name') else 'defaults'
defaults = {}
if before_2_0_64:
options = config.config_parser.options(defaults_section)
for opt in options:
value = config.get(defaults_section, opt)
if value:
defaults[opt] = value
else:
options = config.items(defaults_section)
for opt in options:
name = opt['name']
value = opt['value']
if value:
defaults[name] = value
return defaults
except configparser.NoSectionError:
return {}
示例6: get_PAT_from_file
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def get_PAT_from_file(self, key):
ensure_dir(AZ_DEVOPS_GLOBAL_CONFIG_DIR)
logger.debug('Keyring not configured properly or package not found.'
'Looking for credentials with key:%s in the file: %s', key, self._PAT_FILE)
creds_list = self._get_credentials_list()
try:
return creds_list.get(key, self._USERNAME)
except (configparser.NoOptionError, configparser.NoSectionError):
return None
示例7: _get_section_name
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def _get_section_name(self, name):
for section_name in self.sections():
if section_name.lower() == name.lower():
return section_name
else:
raise NoSectionError(name)
示例8: _update_default_info
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def _update_default_info(self):
try:
options = az_config.config_parser.options(DEFAULTS_SECTION)
self.config_default = ""
for opt in options:
self.config_default += opt + ": " + az_config.get(DEFAULTS_SECTION, opt) + " "
except configparser.NoSectionError:
self.config_default = ""
示例9: _config_to_dict
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def _config_to_dict(self, config_file):
"""Convert a config file to a dict."""
config = configparser.ConfigParser()
try:
with open(config_file, 'r'):
logger.info("Overlays config file %s found", str(config_file))
config.read(config_file)
except IOError:
logger.error("Overlays config file %s does not exist!",
str(config_file))
raise
except configparser.NoSectionError:
logger.error("Error in %s", str(config_file))
raise
SECTIONS = ['cache', 'coasts', 'rivers', 'borders', 'cities', 'points', 'grid']
overlays = {}
for section in config.sections():
if section in SECTIONS:
overlays[section] = {}
for option in config.options(section):
val = config.get(section, option)
try:
overlays[section][option] = ast.literal_eval(val)
except ValueError:
overlays[section][option] = val
return overlays
示例10: get_value
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def get_value(cls, section, key):
try:
value = cls._translator_config.get(section, key)
except configparser.NoOptionError:
raise exception.ConfOptionNotDefined(key=key, section=section)
except configparser.NoSectionError:
raise exception.ConfSectionNotDefined(section=section)
return value
示例11: projecttool
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def projecttool(args, get_path, set_path):
"""
Run the MAXON API Project Tool. The path to the project tool must be
configured once.
"""
cfg = load_cfg()
if set_path:
if not os.path.isfile(set_path):
print('fatal: "{}" is not a file'.format(set_path), file=sys.stderr)
sys.exit(2)
if not cfg.has_section('projecttool'):
cfg.add_section('projecttool')
cfg.set('projecttool', 'path', set_path)
save_cfg(cfg)
return
try:
path = cfg.get('projecttool', 'path')
except NoSectionError:
print('fatal: path to projecttool is not configured', file=sys.stderr)
sys.exit(1)
if get_path:
print(path)
return
sys.exit(oscall([path] + list(args)))
示例12: _find_configured_default
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def _find_configured_default(config, argument):
if not (hasattr(argument.type, 'default_name_tooling') and argument.type.default_name_tooling):
return None
try:
defaults_section = config.defaults_section_name if hasattr(config, 'defaults_section_name') else 'defaults'
return config.get(defaults_section, argument.type.default_name_tooling, None)
except configparser.NoSectionError:
return None
示例13: get_configured_defaults
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def get_configured_defaults():
_reload_config()
try:
options = az_config.config_parser.options(DEFAULTS_SECTION)
defaults = {}
for opt in options:
value = az_config.get(DEFAULTS_SECTION, opt)
if value:
defaults[opt] = value
return defaults
except configparser.NoSectionError:
return {}
示例14: _find_configured_default
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def _find_configured_default(argument):
if not (hasattr(argument.type, 'default_name_tooling') and argument.type.default_name_tooling):
return None
try:
return az_config.get(DEFAULTS_SECTION, argument.type.default_name_tooling, None)
except configparser.NoSectionError:
return None
示例15: from_config
# 需要导入模块: from six.moves import configparser [as 别名]
# 或者: from six.moves.configparser import NoSectionError [as 别名]
def from_config(cls, cp, variable_params):
"""Gets sampling transforms specified in a config file.
Sampling parameters and the parameters they replace are read from the
``sampling_params`` section, if it exists. Sampling transforms are
read from the ``sampling_transforms`` section(s), using
``transforms.read_transforms_from_config``.
An ``AssertionError`` is raised if no ``sampling_params`` section
exists in the config file.
Parameters
----------
cp : WorkflowConfigParser
Config file parser to read.
variable_params : list
List of parameter names of the original variable params.
Returns
-------
SamplingTransforms
A sampling transforms class.
"""
# Check if a sampling_params section is provided
try:
sampling_params, replace_parameters = \
read_sampling_params_from_config(cp)
except NoSectionError as e:
logging.warning("No sampling_params section read from config file")
raise e
# get sampling transformations
sampling_transforms = transforms.read_transforms_from_config(
cp, 'sampling_transforms')
logging.info("Sampling in {} in place of {}".format(
', '.join(sampling_params), ', '.join(replace_parameters)))
return cls(variable_params, sampling_params,
replace_parameters, sampling_transforms)