当前位置: 首页>>代码示例>>Python>>正文


Python configparser.NoSectionError方法代码示例

本文整理汇总了Python中configparser.NoSectionError方法的典型用法代码示例。如果您正苦于以下问题:Python configparser.NoSectionError方法的具体用法?Python configparser.NoSectionError怎么用?Python configparser.NoSectionError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在configparser的用法示例。


在下文中一共展示了configparser.NoSectionError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_config_from_root

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def get_config_from_root(root):
    # This might raise EnvironmentError (if setup.cfg is missing), or
    # configparser.NoSectionError (if it lacks a [versioneer] section), or
    # configparser.NoOptionError (if it lacks "VCS="). See the docstring at
    # the top of versioneer.py for instructions on writing your setup.cfg .
    setup_cfg = os.path.join(root, "setup.cfg")
    parser = configparser.SafeConfigParser()
    with open(setup_cfg, "r") as f:
        parser.readfp(f)
    VCS = parser.get("versioneer", "VCS")  # mandatory

    def get(parser, name):
        if parser.has_option("versioneer", name):
            return parser.get("versioneer", name)
        return None
    cfg = VersioneerConfig()
    cfg.VCS = VCS
    cfg.style = get(parser, "style") or ""
    cfg.versionfile_source = get(parser, "versionfile_source")
    cfg.versionfile_build = get(parser, "versionfile_build")
    cfg.tag_prefix = get(parser, "tag_prefix")
    cfg.parentdir_prefix = get(parser, "parentdir_prefix")
    cfg.verbose = get(parser, "verbose")
    return cfg 
开发者ID:menpo,项目名称:landmarkerio-server,代码行数:26,代码来源:versioneer.py

示例2: get

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def get(self, conf, stanza, option):
        '''Return the metadata value of option in [conf/stanza] section.

        :param conf: Conf name.
        :type conf: ``string``
        :param stanza: Stanza name.
        :type stanza: ``string``
        :param option: Option name in section [conf/stanza].
        :type option: ``string``
        :returns: Value of option in section [conf/stanza].
        :rtype: ``string``

        :raises ValueError: Raises ValueError if the value cannot be determined.
            Note that this can occur in several situations:

        - The section does not exist.
        - The section exists but the option does not exist.
        '''

        try:
            return self._cfg.get('/'.join([conf, stanza]), option)
        except (NoSectionError, NoOptionError):
            raise ValueError('The metadata value could not be determined.') 
开发者ID:remg427,项目名称:misp42splunk,代码行数:25,代码来源:metadata.py

示例3: get_float

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def get_float(self, conf, stanza, option):
        '''Return the metadata value of option in [conf/stanza] section as a float.

        :param conf: Conf name.
        :type conf: ``string``
        :param stanza: Stanza name.
        :type stanza: ``string``
        :param option: Option name in section [conf/stanza].
        :type option: ``string``
        :returns: A float value.
        :rtype: ``float``

        :raises ValueError: Raises ValueError if the value cannot be determined.
            Note that this can occur in several situations:

        - The stanza exists but the value does not exist (perhaps having never
          been updated).
        - The stanza does not exist.
        - The value exists but cannot be converted to a float.
        '''

        try:
            return self._cfg.getfloat('/'.join([conf, stanza]), option)
        except (NoSectionError, NoOptionError):
            raise ValueError('The metadata value could not be determined.') 
开发者ID:remg427,项目名称:misp42splunk,代码行数:27,代码来源:metadata.py

示例4: _get_s3_config

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def _get_s3_config(key=None):
        defaults = dict(configuration.get_config().defaults())
        try:
            config = dict(configuration.get_config().items('s3'))
        except (NoSectionError, KeyError):
            return {}
        # So what ports etc can be read without us having to specify all dtypes
        for k, v in six.iteritems(config):
            try:
                config[k] = int(v)
            except ValueError:
                pass
        if key:
            return config.get(key)
        section_only = {k: v for k, v in config.items() if k not in defaults or v != defaults[k]}

        return section_only 
开发者ID:d6t,项目名称:d6tpipe,代码行数:19,代码来源:s3.py

示例5: _module_init_

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def _module_init_(cls):
        """
        Initialize the class object on first module load.
        """
        cls.register(cls.__hash, "hash")
        cls.register(cls.__identity, "identity")
        cls.register(cls.__ligo, "ligo")
        cls.register(cls.__belleii, "belleii")
        policy_module = None
        try:
            policy_module = config.config_get('policy', 'lfn2pfn_module')
        except (NoOptionError, NoSectionError):
            pass
        if policy_module:
            # TODO: The import of importlib is done like this due to a dependency issue with python 2.6 and incompatibility of the module with py3.x
            # More information https://github.com/rucio/rucio/issues/875
            import importlib
            importlib.import_module(policy_module)

        cls._DEFAULT_LFN2PFN = config.get_lfn2pfn_algorithm_default() 
