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


Python ConfigParser.NoOptionError方法代码示例

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


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

示例1: _module_init_

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [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

示例2: _get_key

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [as 别名]
def _get_key():
    if this.key:
        return this.key

    secret = getpass.getpass()
    try:
        salt = config().get('Security', 'salt')
    except NoOptionError:
        salt = base64.urlsafe_b64encode(os.urandom(16))
        config().set('Security', 'salt', salt)

    kdf = PBKDF2HMAC(
        algorithm=hashes.SHA256(),
        length=32,
        salt=salt,
        iterations=100000,
        backend=default_backend()
    )
    this.key = base64.urlsafe_b64encode(kdf.derive(secret))
    return this.key 
开发者ID:rtshome,项目名称:pgrepup,代码行数:22,代码来源:crypt.py

示例3: __add_checks__

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [as 别名]
def __add_checks__(self, appconfig, result):
        checks = []
        unwanted = []
        for checker in appconfig.sections():
            if "checker" in checker.lower() or "collector" in checker.lower():
                try: 
                    enabled=not strtobool(appconfig.get(checker, 'disabled'))
                except NoOptionError:
                    enabled=True
                try: 
                    enabled=strtobool(appconfig.get(checker, 'enabled'))
                except NoOptionError:
                    enabled=True
                if enabled:
                    checks.append(checker)
                else:
                    unwanted.append(checker)
        result['checks'] = checks
        result['unwanted'] = unwanted 
开发者ID:koenbuyens,项目名称:securityheaders,代码行数:21,代码来源:optionparser.py

示例4: get_config_from_root

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [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

示例5: get

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [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

示例6: get_float

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [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

示例7: config_get_bool

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [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

示例8: action2label

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [as 别名]
def action2label(action,world,form=False):
    pat = re.compile('<.*?>')
    if action['subject'] == config.get('Game','user'):
        lookup = action['verb']
    else:
        lookup = '%s %s' % (action['subject'],action['verb'])
    try:
        label = config.get('Actions',lookup)
    except NoOptionError:
        label = action['verb'].capitalize()
    for term in pat.findall(label):
        words = term[1:-1].split(':')
        if words[0] == 'action':
            if form:
                label = label.replace(term,'</input><input type="text" size="2" name="%s"/>' % (words[1]))
            else:
                label = label.replace(term,'%d' % (action[words[1]]))
        else:
            value = world.getState(words[0],words[1]).expectation()
            label = label.replace(term,'%d' % (value))
    return label 
开发者ID:pynadath,项目名称:psychsim,代码行数:23,代码来源:index.py

示例9: delete_innodb_log_files

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [as 别名]
def delete_innodb_log_files(port):
    """ Purge ib_log files

    Args:
    port - the port on which to act on localhost
    """
    try:
        ib_logs_dir = host_utils.get_cnf_setting('innodb_log_group_home_dir',
                                                 port)
    except ConfigParser.NoOptionError:
        ib_logs_dir = host_utils.get_cnf_setting('datadir',
                                                 port)
    glob_path = os.path.join(ib_logs_dir, 'ib_logfile')
    final_glob = ''.join((glob_path, '*'))
    for del_file in glob.glob(final_glob):
        log.info('Clearing {del_file}'.format(del_file=del_file))
        os.remove(del_file) 
开发者ID:pinterest,项目名称:mysql_utils,代码行数:19,代码来源:mysql_init_server.py

示例10: get_config_from_root

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [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

示例11: load_config

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [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

示例12: get_sysdig_config

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [as 别名]
def get_sysdig_config():
    """Read and parse Sysdig config from config.ini"""
    if os.path.exists(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))):
        config_parser = ConfigParser.SafeConfigParser()
        config_parser.read(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini")))
        try:
            sysdig_api_key = config_parser.get('sysdig', 'api_key')
            hostname = config_parser.get('sysdig', 'hostname')
            all_metrics = config_parser.get('sysdig', 'all_metrics').split(',')
            sysdig_http_proxy = config_parser.get('sysdig', 'sysdig_http_proxy')
            sysdig_https_proxy = config_parser.get('sysdig', 'sysdig_https_proxy')
            sysdig_metric_chunk_size= config_parser.get('sysdig', 'metric_chunk_size')
            sysdig_host_chunk_size=config_parser.get('sysdig', 'host_chunk_size')
        except ConfigParser.NoOptionError:
            logger.error(
                "Agent not correctly configured. Check config file.")
            sys.exit(1)

        if len(sysdig_api_key) == 0:
            logger.warning(
                "Agent not correctly configured(API KEY). Check config file.")
            exit()
        if len(hostname) == 0:
            logger.warning(
                "Agent not correctly configured. Check config file.")
            exit()

        sysdig_config = {
            "sysdig_api_key": sysdig_api_key,
            "hostname": hostname,
            "all_metrics": all_metrics,
            "httpProxy": sysdig_http_proxy,
            "httpsProxy": sysdig_https_proxy,
            "host_chunk_size":sysdig_host_chunk_size,
            "metric_chunk_size":sysdig_metric_chunk_size
        }
    else:
        logger.warning("No config file found. Exiting...")
        exit()

    return sysdig_config 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:43,代码来源:getmetrics_sysdig.py

示例13: get_hadoop_config

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [as 别名]
def get_hadoop_config():
    """Read and parse Hadoop config from config.ini"""
    if os.path.exists(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))):
        config_parser = ConfigParser.SafeConfigParser()
        config_parser.read(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini")))
        try:
            name_nodes = config_parser.get('hadoop', 'name_nodes')
            data_nodes = config_parser.get('hadoop', 'data_nodes')
            yarn_nodes = config_parser.get('hadoop', 'yarn_nodes')
        except ConfigParser.NoOptionError:
            logger.error(
                "Agent not correctly configured. Check config file.")
            sys.exit(1)

        if len(name_nodes) != 0:
            name_nodes = name_nodes.split(",")
        else:
            name_nodes = ["http://127.0.0.1:50070"]
        if len(data_nodes) != 0:
            data_nodes = data_nodes.split(",")
        else:
            data_nodes = ["http://127.0.0.1:50075"]
        if len(yarn_nodes) != 0:
            yarn_nodes = yarn_nodes.split(",")
        else:
            yarn_nodes = ["http://127.0.0.1:8088"]

        hadoop_config = {
            "NAME_NODES": name_nodes,
            "DATA_NODES": data_nodes,
            "YARN_NODES": yarn_nodes
        }
    else:
        logger.warning("No config file found. Using defaults.")
        hadoop_config = {
            "NAME_NODES": ["http://127.0.0.1:50070"],
            "DATA_NODES": ["http://127.0.0.1:50075"],
            "YARN_NODES": ["http://127.0.0.1:8088"]
        }

    return hadoop_config 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:43,代码来源:getmetrics_hadoop.py

示例14: get_agent_config_vars

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [as 别名]
def get_agent_config_vars():
    if os.path.exists(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))):
        config_parser = ConfigParser.SafeConfigParser()
        config_parser.read(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini")))
        try:
            user_name = config_parser.get('insightfinder', 'user_name')
            license_key = config_parser.get('insightfinder', 'license_key')
            project_name = config_parser.get('insightfinder', 'project_name')
        except ConfigParser.NoOptionError:
            logger.error(
                "Agent not correctly configured. Check config file.")
            sys.exit(1)

        if len(user_name) == 0:
            logger.warning(
                "Agent not correctly configured(user_name). Check config file.")
            sys.exit(1)
        if len(license_key) == 0:
            logger.warning(
                "Agent not correctly configured(license_key). Check config file.")
            sys.exit(1)
        if len(project_name) == 0:
            logger.warning(
                "Agent not correctly configured(project_name). Check config file.")
            sys.exit(1)

        config_vars = {
            "userName": user_name,
            "licenseKey": license_key,
            "projectName": project_name
        }

        return config_vars
    else:
        logger.error(
            "Agent not correctly configured. Check config file.")
        sys.exit(1) 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:39,代码来源:getmetrics_opentsdb.py

示例15: get_opentsdb_config

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import NoOptionError [as 别名]
def get_opentsdb_config():
    """Read and parse Open TSDB config from config.ini"""
    if os.path.exists(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))):
        config_parser = ConfigParser.SafeConfigParser()
        config_parser.read(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini")))
        try:
            opentsdb_url = config_parser.get('opentsdb', 'opentsdb_server_url')
            opentsdb_token = config_parser.get('opentsdb', 'token')
            opentsdb_metrics = config_parser.get('opentsdb', 'metrics')
        except ConfigParser.NoOptionError:
            logger.error(
                "Agent not correctly configured. Check config file.")
            sys.exit(1)

        if len(opentsdb_url) == 0:
            logger.warning(
                "Agent not correctly configured(OPENTSDB_URL). Check config file. Using \"127.0.0.1:4242\" as default.")
            opentsdb_url = "http://127.0.0.1:4242"
        if len(opentsdb_metrics) != 0:
            opentsdb_metrics = opentsdb_metrics.split(",")
        else:
            opentsdb_metrics = []

        opentsdb_config = {
            "OPENTSDB_URL": opentsdb_url,
            "OPENTSDB_METRICS": opentsdb_metrics,
            "OPENTSDB_TOKEN": opentsdb_token
        }
    else:
        logger.warning("No config file found. Using defaults.")
        opentsdb_config = {
            "OPENTSDB_URL": "http://127.0.0.1:4242",
            "OPENTSDB_METRICS": "",
            "OPENTSDB_TOKEN": ""
        }

    return opentsdb_config 
开发者ID:insightfinder,项目名称:InsightAgent,代码行数:39,代码来源:getmetrics_opentsdb.py


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