当前位置: 首页>>代码示例>>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: getLogger

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoSectionError [as 别名]
def getLogger(self):
        """
        Get logger configuration and create instance of a logger
        """
        # Known paths where loggingConfig.ini can exist
        relpath1 = os.path.join('etc', 'faraday')
        relpath2 = os.path.join('..', 'etc', 'faraday')
        setuppath = os.path.join(sys.prefix, 'etc', 'faraday')
        userpath = os.path.join(os.path.expanduser('~'), '.faraday')
        self.path = ''

        # Check all directories until first instance of loggingConfig.ini
        for location in os.curdir, relpath1, relpath2, setuppath, userpath:
            try:
                logging.config.fileConfig(os.path.join(location, "loggingConfig.ini"))
                self.path = location
                break
            except ConfigParser.NoSectionError:
                pass

        self._logger = logging.getLogger(self._name)
        return self._logger 
开发者ID:FaradayRF,项目名称:Faraday-Software,代码行数:24,代码来源:helper.py

示例8: read_system_config

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoSectionError [as 别名]
def read_system_config(path=SYSTEM_CONFIG_PATH):
    """Parse and return the system config settings in /etc/encompass.conf."""
    result = {}
    if os.path.exists(path):
        try:
            import ConfigParser
        except ImportError:
            print "cannot parse encompass.conf. please install ConfigParser"
            return

        p = ConfigParser.ConfigParser()
        try:
            p.read(path)
            for k, v in p.items('client'):
                result[k] = v
        except (ConfigParser.NoSectionError, ConfigParser.MissingSectionHeaderError):
            pass

    return result 
开发者ID:mazaclub,项目名称:encompass,代码行数:21,代码来源:simple_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: load_config

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoSectionError [as 别名]
def load_config(self, section, name, option, env):
        try:
            value = self.hubic_config.get(section, name)
        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
            if option:
                value = option
            else:
                value = os.environ.get(env, 0)
        if options.verbose and value:
            print "%s=%s" % (env, value)
        return value 
开发者ID:puzzle1536,项目名称:hubic-wrapper-to-swift,代码行数:13,代码来源:hubic.py

示例11: geteval

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoSectionError [as 别名]
def geteval(self, section, option,
                default=_ERROR, globals=None, locals=None):
        (globals, locals) = self.get_eval_environ(globals, locals)
        if isinstance(section, (tuple, list)):
            for sec in section:
                try:
                    return self.geteval(sec, option, _ERROR, globals, locals)
                except (NoOptionError, NoSectionError), ex:
                    pass
            if default is not _ERROR:
                return default
            raise ex 
开发者ID:hjimce,项目名称:Depth-Map-Prediction,代码行数:14,代码来源:configuration.py

示例12: __get

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoSectionError [as 别名]
def __get(self, section, option, default, getf):
        if isinstance(section, (tuple, list)):
            for sec in section:
                try:
                    return self.__get(sec, option, _ERROR, getf)
                except (NoOptionError, NoSectionError), ex:
                    pass
            if default is not _ERROR:
                return default
            raise ex 
开发者ID:hjimce,项目名称:Depth-Map-Prediction,代码行数:12,代码来源:configuration.py

示例13: get_settings_section

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoSectionError [as 别名]
def get_settings_section(self, section):
        dictr = {}
        options = self.conf.options(section)
        for option in options:
            try:
                dictr[option] = self.conf.get(section, option)
                if dictr[option] == -1:
                    logger.debug("skip: %s" % option)
            except ConfigParser.NoSectionError:
                logger.debug("exception on %s!" % option)
                dictr[option] = None
        return dictr 
开发者ID:dsp-jetpack,项目名称:JetPack,代码行数:14,代码来源:config.py

示例14: 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

示例15: get_config_value

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoSectionError [as 别名]
def get_config_value(config, section, name, required=False):
    if config:
        try:
            return config.get(section, name)
        except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
            if required:
                raise SSHCAInvalidConfiguration(
                    "option '%s' is required in section '%s'" %
                    (name, section))
            pass
    return None 
开发者ID:cloudtools,项目名称:ssh-ca,代码行数:13,代码来源:__init__.py


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