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


Python ConfigParser.items方法代码示例

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


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

示例1: load_theme

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
def load_theme(struct, path, colors, default_colors):
    theme = ConfigParser()
    with open(path, 'r') as f:
        theme.readfp(f)
    for k, v in chain(theme.items('syntax'), theme.items('interface')):
        if theme.has_option('syntax', k):
            colors[k] = theme.get('syntax', k)
        else:
            colors[k] = theme.get('interface', k)

    # Check against default theme to see if all values are defined
    for k, v in iteritems(default_colors):
        if k not in colors:
            colors[k] = v
开发者ID:daronwolff,项目名称:CHART_IN_REAL_TIME_socketio_python,代码行数:16,代码来源:config.py

示例2: loadConfigs

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
    def loadConfigs(self):
        """Entry point to load the l10n.ini file this Parser refers to.

        This implementation uses synchronous loads, subclasses might overload
        this behaviour. If you do, make sure to pass a file-like object
        to onLoadConfig.
        """
        cp = ConfigParser(self.defaults)
        cp.read(self.inipath)
        depth = self.getDepth(cp)
        self.base = mozpath.join(mozpath.dirname(self.inipath), depth)
        # create child loaders for any other l10n.ini files to be included
        try:
            for title, path in cp.items('includes'):
                # skip default items
                if title in self.defaults:
                    continue
                # add child config parser
                self.addChild(title, path, cp)
        except NoSectionError:
            pass
        # try to load the "dirs" defined in the "compare" section
        try:
            self.dirs.extend(cp.get('compare', 'dirs').split())
        except (NoOptionError, NoSectionError):
            pass
        # try to set "all_path" and "all_url"
        try:
            self.all_path = mozpath.join(self.base, cp.get('general', 'all'))
        except (NoOptionError, NoSectionError):
            self.all_path = None
        return cp
开发者ID:Pike,项目名称:compare-locales,代码行数:34,代码来源:ini.py

示例3: get_configuration_dict

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
def get_configuration_dict(configuration=None, value_types=None):
    """
    Parse the configuration files

    Parameters
    ----------
    configuration : str or list, optional
        A configuration file or list of configuration files to parse,
        defaults to the deploy_default.conf file in the package and
        deploy.conf in the current working directory.

    value_types : dict, optional
        Dictionary containing classes to apply to specific items

    Returns
    -------
    dict
        Configuration dictionary
    """
    if not value_types:  # pragma: no cover
        value_types = config_types()
    if configuration is None or configuration is '':  # pragma: no cover
        configuration = [
            # Config file that is part of the package
            # PACKAGE_DEFAULT_CONFIG,

            # Any deploy.conf files in the current directory
            'deploy.conf'
        ]
    config = ConfigParser()

    # Set the config defaults
    try:
        config.read_string(config_defaults())
    except AttributeError:
        config.readfp(io.BytesIO(config_defaults()))

    logger.debug('Working with default dict: %r', config_defaults())
    config.read(configuration)
    result_dict = {}
    for section in config.sections():
        result_dict[section] = {}
        for key, val in config.items(section):
            result_dict[section][key] = str_format_env(val)

    config_update(result_dict)

    if 'locations' not in result_dict.keys():
        result_dict['locations'] = {}
    result_dict['locations']['package_scripts'] = package_scripts_directory()
    if not result_dict['global'].get('virtualenv_dir', None):
        result_dict['global']['virtualenv_dir'] = \
            default_virtualenv_directory()

    cast_types(result_dict)

    return result_dict
开发者ID:dwighthubbard,项目名称:invirtualenv,代码行数:59,代码来源:config.py

示例4: handleApps

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
 def handleApps(self, **kwargs):
     l10nbuilds = urlopen(
         'https://raw.githubusercontent.com/Pike/master-ball/'
         'master/l10n-master/l10nbuilds.ini')
     cp = ConfigParser()
     cp.readfp(l10nbuilds)
     for section in cp.sections():
         self.stdout.write(section + '\n')
         self.handleSection(section, dict(cp.items(section)))
开发者ID:Pike,项目名称:elmo,代码行数:11,代码来源:deactivate.py

