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


Python RawConfigParser.add_section方法代码示例

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


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

示例1: constructConfigParser

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import add_section [as 别名]
def constructConfigParser():
    """
    returns a pre-setup config parser
    """
    parser = RawConfigParser()
    parser.read([CONFIG_SYSTEM, CONFIG_USER])
    if not parser.has_section(GERALD_CONFIG_SECTION):
        parser.add_section(GERALD_CONFIG_SECTION)

    return parser
开发者ID:detrout,项目名称:htsworkflow,代码行数:12,代码来源:retrieve_config.py

示例2: _merge_from_file

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import add_section [as 别名]
    def _merge_from_file(self, config_file):
        """
        Merge variables from ``config_file`` into the environment.

        Any variables in ``config_file`` that have already been set will be
        ignored (meaning this method will *not* try to override them, which
        would raise an exception).

        If ``config_file`` does not exist or is not a regular file, or if there
        is an error parsing ``config_file``, ``None`` is returned.

        Otherwise this method returns a ``(num_set, num_total)`` tuple
        containing first the number of variables that were actually set, and
        second the total number of variables found in ``config_file``.

        This method will raise a ``ValueError`` if ``config_file`` is not an
        absolute path.  For example:

        >>> env = Env()
        >>> env._merge_from_file('my/config.conf')
        Traceback (most recent call last):
          ...
        ValueError: config_file must be an absolute path; got 'my/config.conf'

        Also see `Env._merge()`.

        :param config_file: Absolute path of the configuration file to load.
        """
        if path.abspath(config_file) != config_file:
            raise ValueError(
                'config_file must be an absolute path; got %r' % config_file
            )
        if not path.isfile(config_file):
            return
        parser = RawConfigParser()
        try:
            parser.read(config_file)
        except ParsingError:
            return
        if not parser.has_section(CONFIG_SECTION):
            parser.add_section(CONFIG_SECTION)
        items = parser.items(CONFIG_SECTION)
        if len(items) == 0:
            return (0, 0)
        i = 0
        for (key, value) in items:
            if key not in self:
                self[key] = value
                i += 1
        if 'config_loaded' not in self: # we loaded at least 1 file
            self['config_loaded'] = True
        return (i, len(items))
开发者ID:icute1349,项目名称:freeipa,代码行数:54,代码来源:config.py

示例3: _test_write_pkispawn_config_file

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import add_section [as 别名]
 def _test_write_pkispawn_config_file(self, template, expected):
     """
     Test that the values we read from an ExternalCAProfile
     object can be used to produce a reasonable-looking pkispawn
     configuration.
     """
     config = RawConfigParser()
     config.optionxform = str
     config.add_section("CA")
     config.set("CA", "pki_req_ext_oid", template.ext_oid)
     config.set("CA", "pki_req_ext_data",
                hexlify(template.get_ext_data()).decode('ascii'))
     out = StringIO()
     config.write(out)
     assert out.getvalue() == expected
开发者ID:npmccallum,项目名称:freeipa,代码行数:17,代码来源:test_cainstance.py

示例4: convert_config_to_tribler71

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import add_section [as 别名]
def convert_config_to_tribler71(current_config, state_dir=None):
    """
    Convert the Config files libtribler.conf and tribler.conf to the newer triblerd.conf and cleanup the files
    when we are done.

    :param: current_config: the current config in which we merge the old config files.
    :return: the newly edited TriblerConfig object with the old data inserted.
    """
    state_dir = state_dir or TriblerConfig.get_default_state_dir()
    libtribler_file_loc = os.path.join(state_dir, "libtribler.conf")
    if os.path.exists(libtribler_file_loc):
        libtribler_cfg = RawConfigParser()
        libtribler_cfg.read(libtribler_file_loc)
        current_config = add_libtribler_config(current_config, libtribler_cfg)
        os.remove(libtribler_file_loc)

    tribler_file_loc = os.path.join(state_dir, "tribler.conf")
    if os.path.exists(tribler_file_loc):
        tribler_cfg = RawConfigParser()
        tribler_cfg.read(tribler_file_loc)
        current_config = add_tribler_config(current_config, tribler_cfg)
        os.remove(tribler_file_loc)

    # We also have to update all existing downloads, in particular, rename the section 'downloadconfig' to
    # 'download_defaults'.
    for _, filename in enumerate(iglob(
            os.path.join(state_dir, STATEDIR_DLPSTATE_DIR, '*.state'))):
        download_cfg = RawConfigParser()
        try:
            with open(filename) as cfg_file:
                download_cfg.readfp(cfg_file, filename=filename)
        except MissingSectionHeaderError:
            logger.error("Removing download state file %s since it appears to be corrupt", filename)
            os.remove(filename)

        try:
            download_items = download_cfg.items("downloadconfig")
            download_cfg.add_section("download_defaults")
            for download_item in download_items:
                download_cfg.set("download_defaults", download_item[0], download_item[1])
            download_cfg.remove_section("downloadconfig")
            with open(filename, "w") as output_config_file:
                download_cfg.write(output_config_file)
        except (NoSectionError, DuplicateSectionError):
            # This item has already been converted
            pass

    return current_config
