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


Python RawConfigParser.set方法代码示例

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


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

示例1: set

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import set [as 别名]
 def set(self, section, option, new_value):
     with self.lock:
         if self.callback and self.has_section(section) and self.has_option(section, option):
             old_value = self.get(section, option)
             if not self.callback(section, option, new_value, old_value):
                 raise OperationNotPossibleAtRuntimeException
         RawConfigParser.set(self, section, option, new_value)
开发者ID:Tribler,项目名称:tribler,代码行数:9,代码来源:configparser.py

示例2: _test_write_pkispawn_config_file

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

示例3: convert_config_to_tribler71

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

示例4: get_config

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import set [as 别名]
def get_config(extra_locations=get_config_locations(), is_test=False):
    config = RawConfigParser()

    config.readfp(get_default_conf())

    conf_files = config.read(extra_locations)
    for conf_file in conf_files:
        config.readfp(open(conf_file, 'r'))

    # Not a huge fan of when developers think they're smarter than the
    # end-users, but I'm calling it a special case for testing
    is_travis = 'TRAVIS_BUILD_NUMBER' in os.environ
    is_pytest = hasattr(sys, '_called_from_test')
    if is_pytest or is_travis or is_test:
        config.set('metrik', 'mongo_database', 'metrik-test')

    return config
开发者ID:bspeice,项目名称:metrik,代码行数:19,代码来源:conf.py

示例5: set_config

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

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import set [as 别名]
def configure(opts):
    credential_path = os.path.join(os.path.expanduser("~"), ".carbonblack")
    credential_file = os.path.join(credential_path, "credentials.protection")

    print("Welcome to the CbAPI.")
    if os.path.exists(credential_file):
        print("An existing credential file exists at {0}.".format(credential_file))
        resp = input("Do you want to continue and overwrite the existing configuration? [Y/N] ")
        if resp.strip().upper() != "Y":
            print("Exiting.")
            return 1

    if not os.path.exists(credential_path):
        os.makedirs(credential_path, 0o700)

    url = input("URL to the Cb Protection server [https://hostname]: ")

    ssl_verify = None
    while ssl_verify not in ["Y", "N"]:
        ssl_verify = input("Use SSL/TLS certificate validation (answer 'N' if using self-signed certs) [Y/N]: ")
        ssl_verify = ssl_verify.strip().upper()

    if ssl_verify == "Y":
        ssl_verify = True
    else:
        ssl_verify = False

    token = input("API token: ")

    config = RawConfigParser()
    config.readfp(StringIO('[default]'))
    config.set("default", "url", url)
    config.set("default", "token", token)
    config.set("default", "ssl_verify", ssl_verify)
    with temp_umask(0):
        with os.fdopen(os.open(credential_file, os.O_WRONLY|os.O_CREAT|os.O_TRUNC, 0o600), 'w') as fp:
            os.chmod(credential_file, 0o600)
            config.write(fp)
    print("Successfully wrote credentials to {0}.".format(credential_file))
开发者ID:RyPeck,项目名称:cbapi-python,代码行数:41,代码来源:cli.py

示例8: set

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import set [as 别名]
 def set(self, section, option, value=None):
     if not self.has_section(section) and section.lower() != "default":
         self.add_section(section)
     RawConfigParser.set(self, section, option, value)
开发者ID:larsks,项目名称:cloud-init,代码行数:6,代码来源:helpers.py

示例9: __spawn_instance

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

示例10: RawConfigParser

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

示例11: Popen

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import set [as 别名]
      rescuedags[prevdags[-1]] = Nrescues + 1

      # run rescue DAG
      from subprocess import Popen
      x = Popen(['condor_submit_dag', prevdags[-1]])
      x.wait()
      if x.returncode != 0:
        errmsg = "Error... unable to submit rescue DAG for '%s'. Automation code is aborting." % prevdags[-1]
        remove_cron(cronid) # remove cron job
        if email != None:
          subject = sys.argv[0] + ': Error message'
          send_email(FROM, email, subject, errmsg, server)
        sys.exit(1)

      # add number of rescue DAGs to configuration file
      cp.set('configuration', 'rescue_dags', str(rescuedags))

      # Write out updated configuration file
      fc = open(inifile, 'w')
      cp.write(fc)
      fc.close()

      # wait until re-running
      try:
        # reset to run again later
        if timestep in ['hourly', 'daily']: # if hourly or daily just wait until the next run
          print("Running rescue DAG")
          os._exit(0) # don't use sys.exit(0) as this throws an exception that is caught by "except": https://stackoverflow.com/a/173323/1862861
        else: # add a day to the crontab job and re-run then
          cron = CronTab(user=True)
          for job in cron.find_comment(cronid):
开发者ID:lscsoft,项目名称:lalsuite,代码行数:33,代码来源:knope_automation_script.py


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