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


Python ConfigParser.read方法代码示例

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


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

示例1: loadKeysConfig

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
def loadKeysConfig(path=None):
	"""Load keys config file.

	If path is ``None``, a file named :any:`DEFAULT_KEYS_FILE` will be looked for in the config
	directory.

	:param path: path of the keyboard configuration file
	"""

	if path is None:
		path = getConfigFilePath(DEFAULT_KEYS_FILE)

	cfg = ConfigParser()
	cfg.optionxform = str
	cfg.read([path])

	for category in cfg.sections():
		for actionName in cfg.options(category):
			keystr = cfg.get(category, actionName)

			context = Qt.WidgetShortcut
			if keystr.startswith('widget:'):
				keystr = keystr.split(':', 1)[1]
			elif keystr.startswith('window:'):
				keystr = keystr.split(':', 1)[1]
				context = Qt.WindowShortcut
			elif keystr.startswith('children:'):
				keystr = keystr.split(':', 1)[1]
				context = Qt.WidgetWithChildrenShortcut
			elif keystr.startswith('application:'):
				keystr = keystr.split(':', 1)[1]
				context = Qt.ApplicationShortcut
			qks = QKeySequence(keystr)

			registerActionShortcut(category, actionName, qks, context)
开发者ID:hydrargyrum,项目名称:eye,代码行数:37,代码来源:keys.py

示例2: _load_ec_as_default_policy

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
def _load_ec_as_default_policy(proxy_conf_file, swift_conf_file, **kwargs):
    """
    Override swift.conf [storage-policy:0] section to use a 2+1 EC policy.

    :param proxy_conf_file: Source proxy conf filename
    :param swift_conf_file: Source swift conf filename
    :returns: Tuple of paths to the proxy conf file and swift conf file to use
    """
    _debug('Setting configuration for default EC policy')

    conf = ConfigParser()
    conf.read(swift_conf_file)
    # remove existing policy sections that came with swift.conf-sample
    for section in list(conf.sections()):
        if section.startswith('storage-policy'):
            conf.remove_section(section)
    # add new policy 0 section for an EC policy
    conf.add_section('storage-policy:0')
    ec_policy_spec = {
        'name': 'ec-test',
        'policy_type': 'erasure_coding',
        'ec_type': 'liberasurecode_rs_vand',
        'ec_num_data_fragments': 2,
        'ec_num_parity_fragments': 1,
        'ec_object_segment_size': 1048576,
        'default': True
    }

    for k, v in ec_policy_spec.items():
        conf.set('storage-policy:0', k, str(v))

    with open(swift_conf_file, 'w') as fp:
        conf.write(fp)
    return proxy_conf_file, swift_conf_file
开发者ID:mahak,项目名称:swift,代码行数:36,代码来源:__init__.py

示例3: loadConfigs

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

示例4: update_from

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
    def update_from(self, file_path):
        """
        Reads and loads user customised settings from the given file path.

        :param file_path: Absolute path to user settings file conf.cfg.
        """
        assert isinstance(file_path, six.text_type)

        cfg_parser = ConfigParser(inline_comment_prefixes=("#",))
        cfg_parser.read(file_path)
        ptpycfg = cfg_parser["ptpython"]
        converters = [ConfigParser.getboolean, ConfigParser.getint, ConfigParser.getfloat]

        for key in ptpycfg:
            converted = False

            if key not in self.user_defined:
                # Only settings provided in initial defaults dict can get
                # customised with user defined values from conf.cfg file.
                continue

            for func in converters:
                try:
                    value = func(cfg_parser, "ptpython", key)
                except ValueError:
                    continue
                else:
                    self.user_defined[key] = value
                    converted = True
                    break

            if not converted:
                self.user_defined[key] = ptpycfg.get(key, "")
开发者ID:danirus,项目名称:ptpython,代码行数:35,代码来源:config.py

示例5: load_config

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
def load_config(config_file=_CONFIG_FILE):
    cfg_parser = ConfigParser()
    if not os.path.isfile(config_file):
        raise Exception(
            'configuration file not found: {0}'.format(config_file))
    cfg_parser.read(config_file)
    _cfg.load_config(cfg_parser)
开发者ID:CloudRift,项目名称:Rift,代码行数:9,代码来源:config.py

示例6: reader

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
def reader(filename=None):
    if filename is None:
        filename = ini_file
    cfg = ConfigParser()
    log.debug("Reading configuration from {} ...".format(ini_file))
    cfg.read(filename)
    return cfg
