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


Python ConfigParser.write方法代码示例

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


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

示例1: _load_ec_as_default_policy

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

示例2: add_repo

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
    def add_repo(
        self, name, uri, repo_type='rpm-md', prio=None, dist=None, components=None
    ):
        """
        Add yum repository

        :param string name: repository base file name
        :param string uri: repository URI
        :param repo_type: repostory type name
        :param int prio: yum repostory priority
        :param dist: unused
        :param components: unused
        """
        repo_file = self.shared_yum_dir['reposd-dir'] + '/' + name + '.repo'
        self.repo_names.append(name + '.repo')
        if os.path.exists(uri):
            # yum requires local paths to take the file: type
            uri = 'file://' + uri
        repo_config = ConfigParser()
        repo_config.add_section(name)
        repo_config.set(
            name, 'name', name
        )
        repo_config.set(
            name, 'baseurl', uri
        )
        if prio:
            repo_config.set(
                name, 'priority', format(prio)
            )
        with open(repo_file, 'w') as repo:
            repo_config.write(repo)
开发者ID:SUSE,项目名称:kiwi,代码行数:34,代码来源:yum.py

示例3: setUp

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
    def setUp(self):
        self.tmpdir = tempfile.mkdtemp()

        self.conffile = os.path.join(self.tmpdir, 'zeyple.conf')
        self.homedir = os.path.join(self.tmpdir, 'gpg')
        self.logfile = os.path.join(self.tmpdir, 'zeyple.log')

        config = ConfigParser()

        config.add_section('zeyple')
        config.set('zeyple', 'log_file', self.logfile)
        config.set('zeyple', 'add_header', 'true')

        config.add_section('gpg')
        config.set('gpg', 'home', self.homedir)

        config.add_section('relay')
        config.set('relay', 'host', 'example.net')
        config.set('relay', 'port', '2525')

        with open(self.conffile, 'w') as fp:
            config.write(fp)

        os.mkdir(self.homedir, 0o700)
        subprocess.check_call(
            ['gpg', '--homedir', self.homedir, '--import', KEYS_FNAME],
            stderr=open('/dev/null'),
        )

        self.zeyple = zeyple.Zeyple(self.conffile)
        self.zeyple._send_message = Mock()  # don't try to send emails
开发者ID:morph027,项目名称:zeyple,代码行数:33,代码来源:test_zeyple.py

示例4: _save

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
    def _save(self, nv):
        p = get_spectrometer_config_path()
        config = ConfigParser()
        config.read(p)

        config.set('CDDParameters', 'OperatingVoltage', nv)
        config.write(open(p, 'w'))
        self.info('saving new operating voltage {:0.1f} to {}'.format(nv, p))
开发者ID:NMGRL,项目名称:pychron,代码行数:10,代码来源:cdd_operating_voltage_scan.py

示例5: as_ini

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
 def as_ini(self):
     """
     """
     context = self.context
     parser = ConfigParser()
     stream = cStringIO()
     for k, v in context.propertyItems():
         parser.set('DEFAULT', k, str(v))
     parser.write(stream)
     return stream.getvalue()
开发者ID:zopefoundation,项目名称:Products.GenericSetup,代码行数:12,代码来源:content.py

示例6: open_buildout_configfile

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
def open_buildout_configfile(filepath="buildout.cfg", write_on_exit=False):
    parser = ConfigParser()
    parser.read(filepath)
    try:
        yield parser
    finally:
        if not write_on_exit:
            return
        with open(filepath, 'w') as fd:
            parser.write(fd)
开发者ID:Infinidat,项目名称:infi.recipe.application_packager,代码行数:12,代码来源:__init__.py

示例7: dump

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
    def dump(self):
        p = get_spectrometer_config_path()

        cfp = ConfigParser()
        cfp.read(p)
        for gn, pn, v in self.itervalues():
            cfp.set(gn, pn, v)

        with open(p, 'w') as wfile:
            cfp.write(wfile)

        return p
开发者ID:NMGRL,项目名称:pychron,代码行数:14,代码来源:spectrometer_parameters.py

示例8: _modify_wpr_file

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
def _modify_wpr_file(template, outfile, version):
    config = ConfigParser()
    config.read(template)
    if sys.platform == 'darwin':
        config.set('user attributes', 'proj.pyexec',
                   text_type(dict({None: ('custom', sys.executable)})))
        config.set('user attributes', 'proj.pypath',
                   text_type(dict({None: ('custom',os.pathsep.join(sys.path))})))

    with open(outfile, 'w') as fp:
        fp.write('#!wing\n#!version=%s\n' % version)
        config.write(fp)
开发者ID:Mrbarhate,项目名称:OpenMDAO,代码行数:14,代码来源:wingproj.py