开发者ID:Tribler,项目名称:tribler,代码行数:50,代码来源:config_converter.py

示例5: set_config

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import add_section [as 别名]
 def set_config(self, path, value):
     """Set entry in local configuration."""
     section, option = path.split('.', 1)
     filename = os.path.join(self.path, '.hg', 'hgrc')
     if six.PY2:
         value = value.encode('utf-8')
         section = section.encode('utf-8')
         option = option.encode('utf-8')
     config = RawConfigParser()
     config.read(filename)
     if not config.has_section(section):
         config.add_section(section)
     if (config.has_option(section, option) and
             config.get(section, option) == value):
         return
     config.set(section, option, value)
     with open(filename, 'w') as handle:
         config.write(handle)
开发者ID:saily,项目名称:weblate,代码行数:20,代码来源:vcs.py

示例6: set_config

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import add_section [as 别名]
 def set_config(self, path, value):
     """
     Set entry in local configuration.
     """
     section, option = path.split(".", 1)
     filename = os.path.join(self.path, ".hg", "hgrc")
     if six.PY2:
         value = value.encode("utf-8")
         section = section.encode("utf-8")
         option = option.encode("utf-8")
     config = RawConfigParser()
     config.read(filename)
     if not config.has_section(section):
         config.add_section(section)
     if config.has_option(section, option) and config.get(section, option) == value:
         return
     config.set(section, option, value)
     with open(filename, "w") as handle:
         config.write(handle)
开发者ID:nijel,项目名称:weblate,代码行数:21,代码来源:vcs.py

示例7: _merge_from_file

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import add_section [as 别名]
    def _merge_from_file(self, config_file):
        """
        Merge variables from ``config_file`` into the environment.

        Any variables in ``config_file`` that have already been set will be
        ignored (meaning this method will *not* try to override them, which
        would raise an exception).

        If ``config_file`` does not exist or is not a regular file, or if there
        is an error parsing ``config_file``, ``None`` is returned.

        Otherwise this method returns a ``(num_set, num_total)`` tuple
        containing first the number of variables that were actually set, and
        second the total number of variables found in ``config_file``.

        Also see `Env._merge()`.

        :param config_file: Path of the configuration file to load.
        """
        if not path.isfile(config_file):
            return None
        parser = RawConfigParser()
        try:
            parser.read(config_file)
        except ParsingError:
            return None
        if not parser.has_section(CONFIG_SECTION):
            parser.add_section(CONFIG_SECTION)
        items = parser.items(CONFIG_SECTION)
        if len(items) == 0:
            return 0, 0
        i = 0
        for (key, value) in items:
            if key not in self:
                self[key] = value
                i += 1
        if 'config_loaded' not in self: # we loaded at least 1 file
            self['config_loaded'] = True
        return i, len(items)
开发者ID:npmccallum,项目名称:freeipa,代码行数:41,代码来源:config.py