示例5: parse_config_file

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
def parse_config_file(file_path):
    config = ConfigParser()
    config.read(file_path)
    if 'batch_scoring' not in config.sections():
        #  We are return empty dict, because there is nothing in this file
        #  that related to arguments to batch scoring.
        return {}
    parsed_dict = dict(config.items('batch_scoring'))
    return config_validator(parsed_dict)
开发者ID:leigh-johnson,项目名称:batch-scoring,代码行数:11,代码来源:utils.py

示例6: main

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
def main():
    patcher.monkey_patch()
    hubs.get_hub().debug_exceptions = False

    conffile = '/etc/swift/dispersion.conf'

    parser = OptionParser(usage='''
Usage: %%prog [options] [conf_file]

[conf_file] defaults to %s'''.strip() % conffile)
    parser.add_option('-j', '--dump-json', action='store_true', default=False,
                      help='dump dispersion report in json format')
    parser.add_option('-d', '--debug', action='store_true', default=False,
                      help='print 404s to standard error')
    parser.add_option('-p', '--partitions', action='store_true', default=False,
                      help='print missing partitions to standard error')
    parser.add_option('--container-only', action='store_true', default=False,
                      help='Only run container report')
    parser.add_option('--object-only', action='store_true', default=False,
                      help='Only run object report')
    parser.add_option('--insecure', action='store_true', default=False,
                      help='Allow accessing insecure keystone server. '
                           'The keystone\'s certificate will not be verified.')
    parser.add_option('-P', '--policy-name', dest='policy_name',
                      help="Specify storage policy name")

    options, args = parser.parse_args()
    if args:
        conffile = args.pop(0)

    if options.debug:
        global debug
        debug = True

    c = ConfigParser()
    if not c.read(conffile):
        exit('Unable to read config file: %s' % conffile)
    conf = dict(c.items('dispersion'))

    if options.dump_json:
        conf['dump_json'] = 'yes'
    if options.object_only:
        conf['container_report'] = 'no'
    if options.container_only:
        conf['object_report'] = 'no'
    if options.insecure:
        conf['keystone_api_insecure'] = 'yes'
    if options.partitions:
        conf['partitions'] = 'yes'

    output = generate_report(conf, options.policy_name)

    if json_output:
        print(json.dumps(output))
开发者ID:chenzhongtao,项目名称:swift,代码行数:56,代码来源:dispersion_report.py

示例7: check_db

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
def check_db(config_parser):
    dburi = None

    if config_parser.has_option('app:main', 'database_connection'):
        dburi = config_parser.get('app:main', 'database_connection')
    elif config_parser.has_option('app:main', 'database_file'):
        db_file = config_parser.get('app:main', 'database_file')
        dburi = "sqlite:///%s?isolation_level=IMMEDIATE" % db_file
    else:
        sys.exit('The database configuration setting is missing from the tool_shed.ini file.  Add this setting before attempting to bootstrap.')

    sa_session = None

    database_exists_message = 'The database configured for this Tool Shed is not new, so bootstrapping is not allowed.  '
    database_exists_message += 'Create a new database that has not been migrated before attempting to bootstrap.'

    try:
        model = tool_shed_model.init(config_parser.get('app:main', 'file_path'), dburi, engine_options={}, create_tables=False)
        sa_session = model.context.current
        sys.exit(database_exists_message)
    except ProgrammingError:
        pass
    except OperationalError:
        pass

    try:
        if sa_session is not None:
            result = sa_session.execute('SELECT version FROM migrate_version').first()
            if result[0] >= 2:
                sys.exit(database_exists_message)
            else:
                pass
    except ProgrammingError:
        pass

    if config_parser.has_option('app:main', 'hgweb_config_dir'):
        hgweb_config_parser = ConfigParser()
        hgweb_dir = config_parser.get('app:main', 'hgweb_config_dir')
        hgweb_config_file = os.path.join(hgweb_dir, 'hgweb.config')
        if not os.path.exists(hgweb_config_file):
            sys.exit(0)
        hgweb_config_parser.read(hgweb_config_file)
        configured_repos = hgweb_config_parser.items('paths')
        if len(configured_repos) >= 1:
            message = "This Tool Shed's hgweb.config file contains entries, so bootstrapping is not allowed.  Delete"
            message += " the current hgweb.config file along with all associated repositories in the configured "
            message += "location before attempting to boostrap."
            sys.exit(message)
        else:
            sys.exit(0)
    else:
        sys.exit(0)

    sys.exit(0)
