本文整理汇总了Python中six.moves.configparser.ConfigParser.set方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.set方法的具体用法?Python ConfigParser.set怎么用?Python ConfigParser.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves.configparser.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: log_in
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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
示例2: _load_ec_as_default_policy
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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
示例3: setUp
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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
示例4: _save
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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))
示例5: as_ini
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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()
示例6: dump
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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
示例7: _modify_wpr_file
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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)
示例8: add_repo
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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 dnf repository
:param str name: repository base file name
:param str uri: repository URI
:param repo_type: repostory type name
:param int prio: dnf 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_dnf_dir['reposd-dir'] + '/' + name + '.repo'
self.repo_names.append(name + '.repo')
if os.path.exists(uri):
# dnf 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)
)
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(repo)
示例9: _load_domain_remap_staticweb
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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
示例10: _in_process_setup_swift_conf
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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
示例11: _in_process_setup_swift_conf
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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
示例12: add_repo
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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)
示例13: _load_encryption
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [as 别名]
def _load_encryption(proxy_conf_file, swift_conf_file, **kwargs):
"""
Load encryption configuration and override proxy-server.conf contents.
: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 encryption')
# 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'
pipeline = conf.get(section, 'pipeline')
pipeline = pipeline.replace(
"proxy-logging proxy-server",
"keymaster encryption proxy-logging proxy-server")
conf.set(section, 'pipeline', pipeline)
root_secret = os.urandom(32).encode("base64")
conf.set('filter:keymaster', 'encryption_root_secret', root_secret)
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
示例14: process_mistral_config
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [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)
示例15: run
# 需要导入模块: from six.moves.configparser import ConfigParser [as 别名]
# 或者: from six.moves.configparser.ConfigParser import set [as 别名]
def run(self, args, **kwargs):
if not args.password:
args.password = getpass.getpass()
instance = self.resource(ttl=args.ttl) if args.ttl else self.resource()
cli = BaseCLIApp()
# Determine path to config file
try:
config_file = cli._get_config_file_path(args)
except ValueError:
# config file not found in args or in env, defaulting
config_file = config_parser.ST2_CONFIG_PATH
# Retrieve token
manager = self.manager.create(instance, auth=(args.username, args.password), **kwargs)
cli._cache_auth_token(token_obj=manager)
# Update existing configuration with new credentials
config = ConfigParser()
config.read(config_file)
# Modify config (and optionally populate with password)
if not config.has_section('credentials'):
config.add_section('credentials')
config.set('credentials', 'username', args.username)
if args.write_password:
config.set('credentials', 'password', args.password)
else:
# Remove any existing password from config
config.remove_option('credentials', 'password')
with open(config_file, 'w') as cfg_file_out:
config.write(cfg_file_out)
return manager