开发者ID:imagingearth,项目名称:lcmap-client-py,代码行数:9,代码来源:cfg.py

示例7: get_configuration

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
def get_configuration(configuration=None):
    """
    Parse a configuration file

    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.

    Returns
    -------
    configparser
        The parsed configuration
    """
    if not configuration:  # 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)
    return config
开发者ID:yahoo,项目名称:invirtualenv,代码行数:37,代码来源:config.py

示例8: restore_rois

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
    def restore_rois(self, roifile):
        """restore ROI setting from ROI.dat file"""
        cp =  ConfigParser()
        cp.read(roifile)
        rois = []
        self.mcas[0].clear_rois()
        prefix = self.mcas[0]._prefix
        if prefix.endswith('.'):
            prefix = prefix[:-1]
        iroi = 0
        for a in cp.options('rois'):
            if a.lower().startswith('roi'):
                name, dat = cp.get('rois', a).split('|')
                lims = [int(i) for i in dat.split()]
                lo, hi = lims[0], lims[1]
                # print('ROI ', name, lo, hi)
                roi = ROI(prefix=prefix, roi=iroi)
                roi.LO = lo
                roi.HI = hi
                roi.NM = name.strip()
                rois.append(roi)
                iroi += 1

        poll(0.050, 1.0)
        self.mcas[0].set_rois(rois)
        cal0 = self.mcas[0].get_calib()
        for mca in self.mcas[1:]:
            mca.set_rois(rois, calib=cal0)
开发者ID:maurov,项目名称:xraylarch,代码行数:30,代码来源:xspress3.py

示例9: get_ic_factor

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
    def get_ic_factor(self, det):
        # storing ic_factor in preferences causing issues
        # ic_factor stored in detectors.cfg

        p = os.path.join(paths.spectrometer_dir, 'detectors.cfg')
        # factors=None
        ic = 1, 0
        if os.path.isfile(p):
            c = ConfigParser()
            c.read(p)
            det = det.lower()
            for si in c.sections():
                if si.lower() == det:
                    v, e = 1, 0
                    if c.has_option(si, 'ic_factor'):
                        v = c.getfloat(si, 'ic_factor')
                    if c.has_option(si, 'ic_factor_err'):
                        e = c.getfloat(si, 'ic_factor_err')
                    ic = v, e
                    break
        else:
            self.debug('no detector file {}. cannot retrieve ic_factor'.format(p))

        r = ufloat(*ic)
        return r
开发者ID:NMGRL,项目名称:pychron,代码行数:27,代码来源:isotope_group.py

示例10: pytest_collect_file

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
def pytest_collect_file(path, parent):
    """Handle running pylint on files discovered"""
    config = parent.config
    if not config.option.pylint:
        return
    if not path.ext == ".py":
        return
    # Find pylintrc to check ignore list
    pylintrc_file = config.option.pylint_rcfile or PYLINTRC
    # No pylintrc, therefore no ignores, so return the item.
    if not pylintrc_file or not exists(pylintrc_file):
        return PyLintItem(path, parent)

    pylintrc = ConfigParser()
    pylintrc.read(pylintrc_file)
    ignore_list = []
    try:
        ignore_string = pylintrc.get('MASTER', 'ignore')
        if len(ignore_string) > 0:
            ignore_list = ignore_string.split(',')
    except (NoSectionError, NoOptionError):
        pass
    rel_path = path.strpath.replace(parent.fspath.strpath, '', 1)[1:]
    if not any(basename in rel_path for basename in ignore_list):
        return PyLintItem(path, parent)
开发者ID:rutsky,项目名称:pytest-pylint,代码行数:27,代码来源:pytest_pylint.py

示例11: get_stackstorm_version

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
def get_stackstorm_version():
    """
    Return StackStorm version including git commit revision if running a dev release and a file
    with package metadata which includes git revision is available.

    :rtype: ``str``
    """
    if 'dev' in __version__:
        version = __version__

        if not os.path.isfile(PACKAGE_METADATA_FILE_PATH):
            return version

        config = ConfigParser()

        try:
            config.read(PACKAGE_METADATA_FILE_PATH)
        except Exception:
            return version

        try:
            git_revision = config.get('server', 'git_sha')
        except Exception:
            return version

        version = '%s (%s)' % (version, git_revision)
    else:
        version = __version__

    return version