开发者ID:ImmPortDB,项目名称:immport-galaxy,代码行数:56,代码来源:bootstrap_util.py

示例8: load_ini

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
    def load_ini(self, ini_config):
        """
        Read the provided ini contents arguments and merge
        the data in the ini config into the config object.

        ini_config is assumed to be a string of the ini file contents.
        """
        parser = ConfigParser()
        parser.readfp(StringIO(ini_config))
        data = {
            'linters': {},
            'files': {},
            'branches': {},
            'fixers': {},
            'review': {}
        }
        if parser.has_section('files'):
            ignore = parser.get('files', 'ignore')
            data['files']['ignore'] = newline_value(ignore)
        if parser.has_section('branches'):
            ignore = parser.get('branches', 'ignore')
            data['branches']['ignore'] = comma_value(ignore)

        linters = []
        if parser.has_section('tools'):
            linters = comma_value(parser.get('tools', 'linters'))

        if parser.has_section('fixers'):
            data['fixers'] = dict(parser.items('fixers'))
        if parser.has_section('review'):
            data['review'] = dict(parser.items('review'))
        # Setup empty config sections
        for linter in linters:
            data['linters'][linter] = {}
        for section in parser.sections():
            if not section.startswith('tool_'):
                continue
            # Strip off tool_
            linter = section[5:]
            data['linters'][linter] = dict(parser.items(section))
        self.update(data)
开发者ID:markstory,项目名称:lint-review,代码行数:43,代码来源:config.py

示例9: __load_config

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
    def __load_config(self):
        log.info('Reading config from %s' % self.options.config)
        config_parser = ConfigParser(dict(here=os.getcwd(),
                                          database_connection='sqlite:///database/universe.sqlite?isolation_level=IMMEDIATE'))
        config_parser.read(self.options.config)

        config_dict = {}
        for key, value in config_parser.items('app:main'):
            config_dict[key] = value
        config_dict['root_dir'] = galaxy_root

        self.config = galaxy.config.Configuration(**config_dict)
开发者ID:AAFC-MBB,项目名称:galaxy-1,代码行数:14,代码来源:pgcleanup.py

示例10: load_config

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
def load_config(filename):
    section = "root"

    try:
        config_text = "[%s]\n%s" % (section, open(filename).read())
    except IOError as e:
        sys.stderr.write("load_config: %s\n" % e)
        config_text = "[%s]\n" % section

    config = ConfigParser()
    config.readfp(StringIO(config_text))

    return config.items(section)
开发者ID:muccg,项目名称:ccg-django-utils,代码行数:15,代码来源:conf.py

示例11: load

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
  def load(self):
    schemes = [defaultScheme]
    parser = ConfigParser()
    parser.read(settings.DASHBOARD_CONF)

    for option, default_value in defaultUIConfig.items():
      if parser.has_option('ui', option):
        try:
          self.ui_config[option] = parser.getint('ui', option)
        except ValueError:
          self.ui_config[option] = parser.get('ui', option)
      else:
        self.ui_config[option] = default_value

    if parser.has_option('ui', 'automatic_variants'):
      self.ui_config['automatic_variants']   = parser.getboolean('ui', 'automatic_variants')
    else:
      self.ui_config['automatic_variants'] = True

    self.ui_config['keyboard_shortcuts'] = defaultKeyboardShortcuts.copy()
    if parser.has_section('keyboard-shortcuts'):
      self.ui_config['keyboard_shortcuts'].update( parser.items('keyboard-shortcuts') )

    for section in parser.sections():
      if section in ('ui', 'keyboard-shortcuts'):
        continue

      scheme = parser.get(section, 'scheme')
      fields = []

      for match in fieldRegex.finditer(scheme):
        field = match.group(1)
        if parser.has_option(section, '%s.label' % field):
          label = parser.get(section, '%s.label' % field)
        else:
          label = field

        fields.append({
          'name' : field,
          'label' : label
        })

      schemes.append({
        'name' : section,
        'pattern' : scheme,
        'fields' : fields,
      })

    self.schemes = schemes
