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