本文整理汇总了Python中iniparse.RawConfigParser.read方法的典型用法代码示例。如果您正苦于以下问题:Python RawConfigParser.read方法的具体用法?Python RawConfigParser.read怎么用?Python RawConfigParser.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iniparse.RawConfigParser
的用法示例。
在下文中一共展示了RawConfigParser.read方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _has_changed
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import read [as 别名]
def _has_changed(self):
'''
Check if the version on disk is different from what we have loaded
'''
on_disk = ConfigParser()
on_disk.read(self.path)
return not self._configparsers_equal(on_disk)
示例2: inifile_writestring
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import read [as 别名]
def inifile_writestring(inifilename,section,key,value):
"""Write a string parameter to inifile"""
inifile = RawConfigParser()
inifile.read(inifilename)
if not inifile.has_section(section):
inifile.add_section(section)
inifile.set(section,key,value)
inifile.write(open(inifilename,'w'))
示例3: inifile_readstring
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import read [as 别名]
def inifile_readstring(inifilename,section,key,default=None):
"""Read a string parameter from inifile"""
inifile = RawConfigParser()
inifile.read(inifilename)
if inifile.has_section(section) and inifile.has_option(section,key):
return inifile.get(section,key)
else:
return default
示例4: read_config
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import read [as 别名]
def read_config(filename,providers):
cp = RawConfigParser()
cp.read(filename)
while providers:
providers.pop()
for provider_name in cp.sections():
provider = Provider(provider_name)
provider.read_config(cp)
providers.append(provider)
示例5: read
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import read [as 别名]
def read(self):
ConfigParser.read(self, self.path)
示例6: RawConfigParser
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import read [as 别名]
import dialog
from iniparse import RawConfigParser
import shutil
import fileinput
import os, glob, sys
import hashlib
postconf = dialog.Dialog(dialog="dialog")
if postconf.yesno("Do you want to launch post configuration tool ?") == postconf.DIALOG_OK:
shutil.copyfile("/opt/wapt/waptserver/waptserver.ini.template", "/opt/wapt/waptserver/waptserver.ini")
waptserver_ini = RawConfigParser()
waptserver_ini.read("/opt/wapt/waptserver/waptserver.ini")
if os.path.isdir("/var/www/wapt"):
waptserver_ini.set("options", "wapt_folder", "/var/www/wapt")
code, tag = postconf.menu("Mongodb server location", choices=[("1", "localhost (default)"), ("2", "other server")])
if code == postconf.DIALOG_OK:
if tag == "1":
waptserver_ini.set("options", "mongodb_ip", "127.0.0.1")
elif tag == "2":
(code, mongodb_ip) = postconf.inputbox("IP address of the mongodb server:")
if code != postconf.DIALOG_OK:
exit(1)
else:
waptserver_ini.set("options", "mongodb_ip", mongodb_ip)
elif code != postconf.DIALOG_OK:
exit(1)
示例7: _enable_plugins
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import read [as 别名]
def _enable_plugins(cls, pkg_mgr_name, plugin_dir):
"""
This class method tries to enable plugins for DNF or YUM
:param pkg_mgr_name: It can be "dnf" or "yum"
:type pkg_mgr_name: str
:param plugin_dir: Directory with configuration files for (dnf/yum) plugins
:type plugin_dir: str
:return:
"""
# List of successfully enabled plugins
enabled_lugins = []
# Go through the list of yum plugins and try to find configuration
# file of these plugins.
for plugin_name in cls.PLUGINS:
plugin_file_name = plugin_dir + '/' + plugin_name + '.conf'
plugin_config = ConfigParser()
try:
result = plugin_config.read(plugin_file_name)
except Exception as err:
# Capture all errors during reading yum plugin conf file
# report them and skip this conf file
log.error(
"Error during reading %s plugin config file '%s': %s. Skipping this file." %
(pkg_mgr_name, plugin_file_name, err)
)
continue
if len(result) == 0:
log.warn('Configuration file of %s plugin: "%s" cannot be read' %
(pkg_mgr_name, plugin_file_name))
continue
is_plugin_enabled = False
if not plugin_config.has_section('main'):
log.warning(
'Configuration file of %s plugin: "%s" does not include main section. Adding main section.' %
(pkg_mgr_name, plugin_file_name)
)
plugin_config.add_section('main')
elif plugin_config.has_option('main', 'enabled'):
try:
# Options 'enabled' can be 0 or 1
is_plugin_enabled = plugin_config.getint('main', 'enabled')
except ValueError:
try:
# Options 'enabled' can be also: true or false
is_plugin_enabled = plugin_config.getboolean('main', 'enabled')
except ValueError:
log.warning(
"File %s has wrong value of options: 'enabled' in section: 'main' (not a int nor boolean)" %
plugin_file_name
)
if is_plugin_enabled == cls.PLUGIN_ENABLED:
log.debug('%s plugin: "%s" already enabled. Nothing to do.' %
(pkg_mgr_name, plugin_file_name))
else:
log.warning('Enabling %s plugin: "%s".' % (pkg_mgr_name, plugin_file_name))
# Change content of plugin configuration file and enable this plugin.
with open(plugin_file_name, 'w') as cfg_file:
plugin_config.set('main', 'enabled', cls.PLUGIN_ENABLED)
plugin_config.write(cfg_file)
enabled_lugins.append(plugin_file_name)
return enabled_lugins
示例8: RawConfigParser
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import read [as 别名]
defaults = {
'repositories':'',
'repo_url':'',
'default_source_url':'',
'gpgkey':'',
'default_development_base':'c:\tranquilit',
'default_package_prefix':'tis',
'default_sources_suffix':'wapt',
'default_sources_url':'',
'upload_cmd':'',
'wapt_server':'',
}
cp = RawConfigParser(defaults = defaults)
cp.add_section('global')
cp.read(config_file)
if len(logger.handlers)<1:
hdlr = logging.StreamHandler(sys.stdout)
hdlr.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(message)s'))
logger.addHandler(hdlr)
# set loglevel
if loglevel in ('debug','warning','info','error','critical'):
numeric_level = getattr(logging, loglevel.upper(), None)
if not isinstance(numeric_level, int):
raise ValueError('Invalid log level: %s' % loglevel)
logger.setLevel(numeric_level)
mywapt = Wapt(config=cp)
mywapt.wapt_repourl = mywapt.find_wapt_server()
示例9: main
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import read [as 别名]
def main():
if len(args) == 0:
print "ERROR : You must provide one action to perform"
parser.print_usage()
sys.exit(2)
action = args[0]
# Config file
if not os.path.isfile(config_file):
logger.error("Error : could not find file : " + config_file + ", please check the path")
logger.debug("Config file: %s" % config_file)
defaults = {
"repositories": "",
"repo_url": "",
"default_source_url": "",
"private_key": "",
"public_cert": "",
"default_development_base": "c:\tranquilit",
"default_package_prefix": "tis",
"default_sources_suffix": "wapt",
"default_sources_url": "",
"upload_cmd": "",
"wapt_server": "",
"loglevel": "info",
}
cp = RawConfigParser(defaults=defaults)
cp.add_section("global")
cp.read(config_file)
global loglevel
if not loglevel and cp.has_option("global", "loglevel"):
loglevel = cp.get("global", "loglevel")
setloglevel(loglevel)
mywapt = Wapt(config=cp)
if options.wapt_url:
mywapt.wapt_repourl = options.wapt_url
if options.private_key:
mywapt.private_key = options.private_key
else:
mywapt.private_key = cp.get("global", "private_key")
mywapt.dry_run = options.dry_run
# logger.info("Main wapt Repository %s" % mywapt.wapt_repourl)
logger.debug("WAPT base directory : %s" % mywapt.wapt_base_dir)
logger.debug("Package cache dir : %s" % mywapt.packagecachedir)
logger.debug("WAPT DB Structure version;: %s" % mywapt.waptdb.db_version)
try:
params_dict = {}
try:
params_dict = json.loads(options.params.replace("'", '"'))
except:
raise Exception("Install Parameters must be in json format")
if action == "install" or action == "download":
if len(args) < 2:
print "You must provide at least one package name"
sys.exit(1)
if os.path.isdir(args[1]) or os.path.isfile(args[1]):
print "installing WAPT file %s" % args[1]
if action == "install":
mywapt.install_wapt(args[1], params_dict=params_dict)
else:
print "%sing WAPT packages %s" % (action, ",".join(args[1:]))
if options.update_packages:
print "Update package list"
mywapt.update()
result = mywapt.install(
args[1:], force=options.force, params_dict=params_dict, download_only=(action == "download")
)
print "\nResults :"
if action <> "download":
for k in ("install", "additional", "upgrade", "skipped", "errors"):
if result.get(k, []):
print "\n=== %s packages ===\n%s" % (
k,
"\n".join(
[" %-30s | %s (%s)" % (s[0], s[1].package, s[1].version) for s in result[k]]
),
)
else:
for k in ("downloaded", "skipped", "errors"):
if result.get("downloads", {"downloaded": [], "skipped": [], "errors": []})[k]:
print "\n=== %s packages ===\n%s" % (
k,
"\n".join([" %s" % (s,) for s in result["downloads"][k]]),
)
elif action == "download":
if len(args) < 2:
print "You must provide at least one package name to download"
sys.exit(1)
#.........这里部分代码省略.........
示例10: enable_yum_plugins
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import read [as 别名]
def enable_yum_plugins(cls):
"""
This function tries to enable yum plugins: subscription-manager and product-id.
It takes no action, when automatic enabling of yum plugins is disabled in rhsm.conf.
:return: It returns list of enabled plugins
"""
# When user doesn't want to automatically enable yum plugins, then return empty list
if cls.is_auto_enable_enabled() is False:
log.info('The rhsm.auto_enable_yum_plugins is disabled. Skipping the enablement of yum plugins.')
return []
log.debug('The rhsm.auto_enable_yum_plugins is enabled')
# List of successfully enabled plugins
enabled_yum_plugins = []
# Go through the list of yum plugins and try to find configuration
# file of these plugins.
for yum_plugin_name in cls.YUM_PLUGINS:
yum_plugin_file_name = cls.YUM_PLUGIN_DIR + '/' + yum_plugin_name + '.conf'
yum_plugin_config = ConfigParser()
try:
result = yum_plugin_config.read(yum_plugin_file_name)
except Exception as err:
# Capture all errors during reading yum plugin conf file
# report them and skip this conf file
log.error(
"Error during reading yum plugin config file '%s': %s. Skipping this file." %
(yum_plugin_file_name, err)
)
continue
if len(result) == 0:
log.info('Configuration file of yum plugin: "%s" cannot be read' % yum_plugin_file_name)
continue
is_plugin_enabled = False
if not yum_plugin_config.has_section('main'):
log.warn(
'Configuration file of yum plugin: "%s" does not include main section. Adding main section.' %
yum_plugin_file_name
)
yum_plugin_config.add_section('main')
elif yum_plugin_config.has_option('main', 'enabled'):
try:
# Options 'enabled' can be 0 or 1
is_plugin_enabled = yum_plugin_config.getint('main', 'enabled')
except ValueError:
try:
# Options 'enabled' can be also: true or false
is_plugin_enabled = yum_plugin_config.getboolean('main', 'enabled')
except ValueError:
log.warn(
"File %s has wrong value of options: 'enabled' in section: 'main' (not a int nor boolean)" %
yum_plugin_file_name
)
if is_plugin_enabled == cls.YUM_PLUGIN_ENABLED:
log.debug('Yum plugin: "%s" already enabled. Nothing to do.' % yum_plugin_file_name)
else:
log.warn('Enabling yum plugin: "%s".' % yum_plugin_file_name)
# Change content of plugin configuration file and enable this plugin.
with open(yum_plugin_file_name, 'w') as cfg_file:
yum_plugin_config.set('main', 'enabled', cls.YUM_PLUGIN_ENABLED)
yum_plugin_config.write(cfg_file)
enabled_yum_plugins.append(yum_plugin_file_name)
return enabled_yum_plugins
示例11: get_packages_filenames
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import read [as 别名]
def get_packages_filenames(packages,with_depends=True,waptconfigfile=None,repo_name='wapt-templates',remoterepo=None,package_request=None):
"""Returns list of package filenames (latest version) and md5 matching comma separated list of packages names and their dependencies
helps to batch download a list of selected packages using tools like curl or wget
Args:
packages (list): list of package entries as dicts or PackageEntry
with_depends (bool): get recursively the all depends filenames
waptconfigfile (str): path to wapt ini file
repo_name : section name in wapt ini file for repo parameters (repo_url, http_proxy, timeout, verify_cert)
remoterepo (WaptRemoteRepo) : remote repo to query.
Mutually exclusive with waptconfigfile and repo_name
Returns:
list: list of (wapt file basename,md5)
>>> get_packages_filenames(r"c:\users\htouvet\AppData\Local\waptconsole\waptconsole.ini","tis-firefox-esr,tis-flash,tis-wapttest")
[u'tis-firefox-esr_24.4.0-0_all.wapt', u'tis-flash_12.0.0.77-3_all.wapt', u'tis-wapttest.wapt', u'tis-wapttestsub_0.1.0-1_all.wapt', u'tis-7zip_9.2.0-15_all.wapt']
"""
result = []
defaults = {
'repo_url':'https://store.wapt.fr/wapt',
'http_proxy':'',
'verify_cert':'0',
}
if remoterepo is None:
config = RawConfigParser(defaults=defaults)
config.read(waptconfigfile)
remoterepo = WaptRemoteRepo(name=repo_name,config=config)
remoterepo.update()
if package_request is not None and isinstance(package_request,dict):
package_request = PackageRequest(**package_request)
for pe in packages:
if not isinstance(pe,PackageEntry):
pe = PackageEntry(**pe)
# propagate capa to parent package
if package_request is None:
request_filter = PackageRequest()
if pe.locale != 'all' and pe.locale:
request_filter.locales = [pe.locale]
if pe.architecture != 'all' and pe.architecture:
request_filter.architectures = [pe.architecture]
if pe.min_os_version:
request_filter.min_os_version = pe.min_os_version
if pe.max_os_version:
request_filter.max_os_version = pe.max_os_version
else:
request_filter = package_request
result.append((pe.filename,pe.md5sum,))
if with_depends and pe.depends:
depends_list = []
for depname in ensure_list(pe.depends):
request_filter.request = depname
pe_dep = remoterepo.packages_matching(request_filter)
if pe_dep:
depends_list.append(pe_dep[-1])
for (fn,md5) in get_packages_filenames(depends_list,remoterepo = remoterepo):
if not fn in result:
result.append((fn,md5,))
return result
示例12: inifile_hasoption
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import read [as 别名]
def inifile_hasoption(inifilename,section,key):
"""Read a string parameter from inifile"""
inifile = RawConfigParser()
inifile.read(inifilename)
return inifile.has_section(section) and inifile.has_option(section,key)