示例9: add_repo

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
    def add_repo(
        self, name, uri, repo_type='rpm-md',
        prio=None, dist=None, components=None,
        user=None, secret=None, credentials_file=None,
        repo_gpgcheck=None, pkg_gpgcheck=None
    ):
        """
        Add yum repository

        :param string name: repository base file name
        :param string uri: repository URI
        :param repo_type: repostory type name
        :param int prio: yum repostory priority
        :param dist: unused
        :param components: unused
        :param user: unused
        :param secret: unused
        :param credentials_file: unused
        :param bool repo_gpgcheck: enable repository signature validation
        :param bool pkg_gpgcheck: enable package signature validation
        """
        repo_file = self.shared_yum_dir['reposd-dir'] + '/' + name + '.repo'
        self.repo_names.append(name + '.repo')
        if os.path.exists(uri):
            # yum requires local paths to take the file: type
            uri = 'file://' + uri
        repo_config = ConfigParser()
        repo_config.add_section(name)
        repo_config.set(
            name, 'name', name
        )
        repo_config.set(
            name, 'baseurl', uri
        )
        repo_config.set(
            name, 'enabled', '1'
        )
        if prio:
            repo_config.set(
                name, 'priority', format(prio)
            )
        if repo_gpgcheck is not None:
            repo_config.set(
                name, 'repo_gpgcheck', '1' if repo_gpgcheck else '0'
            )
        if pkg_gpgcheck is not None:
            repo_config.set(
                name, 'gpgcheck', '1' if pkg_gpgcheck else '0'
            )
        with open(repo_file, 'w') as repo:
            repo_config.write(RepositoryYumSpaceRemover(repo))
开发者ID:AdamMajer,项目名称:kiwi-ng,代码行数:53,代码来源:yum.py

示例10: _load_domain_remap_staticweb

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
def _load_domain_remap_staticweb(proxy_conf_file, swift_conf_file, **kwargs):
    """
    Load domain_remap and staticweb into proxy server pipeline.

    :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
    :raises InProcessException: raised if proxy conf contents are invalid
    """
    _debug('Setting configuration for domain_remap')

    # add a domain_remap storage_domain to the test configuration
    storage_domain = 'example.net'
    global config
    config['storage_domain'] = storage_domain

    # The global conf dict cannot be used to modify the pipeline.
    # The pipeline loader requires the pipeline to be set in the local_conf.
    # If pipeline is set in the global conf dict (which in turn populates the
    # DEFAULTS options) then it prevents pipeline being loaded into the local
    # conf during wsgi load_app.
    # Therefore we must modify the [pipeline:main] section.
    conf = ConfigParser()
    conf.read(proxy_conf_file)
    try:
        section = 'pipeline:main'
        old_pipeline = conf.get(section, 'pipeline')
        pipeline = old_pipeline.replace(
            " tempauth ",
            " domain_remap tempauth staticweb ")
        if pipeline == old_pipeline:
            raise InProcessException(
                "Failed to insert domain_remap and staticweb into pipeline: %s"
                % old_pipeline)
        conf.set(section, 'pipeline', pipeline)
        # set storage_domain in domain_remap middleware to match test config
        section = 'filter:domain_remap'
        conf.set(section, 'storage_domain', storage_domain)
    except NoSectionError as err:
        msg = 'Error problem with proxy conf file %s: %s' % \
              (proxy_conf_file, err)
        raise InProcessException(msg)

    test_conf_file = os.path.join(_testdir, 'proxy-server.conf')
    with open(test_conf_file, 'w') as fp:
        conf.write(fp)

    return test_conf_file, swift_conf_file
开发者ID:mahak,项目名称:swift,代码行数:50,代码来源:__init__.py

示例11: _get_config_object

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
def _get_config_object(config_path, use_cashed_config=True):
    '''
    Returns a ConfigParser for the config file at the given path. If no file exists, an empty config file is created.
    :param config_path:
    :param use_cashed_config: If set to True, will return the previously created ConfigParser file (if previously created).
        If set to False, will re-read the config file from disk. If a ConfigParser was previously created, it will not be replaced!
    :return:
    '''
    if config_path not in _CONFIG_OBJECTS or not use_cashed_config:
        config = ConfigParser()
        if not os.path.exists(config_path):
            with open(config_path,'w') as f:
                config.write(f)
        else:
            config.read(config_path)
        if use_cashed_config:
            _CONFIG_OBJECTS[config_path] = config
    else:
        config = _CONFIG_OBJECTS[config_path]
    return config
开发者ID:QUVA-Lab,项目名称:artemis,代码行数:22,代码来源:config_files.py

