本文整理汇总了Python中iniparse.ConfigParser类的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser类的具体用法?Python ConfigParser怎么用?Python ConfigParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self, command, output_dir, vars):
common.Template.post(self, command, output_dir, vars)
#etc = os.path.join(vars['path'], 'etc', 'plone')
#if not os.path.isdir(etc):
# os.makedirs(etc)
cfg = os.path.join(vars['path'], 'etc', 'base.cfg')
dst = os.path.join(vars['path'],
'etc', 'plone', 'plone%s.buildout.cfg' % vars['major'])
vdst = os.path.join(vars['path'],
'etc', 'plone', 'plone%s.versions.cfg' % vars['major'])
sdst = os.path.join(vars['path'],
'etc', 'plone', 'plone%s.sources.cfg' % vars['major'])
ztkdst = os.path.join(vars['path'], 'etc', 'plone', 'ztk.versions.cfg')
zaztkdst = os.path.join(vars['path'], 'etc', 'plone', 'zopeapp.versions.cfg')
zdst = os.path.join(vars['path'],
'etc', 'plone', 'zope2.versions.cfg')
os.rename(os.path.join(vars['path'], 'gitignore'),
os.path.join(vars['path'], '.gitignore'))
bc = ConfigParser()
bc.read(cfg)
for f in (glob(os.path.join(output_dir, 'scripts/*'))
+ glob(os.path.join(output_dir, 'etc/hudson/%s/build/*' % vars['project']))
):
os.chmod(f, 0700)
# release KGS
#try:
# open(vdst, 'w').write(
# urllib2.urlopen(vars['versions_url']).read()
# )
#except Exception, e:
suffix = vars['major']
if vars['major'] > 3:
suffix = self.name.replace('minitage.plone', '')
示例2: config
def config(cfgname, inisect):
cfg = { }
cfgpr = ConfigParser()
try:
cfgpr.readfp(open(cfgname))
except IOError, e:
raise ConfigError(str(e))
示例3: __init__
def __init__(self, name='redhat.repo'):
ConfigParser.__init__(self)
self.path = Path.join(self.PATH, name)
self.manage_repos = 1
if CFG.has_option('rhsm', 'manage_repos'):
self.manage_repos = int(CFG.get('rhsm', 'manage_repos'))
self.create()
示例4: checkSSLvdsm
def checkSSLvdsm(self):
"""check if vdsm is running as SSL or without it"""
cfg = ConfigParser()
cfg.read('/etc/vdsm/vdsm.conf')
cfg.get('vars', 'ssl')
return cfg.data.vars.ssl
示例5: write
def write(self):
if not self.manage_repos:
log.debug("Skipping write due to manage_repos setting: %s" %
self.path)
return
f = open(self.path, 'w')
tidy_writer = TidyWriter(f)
ConfigParser.write(self, tidy_writer)
tidy_writer.close()
f.close()
示例6: update
def update(self, repo):
# Need to clear out the old section to allow unsetting options:
# don't use remove section though, as that will reorder sections,
# and move whitespace around (resulting in more and more whitespace
# as time progresses).
for (k, v) in self.items(repo.id):
self.remove_option(repo.id, k)
for k, v in repo.items():
ConfigParser.set(self, repo.id, k, v)
示例7: parseDesktopFile
def parseDesktopFile(self):
"""
Getting all necessary data from *.dektop file of the app
"""
cmd = 'ls -d /usr/share/applications/* | grep ".*%s.desktop"' % self.desktopFileName
proc = Popen(cmd, shell=True, stdout=PIPE)
# !HAVE TO check if the command and its desktop file exist
if proc.wait() != 0:
raise Exception("*.desktop file of the app not found")
output = proc.communicate()[0].rstrip()
desktopConfig = ConfigParser()
desktopConfig.read(output)
return desktopConfig
示例8: test_not_enabling_disabled_yum_plugin
def test_not_enabling_disabled_yum_plugin(self):
"""
Test not enabling (disabled in rhsm.conf) of configuration files of disabled plugins
"""
self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_DISABLED_BOOL)
plugin_list = YumPluginManager.enable_pkg_plugins()
self.assertEqual(len(plugin_list), 0)
for plugin_conf_file_name in YumPluginManager.PLUGINS:
yum_plugin_config = ConfigParser()
result = yum_plugin_config.read(YumPluginManager.YUM_PLUGIN_DIR + '/' + plugin_conf_file_name + '.conf')
self.assertGreater(len(result), 0)
is_plugin_enabled = yum_plugin_config.getboolean('main', 'enabled')
self.assertEqual(is_plugin_enabled, False)
self.restore_yum_plugin_conf_files()
示例9: test_enabling_yum_plugin_with_wrong_conf
def test_enabling_yum_plugin_with_wrong_conf(self):
"""
Test automatic enabling of configuration files of already plugins with wrong values in conf file.
"""
self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_WRONG_VALUE)
plugin_list = YumPluginManager.enable_pkg_plugins()
self.assertEqual(len(plugin_list), 2)
for plugin_conf_file_name in YumPluginManager.PLUGINS:
yum_plugin_config = ConfigParser()
result = yum_plugin_config.read(YumPluginManager.YUM_PLUGIN_DIR + '/' + plugin_conf_file_name + '.conf')
self.assertGreater(len(result), 0)
is_plugin_enabled = yum_plugin_config.getint('main', 'enabled')
self.assertEqual(is_plugin_enabled, 1)
self.restore_yum_plugin_conf_files()
示例10: test_enabling_enabled_yum_plugin_int
def test_enabling_enabled_yum_plugin_int(self):
"""
Test automatic enabling of configuration files of already enabled plugins
"""
self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_ENABLED_INT)
plugin_list = YumPluginManager.enable_pkg_plugins()
self.assertEqual(len(plugin_list), 0)
for plugin_conf_file_name in YumPluginManager.PLUGINS:
yum_plugin_config = ConfigParser()
result = yum_plugin_config.read(YumPluginManager.YUM_PLUGIN_DIR + '/' + plugin_conf_file_name + '.conf')
self.assertGreater(len(result), 0)
is_plugin_enabled = yum_plugin_config.getint('main', 'enabled')
self.assertEqual(is_plugin_enabled, 1)
self.restore_yum_plugin_conf_files()
示例11: test_enabling_enabled_yum_plugin_bool
def test_enabling_enabled_yum_plugin_bool(self):
"""
Test automatic enabling of configuration files of already enabled plugins
"""
self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_ENABLED_BOOL)
plugin_list = YumPluginManager.enable_pkg_plugins()
self.assertEqual(len(plugin_list), 0)
for plugin_conf_file_name in YumPluginManager.PLUGINS:
yum_plugin_config = ConfigParser()
result = yum_plugin_config.read(YumPluginManager.YUM_PLUGIN_DIR + '/' + plugin_conf_file_name + '.conf')
self.assertGreater(len(result), 0)
# The file was not modified. We have to read value with with getboolean()
is_plugin_enabled = yum_plugin_config.getboolean('main', 'enabled')
self.assertEqual(is_plugin_enabled, True)
self.restore_yum_plugin_conf_files()
示例12: __init__
def __init__(self, name='redhat.repo'):
ConfigParser.__init__(self)
# note PATH get's expanded with chroot info, etc
self.path = Path.join(self.PATH, name)
self.repos_dir = Path.abs(self.PATH)
self.manage_repos = 1
if CFG.has_option('rhsm', 'manage_repos'):
self.manage_repos = int(CFG.get('rhsm', 'manage_repos'))
# Simulate manage repos turned off if no yum.repos.d directory exists.
# This indicates yum is not installed so clearly no need for us to
# manage repos.
if not os.path.exists(self.repos_dir):
log.warn("%s does not exist, turning manage_repos off." %
self.repos_dir)
self.manage_repos = 0
self.create()
示例13: config
def config(cfgname, inisect):
cfg = { }
cfgpr = ConfigParser()
try:
cfgpr.read(cfgname)
cfg["sleep"] = cfgpr.get(inisect, "sleep")
cfg["cmd"] = cfgpr.get(inisect, "cmd")
cfg["file"] = cfgpr.get(inisect, "file")
cfg["s3mode"] = cfgpr.get(inisect, "s3mode")
cfg["s3host"] = cfgpr.get(inisect, "s3host")
cfg["s3user"] = cfgpr.get(inisect, "s3user")
cfg["s3pass"] = cfgpr.get(inisect, "s3pass")
cfg["bucket"] = cfgpr.get(inisect, "s3bucket")
cfg["prefix"] = cfgpr.get(inisect, "prefix")
except NoSectionError:
# Unfortunately if the file does not exist, we end here.
raise ConfigError("Unable to open or find section " + inisect)
except NoOptionError, e:
raise ConfigError(str(e))
示例14: write
def write(self,
path=None,
dependencies = None,
src_uri = None,
description = None,
install_method = None,
src_type = None,
url = None,
revision = None,
category = None,
src_opts = None,
src_md5 = None,
python = None,
scm_branch = None,
):
"""Store/Update the minibuild config
"""
to_write = OrderedDict(
[('dependencies', dependencies),
('src_uri', src_uri),
('install_method', install_method),
('src_type', src_type),
('revision', revision),
('category', category),
('description', description),
('src_md5', src_md5),
('url', url),
('src_opts', src_opts),
('python', python),
('scm_branch', scm_branch),]
)
# open config
if not path:
path = self.path
shutil.copy2(path, path+'.sav')
wconfig = WritableConfigParser()
wconfig.read(path)
for metadata in to_write:
value = to_write[metadata]
if isinstance(value, list):
if len(value) < 1:
value = None
else:
value = ' '.join(value)
if value is not None:
wconfig.set('minibuild' , metadata, value)
# write back cofig
fic = open(path, 'w')
wconfig.write(fic)
fic.flush()
fic.close()
newline(path)
# reload minibuild
self.load()
示例15: _apply
def _apply():
debug('Write ini settings to %s' % filename)
debug(config)
cfg = ConfigParser()
cfg.read(filename)
for section, values in config.items():
if not cfg.has_section(section):
if strict_sections:
raise Exception('No section %s in ini file %s' % (section, filename))
else:
cfg.add_section(section)
for key, val in values.items():
cfg.set(section, key, val)
with open(filename, 'w') as configfile:
cfg.write(configfile)
event(on_apply)