开发者ID:nzlosh,项目名称:st2,代码行数:32,代码来源:shell.py

示例12: sync

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
def sync():
    # Add or replace the relevant properites from galaxy.ini
    # into reports.ini
    reports_config_file = "config/reports.ini"
    if len(argv) > 1:
        reports_config_file = argv[1]

    universe_config_file = "config/galaxy.ini"
    if len(argv) > 2:
        universe_config_file = argv[2]

    parser = ConfigParser()
    parser.read(universe_config_file)

    with open(reports_config_file, "r") as f:
        reports_config_lines = f.readlines()

    replaced_properties = set([])
    with open(reports_config_file, "w") as f:
        # Write all properties from reports config replacing as
        # needed.
        for reports_config_line in reports_config_lines:
            (line, replaced_property) = get_synced_line(reports_config_line, parser)
            if replaced_property:
                replaced_properties.add(replaced_property)
            f.write(line)

        # If any properties appear in universe config and not in
        # reports write these as well.
        for replacement_property in REPLACE_PROPERTIES:
            if parser.has_option(MAIN_SECTION, replacement_property) and \
                    not (replacement_property in replaced_properties):
                f.write(get_universe_line(replacement_property, parser))
开发者ID:ImmPortDB,项目名称:immport-galaxy,代码行数:35,代码来源:sync_reports_config.py

示例13: _load_object_post_as_copy_conf

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
    def _load_object_post_as_copy_conf(self, conf):
        if ('object_post_as_copy' in conf or '__file__' not in conf):
            # Option is explicitly set in middleware conf. In that case,
            # we assume operator knows what he's doing.
            # This takes preference over the one set in proxy app
            return

        cp = ConfigParser()
        if os.path.isdir(conf['__file__']):
            read_conf_dir(cp, conf['__file__'])
        else:
            cp.read(conf['__file__'])

        try:
            pipe = cp.get("pipeline:main", "pipeline")
        except (NoSectionError, NoOptionError):
            return

        proxy_name = pipe.rsplit(None, 1)[-1]
        proxy_section = "app:" + proxy_name

        try:
            conf['object_post_as_copy'] = cp.get(proxy_section,
                                                 'object_post_as_copy')
        except (NoSectionError, NoOptionError):
            pass
开发者ID:clayg,项目名称:swift,代码行数:28,代码来源:copy.py

示例14: get_config

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
def get_config(options):
    S3CFG = os.getenv("S3CFG", None)
    if options.config:
        # Command-line overrides everything
        cfg = options.config
    elif S3CFG is not None:
        # Environment variable overrides defaults
        cfg = S3CFG
    else:
        # New default
        new_default = os.path.expanduser("~/.pegasus/s3cfg")
        if os.path.isfile(new_default):
            cfg = new_default
        else:
            # If the new default doesn't exist, try the old default
            cfg = os.path.expanduser("~/.s3cfg")

    if not os.path.isfile(cfg):
        raise Exception("Config file not found")

    debug("Found config file: %s" % cfg)

    # Make sure nobody else can read the file
    mode = os.stat(cfg).st_mode
    if mode & (stat.S_IRWXG | stat.S_IRWXO):
        raise Exception("Permissions of config file %s are too liberal" % cfg)

    config = ConfigParser(DEFAULT_CONFIG)
    config.read(cfg)

    return config
开发者ID:pegasus-isi,项目名称:pegasus,代码行数:33,代码来源:s3.py

示例15: log_in

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import read [as 别名]
def log_in(client):
    """Authorizes ImgurClient to use user account"""
    config = ConfigParser()
    config.read('auth.ini')
    access_token = config.get('credentials', 'access_token')
    refresh_token = config.get('credentials', 'refresh_token')
    if len(access_token) > 0 and len(refresh_token) > 0:
        client.set_user_auth(access_token, refresh_token)
        return client

    authorization_url = client.get_auth_url('pin')
    webbrowser.open(authorization_url)
    pin = input('Please input your pin\n>\t')

    credentials = client.authorize(pin)  # grant_type default is 'pin'

    access_token = credentials['access_token']
    refresh_token = credentials['refresh_token']

    config.set('credentials', 'access_token', access_token)
    config.set('credentials', 'refresh_token', refresh_token)

    save_config(config)
    client.set_user_auth(access_token, refresh_token)
    return client
开发者ID:csettles,项目名称:climgur,代码行数:27,代码来源:auth.py


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