开发者ID:rucio,项目名称:rucio,代码行数:22,代码来源:protocol.py

示例6: config_get_bool

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def config_get_bool(section, option, raise_exception=True, default=None):
    """
    Return the boolean value for a given option in a section

    :param section: the named section.
    :param option: the named option.
    :param raise_exception: Boolean to raise or not NoOptionError or NoSectionError.
    :param default: the default value if not found.
.
    :returns: the configuration value.
    """
    try:
        return get_config().getboolean(section, option)
    except (ConfigParser.NoOptionError, ConfigParser.NoSectionError) as err:
        if raise_exception:
            raise err
        if default is None:
            return default
        return bool(default) 
开发者ID:rucio,项目名称:rucio,代码行数:21,代码来源:config.py

示例7: config_write

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def config_write(configfile, config, oldconfig):
    # Schreibt das Configfile
    # Ein Lock sollte im aufrufenden Programm gehalten werden!

    tmp_filename = get_random_filename(configfile)
    with codecs.open(tmp_filename, 'w', 'utf_8') as new_ini:
        for section_name in config.sections():
            new_ini.write(u'[{section_name}]\n'.format(section_name=section_name))
            for (key, value) in config.items(section_name):
                try:
                    new_ini.write(u'{key} = {value}\n'.format(key=key, value=update_settings(section_name, key, oldconfig.get(section_name, key))))
                except (configparser.NoSectionError, configparser.NoOptionError):
                    new_ini.write(u'{key} = {value}\n'.format(key=key, value=value))
            new_ini.write('\n')
        new_ini.flush()
        os.fsync(new_ini.fileno())
        new_ini.close()
        os.rename(tmp_filename, configfile) 
开发者ID:WLANThermo,项目名称:WLANThermo_v2,代码行数:20,代码来源:wlt_2_updateconfig.py

示例8: load_conf_from_file

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def load_conf_from_file(path=None, section='marvin'):
    data = {}
    config_path = path  # try to get config path from args
    if not config_path:  # try to get config file from env
        config_path = os.getenv('MARVIN_CONFIG_FILE') or os.getenv('CONFIG_FILE')
    if not config_path:  # use default file
        config_path = os.getenv("DEFAULT_CONFIG_PATH")
    logger.info('Loading configuration values from "{path}"...'.format(path=config_path))
    config_parser = ConfigObj(config_path)
    try:
        data = config_parser[section]
    except NoSectionError:
        logger.warn('Couldn\'t find "{section}" section in "{path}"'.format(
            section=section, path=config_path
        ))

    return data 
开发者ID:marvin-ai,项目名称:marvin-python-toolbox,代码行数:19,代码来源:config.py

示例9: get_config_from_root

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def get_config_from_root(root):
    """Read the project setup.cfg file to determine Versioneer config."""
    # This might raise EnvironmentError (if setup.cfg is missing), or
    # configparser.NoSectionError (if it lacks a [versioneer] section), or
    # configparser.NoOptionError (if it lacks "VCS="). See the docstring at
    # the top of versioneer.py for instructions on writing your setup.cfg .
    setup_cfg = os.path.join(root, "setup.cfg")
    parser = configparser.SafeConfigParser()
    with open(setup_cfg, "r") as f:
        parser.readfp(f)
    VCS = parser.get("versioneer", "VCS")  # mandatory

    def get(parser, name):
        if parser.has_option("versioneer", name):
            return parser.get("versioneer", name)
        return None
    cfg = VersioneerConfig()
    cfg.VCS = VCS
    cfg.style = get(parser, "style") or ""
    cfg.versionfile_source = get(parser, "versionfile_source")
    cfg.versionfile_build = get(parser, "versionfile_build")
    cfg.tag_prefix = get(parser, "tag_prefix")
    if cfg.tag_prefix in ("''", '""'):
        cfg.tag_prefix = ""
    cfg.parentdir_prefix = get(parser, "parentdir_prefix")
    cfg.verbose = get(parser, "verbose")
    return cfg 
开发者ID:spencerahill,项目名称:aospy,代码行数:29,代码来源:versioneer.py