示例8: __spawn_instance

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import add_section [as 别名]
    def __spawn_instance(self):
        """
        Create and configure a new KRA instance using pkispawn.
        Creates a configuration file with IPA-specific
        parameters and passes it to the base class to call pkispawn
        """

        # Create an empty and secured file
        (cfg_fd, cfg_file) = tempfile.mkstemp()
        os.close(cfg_fd)
        pent = pwd.getpwnam(self.service_user)
        os.chown(cfg_file, pent.pw_uid, pent.pw_gid)
        self.tmp_agent_db = tempfile.mkdtemp(
                prefix="tmp-", dir=paths.VAR_LIB_IPA)
        tmp_agent_pwd = ipautil.ipa_generate_password()

        # Create a temporary file for the admin PKCS #12 file
        (admin_p12_fd, admin_p12_file) = tempfile.mkstemp()
        os.close(admin_p12_fd)

        # Create KRA configuration
        config = RawConfigParser()
        config.optionxform = str
        config.add_section("KRA")

        # Security Domain Authentication
        config.set("KRA", "pki_security_domain_https_port", "443")
        config.set("KRA", "pki_security_domain_password", self.admin_password)
        config.set("KRA", "pki_security_domain_user", self.admin_user)

        # issuing ca
        config.set("KRA", "pki_issuing_ca_uri", "https://%s" %
                   ipautil.format_netloc(self.fqdn, 443))

        # Server
        config.set("KRA", "pki_enable_proxy", "True")
        config.set("KRA", "pki_restart_configured_instance", "False")
        config.set("KRA", "pki_backup_keys", "True")
        config.set("KRA", "pki_backup_password", self.admin_password)

        # Client security database
        config.set("KRA", "pki_client_database_dir", self.tmp_agent_db)
        config.set("KRA", "pki_client_database_password", tmp_agent_pwd)
        config.set("KRA", "pki_client_database_purge", "True")
        config.set("KRA", "pki_client_pkcs12_password", self.admin_password)

        # Administrator
        config.set("KRA", "pki_admin_name", self.admin_user)
        config.set("KRA", "pki_admin_uid", self.admin_user)
        config.set("KRA", "pki_admin_email", "[email protected]")
        config.set("KRA", "pki_admin_password", self.admin_password)
        config.set("KRA", "pki_admin_nickname", "ipa-ca-agent")
        config.set("KRA", "pki_admin_subject_dn",
                   str(DN(('cn', 'ipa-ca-agent'), self.subject_base)))
        config.set("KRA", "pki_import_admin_cert", "False")
        config.set("KRA", "pki_client_admin_cert_p12", admin_p12_file)

        # Directory server
        config.set("KRA", "pki_ds_ldap_port", "389")
        config.set("KRA", "pki_ds_password", self.dm_password)
        config.set("KRA", "pki_ds_base_dn", six.text_type(self.basedn))
        config.set("KRA", "pki_ds_database", "ipaca")
        config.set("KRA", "pki_ds_create_new_db", "False")

        self._use_ldaps_during_spawn(config)

        # Certificate subject DNs
        config.set("KRA", "pki_subsystem_subject_dn",
                   str(DN(('cn', 'CA Subsystem'), self.subject_base)))
        config.set("KRA", "pki_sslserver_subject_dn",
                   str(DN(('cn', self.fqdn), self.subject_base)))
        config.set("KRA", "pki_audit_signing_subject_dn",
                   str(DN(('cn', 'KRA Audit'), self.subject_base)))
        config.set(
            "KRA", "pki_transport_subject_dn",
            str(DN(('cn', 'KRA Transport Certificate'), self.subject_base)))
        config.set(
            "KRA", "pki_storage_subject_dn",
            str(DN(('cn', 'KRA Storage Certificate'), self.subject_base)))

        # Certificate nicknames
        # Note that both the server certs and subsystem certs reuse
        # the ca certs.
        config.set("KRA", "pki_subsystem_nickname",
                   "subsystemCert cert-pki-ca")
        config.set("KRA", "pki_sslserver_nickname",
                   "Server-Cert cert-pki-ca")
        config.set("KRA", "pki_audit_signing_nickname",
                   "auditSigningCert cert-pki-kra")
        config.set("KRA", "pki_transport_nickname",
                   "transportCert cert-pki-kra")
        config.set("KRA", "pki_storage_nickname",
                   "storageCert cert-pki-kra")

        # Shared db settings
        # Needed because CA and KRA share the same database
        # We will use the dbuser created for the CA
        config.set("KRA", "pki_share_db", "True")
        config.set(
            "KRA", "pki_share_dbuser_dn",
#.........这里部分代码省略.........
开发者ID:stlaz,项目名称:freeipa,代码行数:103,代码来源:krainstance.py

示例9: RawConfigParser

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import add_section [as 别名]
from __future__ import print_function
import os
from six.moves.configparser import RawConfigParser

__author__ = 'alforbes'

try:
    CONFIG_FILE = os.environ['ORLO_CONFIG']
except KeyError:
    CONFIG_FILE = '/etc/orlo/orlo.ini'

config = RawConfigParser()

config.add_section('main')
config.set('main', 'time_format', '%Y-%m-%dT%H:%M:%SZ')
config.set('main', 'time_zone', 'UTC')
config.set('main', 'strict_slashes', 'false')
config.set('main', 'base_url', 'http://localhost:8080')

config.add_section('gunicorn')
config.set('gunicorn', 'workers', '4')

config.add_section('security')
config.set('security', 'enabled', 'false')
config.set('security', 'passwd_file', 'none')
config.set('security', 'secret_key', 'change_me')
# NOTE: orlo.__init__ checks that secret_key is not "change_me" when security
# is enabled. Do not change the default here without updating __init__ as well.
config.set('security', 'token_ttl', '3600')
config.set('security', 'ldap_server', 'localhost.localdomain')
config.set('security', 'ldap_port', '389')
开发者ID:al4,项目名称:orlo,代码行数:33,代码来源:config.py

示例10: RawConfigParser

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import add_section [as 别名]
from __future__ import print_function
import os
from six.moves.configparser import RawConfigParser

__author__ = 'alforbes'

try:
    CONFIG_FILE = os.environ['ORLO_CONFIG']
except KeyError:
    CONFIG_FILE = '/etc/orlo/orlo.ini'

config = RawConfigParser()

config.add_section('main')
config.set('main', 'debug_mode', 'false')
config.set('main', 'propagate_exceptions', 'true')
config.set('main', 'time_format', '%Y-%m-%dT%H:%M:%SZ')
config.set('main', 'time_zone', 'UTC')
config.set('main', 'strict_slashes', 'false')
config.set('main', 'base_url', 'http://localhost:8080')

config.add_section('security')
config.set('security', 'enabled', 'false')
config.set('security', 'passwd_file', 'none')
config.set('security', 'secret_key', 'change_me')
# NOTE: orlo.__init__ checks that secret_key is not "change_me" when security
# is enabled. Do not change the default here without updating __init__ as well.
config.set('security', 'token_ttl', '3600')
config.set('security', 'ldap_server', 'localhost.localdomain')
config.set('security', 'ldap_port', '389')
config.set('security', 'user_base_dn', 'ou=people,ou=example,o=test')
开发者ID:eBayClassifiedsGroup,项目名称:orlo,代码行数:33,代码来源:config.py


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