开发者ID:aihua,项目名称:graphite-web,代码行数:51,代码来源:views.py

示例12: get_sa_session

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
def get_sa_session(ini_file):
    conf_parser = ConfigParser({'here': os.getcwd()})
    conf_parser.read(ini_file)
    kwds = dict()
    for key, value in conf_parser.items("app:main"):
        kwds[key] = value
    ini_config = config.Configuration(**kwds)
    db_con = ini_config.database_connection
    if not db_con:
        db_con = "sqlite:///%s?isolation_level=IMMEDIATE" % ini_config.database
    model = galaxy.model.mapping.init(ini_config.file_path,
                                      db_con,
                                      engine_options={},
                                      create_tables=False)
    return model.context.current, ini_config
开发者ID:osallou,项目名称:galaxy,代码行数:17,代码来源:build_lucene_index.py

示例13: init

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
def init():
    options.config = os.path.abspath(options.config)

    config_parser = ConfigParser(dict(here=os.getcwd(),
                                      database_connection='sqlite:///database/universe.sqlite?isolation_level=IMMEDIATE'))
    config_parser.read(options.config)

    config_dict = {}
    for key, value in config_parser.items("app:main"):
        config_dict[key] = value

    config = galaxy.config.Configuration(**config_dict)

    object_store = build_object_store_from_config(config)
    return (mapping.init(config.file_path, config.database_connection, create_tables=False, object_store=object_store),
            object_store)
开发者ID:osallou,项目名称:galaxy,代码行数:18,代码来源:set_dataset_sizes.py

示例14: _get_retentions_from_storage_schemas

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
    def _get_retentions_from_storage_schemas(self, opts):
        """Parse storage-schemas.conf and returns all retentions."""
        ret = []

        config_parser = ConfigParser()
        if not config_parser.read(opts.storage_schemas):
            raise SystemExit(
                "Error: Couldn't read config file: %s" % opts.storage_schemas
            )
        for section in config_parser.sections():
            options = dict(config_parser.items(section))
            retentions = options["retentions"].split(",")
            archives = [carbon_util.parseRetentionDef(s) for s in retentions]
            ret.append(bg_metric.Retention.from_carbon(archives))

        return ret
开发者ID:Thib17,项目名称:biggraphite,代码行数:18,代码来源:command_syncdb.py

示例15: read_config_cfg

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import items [as 别名]
def read_config_cfg(filename):
    """Read the config file *filename* and replace the values in global
    variables.
    """
    cfg = ConfigParser()
    cfg.read(filename)

    def read_cfg_opts(section):
        """Read the option:value pairs in one section,
        converting value to int/float if applicable.
        """
        kv_dict = {}
        for k, v in cfg.items(section):
            try:
                kv_dict[k] = int(v)
            except:
                try:
                    kv_dict[k] = float(v)
                except:
                    kv_dict[k] = v
        return kv_dict

    default_params = read_cfg_opts("default")
    pattern = {}
    for k, v in cfg.items("pattern"):
        pattern[k] = v
    station_list = []
    for station_id in default_params["station"].split(","):
        station_params = read_cfg_opts(station_id)
        satellites = cfg.get(station_id, "satellites").split(",")
        sat_list = []
        for sat_name in satellites:
            sat_list.append(schedule.Satellite(sat_name,
                                               **read_cfg_opts(sat_name)
                                               ))
        new_station = schedule.Station(station_id, **station_params)
        new_station.satellites = sat_list
        station_list.append(new_station)
    scheduler = schedule.Scheduler(stations=station_list,
                                   min_pass=default_params.get("min_pass", 4),
                                   forward=default_params.get("forward"),
                                   start=default_params.get("start"),
                                   dump_url=default_params.get("dump_url", None),
                                   patterns=pattern,
                                   center_id=default_params.get("center_id", "unknown"))
    return scheduler
开发者ID:pytroll,项目名称:pytroll-schedule,代码行数:48,代码来源:utils.py


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