示例10: get

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def get(self, key, filepath):
        """Get configuration parameter.

        Reads 'key' configuration parameter from the configuration file given
        in 'filepath'. Configuration parameter in 'key' must follow the schema
        <section>.<option> .

        :param key: key to get
        :param filepath: configuration file
        """
        if not filepath:
            raise RuntimeError("Configuration file not given")

        if not self.__check_config_key(key):
            raise RuntimeError("%s parameter does not exists" % key)

        if not os.path.isfile(filepath):
            raise RuntimeError("%s config file does not exist" % filepath)

        section, option = key.split('.')

        config = configparser.SafeConfigParser()
        config.read(filepath)

        try:
            option = config.get(section, option)
            self.display('config.tmpl', key=key, option=option)
        except (configparser.NoSectionError, configparser.NoOptionError):
            pass

        return CMD_SUCCESS 
开发者ID:chaoss,项目名称:grimoirelab-sortinghat,代码行数:33,代码来源:config.py

示例11: get_description

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def get_description(self, section):
        try:
            return self.configparser.get(section, 'description')
        except (configparser.NoSectionError, configparser.NoOptionError):
            pass
        return None 
开发者ID:cryptax,项目名称:droidlysis,代码行数:8,代码来源:droidconfig.py

示例12: get_all_regexp

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def get_all_regexp(self):
        # reads the config file and returns a list of all patterns for all sections
        # the patterns are concatenated with a |
        # throws NoSectionError, NoOptionError
        allpatterns=''
        for section in self.configparser.sections():
            if allpatterns == '':
                allpatterns = self.configparser.get(section, 'pattern')
            else:
                allpatterns= self.configparser.get(section, 'pattern') + '|' + allpatterns
        return bytes(allpatterns, 'utf-8') 
开发者ID:cryptax,项目名称:droidlysis,代码行数:13,代码来源:droidconfig.py

示例13: modify_config

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def modify_config(config, cmd):
    var, value = cmd.split('=', 1)
    section, option = var.split('/')
    if value:
        config.set(section, option, value)
    else:
        try:
            config.remove_option(section, option)
        except (configparser.NoSectionError, configparser.NoOptionError):
            pass 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:12,代码来源:__init__.py

示例14: init

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def init(self, config_channels):
        try:
            gamma = config_channels.config.getboolean('batch_norm', 'gamma')
        except (configparser.NoSectionError, configparser.NoOptionError):
            gamma = True
        try:
            beta = config_channels.config.getboolean('batch_norm', 'beta')
        except (configparser.NoSectionError, configparser.NoOptionError):
            beta = True
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                m.weight = nn.init.kaiming_normal(m.weight)
            elif isinstance(m, nn.BatchNorm2d):
                m.weight.data.fill_(1)
                m.bias.data.zero_()
                m.weight.requires_grad = gamma
                m.bias.requires_grad = beta
        try:
            if config_channels.config.getboolean('model', 'pretrained'):
                settings = pretrained_settings['inceptionv4'][config_channels.config.get('inception4', 'pretrained')]
                logging.info('use pretrained model: ' + str(settings))
                state_dict = self.state_dict()
                for key, value in torch.utils.model_zoo.load_url(settings['url']).items():
                    if key in state_dict:
                        state_dict[key] = value
                self.load_state_dict(state_dict)
        except (configparser.NoSectionError, configparser.NoOptionError):
            pass 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:30,代码来源:inception4.py

示例15: get_config_from_root

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import NoSectionError [as 别名]
def get_config_from_root(root):
    """Read the project setup.cfg file to determine Versioneer config."""
    # This might raise EnvironmentError (if setup.cfg is missing), or
    # configparser.NoSectionError (if it lacks a [versioneer] section), or
    # configparser.NoOptionError (if it lacks "VCS="). See the docstring at
    # the top of versioneer.py for instructions on writing your setup.cfg .
    setup_cfg = os.path.join(root, "setup.cfg")
    parser = configparser.SafeConfigParser()
    with open(setup_cfg, "r") as f:
        parser.readfp(f)
    VCS = parser.get("versioneer", "VCS")  # mandatory

    def get(parser, name):
        if parser.has_option("versioneer", name):
            return parser.get("versioneer", name)
        return None

    cfg = VersioneerConfig()
    cfg.VCS = VCS
    cfg.style = get(parser, "style") or ""
    cfg.versionfile_source = get(parser, "versionfile_source")
    cfg.versionfile_build = get(parser, "versionfile_build")
    cfg.tag_prefix = get(parser, "tag_prefix")
    if cfg.tag_prefix in ("''", '""'):
        cfg.tag_prefix = ""
    cfg.parentdir_prefix = get(parser, "parentdir_prefix")
    cfg.verbose = get(parser, "verbose")
    return cfg 
开发者ID:simonw,项目名称:datasette,代码行数:30,代码来源:versioneer.py


注:本文中的configparser.NoSectionError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。