當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。