示例12: _in_process_setup_swift_conf

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
def _in_process_setup_swift_conf(swift_conf_src, testdir):
    # override swift.conf contents for in-process functional test runs
    conf = ConfigParser()
    conf.read(swift_conf_src)
    try:
        section = 'swift-hash'
        conf.set(section, 'swift_hash_path_suffix', 'inprocfunctests')
        conf.set(section, 'swift_hash_path_prefix', 'inprocfunctests')
        section = 'swift-constraints'
        max_file_size = (8 * 1024 * 1024) + 2  # 8 MB + 2
        conf.set(section, 'max_file_size', str(max_file_size))
    except NoSectionError:
        msg = 'Conf file %s is missing section %s' % (swift_conf_src, section)
        raise InProcessException(msg)

    test_conf_file = os.path.join(testdir, 'swift.conf')
    with open(test_conf_file, 'w') as fp:
        conf.write(fp)

    return test_conf_file
开发者ID:mahak,项目名称:swift,代码行数:22,代码来源:__init__.py

示例13: _in_process_setup_swift_conf

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
def _in_process_setup_swift_conf(swift_conf_src, testdir):
    # override swift.conf contents for in-process functional test runs
    conf = ConfigParser()
    conf.read(swift_conf_src)
    try:
        section = "swift-hash"
        conf.set(section, "swift_hash_path_suffix", "inprocfunctests")
        conf.set(section, "swift_hash_path_prefix", "inprocfunctests")
        section = "swift-constraints"
        max_file_size = (8 * 1024 * 1024) + 2  # 8 MB + 2
        conf.set(section, "max_file_size", max_file_size)
    except NoSectionError:
        msg = "Conf file %s is missing section %s" % (swift_conf_src, section)
        raise InProcessException(msg)

    test_conf_file = os.path.join(testdir, "swift.conf")
    with open(test_conf_file, "w") as fp:
        conf.write(fp)

    return test_conf_file
开发者ID:rtblife97,项目名称:swift,代码行数:22,代码来源:__init__.py

示例14: process_mistral_config

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
def process_mistral_config(config_path):
    """
    Remove sensitive data (credentials) from the Mistral config.

    :param config_path: Full absolute path to the mistral config inside /tmp.
    :type config_path: ``str``
    """
    assert config_path.startswith('/tmp')

    if not os.path.isfile(config_path):
        return

    config = ConfigParser()
    config.read(config_path)

    for section, options in MISTRAL_CONF_OPTIONS_TO_REMOVE.items():
        for option in options:
            if config.has_option(section, option):
                config.set(section, option, REMOVED_VALUE_NAME)

    with open(config_path, 'w') as fp:
        config.write(fp)
开发者ID:StackStorm,项目名称:st2,代码行数:24,代码来源:processors.py

示例15: _install_desktop_file

# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import write [as 别名]
    def _install_desktop_file(self, prefix, activity_path):
        cp = ConfigParser()
        section = 'Desktop Entry'
        cp.add_section(section)
        cp.optionxform = str  # Allow CamelCase entries

        # Get it from the activity.info for the non-translated version
        info = ConfigParser()
        info.read(os.path.join(activity_path, 'activity', 'activity.info'))
        cp.set(section, 'Name', info.get('Activity', 'name'))
        if info.has_option('Activity', 'summary'):
            cp.set(section, 'Comment', info.get('Activity', 'summary'))

        for path in sorted(glob(os.path.join(activity_path, 'locale',
                                             '*', 'activity.linfo'))):
            locale = path.split(os.path.sep)[-2]
            info = ConfigParser()
            info.read(path)
            if info.has_option('Activity', 'name'):
                cp.set(section, 'Name[{}]'.format(locale),
                       info.get('Activity', 'name'))
            if info.has_option('Activity', 'summary'):
                cp.set(section, 'Comment[{}]'.format(locale),
                       info.get('Activity', 'summary'))

        cp.set(section, 'Terminal', 'false')
        cp.set(section, 'Type', 'Application')
        cp.set(section, 'Categories', 'Education;')
        cp.set(section, 'Icon', os.path.join(
            activity_path, 'activity', self.config.bundle.get_icon_filename()))
        cp.set(section, 'Exec', self.config.bundle.get_command())
        cp.set(section, 'Path', activity_path)  # Path == CWD for running

        name = '{}.activity.desktop'.format(self.config.bundle_id)
        path = os.path.join(prefix, 'share', 'applications', name)
        if not os.path.isdir(os.path.dirname(path)):
            os.makedirs(os.path.dirname(path))
        with open(path, 'w') as f:
            cp.write(f)
开发者ID:sugarlabs,项目名称:sugar-toolkit-gtk3,代码行数:41,代码来源:bundlebuilder.py


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