本文整理汇总了Python中iniparse.RawConfigParser类的典型用法代码示例。如果您正苦于以下问题:Python RawConfigParser类的具体用法?Python RawConfigParser怎么用?Python RawConfigParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RawConfigParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inifile_writestring
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'))
示例2: test_configparsers_equal_int
def test_configparsers_equal_int(self, tidy_writer, stub_create):
rf = YumRepoFile()
other = RawConfigParser()
for parser in [rf, other]:
parser.add_section('test')
parser.set('test', 'key', 'val')
rf.set('test', 'k', 1)
other.set('test', 'k', '1')
self.assertTrue(rf._configparsers_equal(other))
示例3: test_configparsers_equal_int
def test_configparsers_equal_int(self, tidy_writer, stub_create):
rf = RepoFile()
other = RawConfigParser()
for parser in [rf, other]:
parser.add_section("test")
parser.set("test", "key", "val")
rf.set("test", "k", 1)
other.set("test", "k", "1")
self.assertTrue(rf._configparsers_equal(other))
示例4: read_config
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: __init__
def __init__(self):
# http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
self.app_dir = join(getenv('XDG_DATA_HOME', expanduser('~/.local/share')), appname)
if not isdir(self.app_dir):
makedirs(self.app_dir)
self.plugin_dir = join(self.app_dir, 'plugins')
if not isdir(self.plugin_dir):
mkdir(self.plugin_dir)
self.home = expanduser('~')
self.respath = dirname(__file__)
self.filename = join(getenv('XDG_CONFIG_HOME', expanduser('~/.config')), appname, '%s.ini' % appname)
if not isdir(dirname(self.filename)):
makedirs(dirname(self.filename))
self.config = RawConfigParser()
try:
self.config.readfp(codecs.open(self.filename, 'r', 'utf-8'))
except:
self.config.add_section('config')
if not self.get('outdir') or not isdir(self.get('outdir')):
self.set('outdir', expanduser('~'))
示例6: inifile_readstring
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
示例7: __init__
def __init__(self):
# http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
self.app_dir = join(getenv("XDG_DATA_HOME", expanduser("~/.local/share")), appname)
if not isdir(self.app_dir):
makedirs(self.app_dir)
self.filename = join(getenv("XDG_CONFIG_HOME", expanduser("~/.config")), appname, "%s.ini" % appname)
if not isdir(dirname(self.filename)):
makedirs(dirname(self.filename))
self.config = RawConfigParser()
try:
self.config.readfp(codecs.open(self.filename, "r", "utf-8"))
except:
self.config.add_section("config")
if not self.get("outdir") or not isdir(self.get("outdir")):
self.set("outdir", expanduser("~"))
示例8: inifile_hasoption
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)
示例9: main
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: __init__
class Config:
OUT_EDDN = 1
OUT_BPC = 2
OUT_TD = 4
OUT_CSV = 8
if platform=='darwin':
def __init__(self):
self.app_dir = join(NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, True)[0], appname)
if not isdir(self.app_dir):
mkdir(self.app_dir)
self.bundle = getattr(sys, 'frozen', False) and NSBundle.mainBundle().bundleIdentifier() or 'uk.org.marginal.%s' % appname.lower() # Don't use Python's settings if interactive
self.defaults = NSUserDefaults.standardUserDefaults()
settings = self.defaults.persistentDomainForName_(self.bundle) or {}
self.settings = dict(settings)
# Check out_dir exists
if not self.get('outdir') or not isdir(self.get('outdir')):
self.set('outdir', NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True)[0])
def get(self, key):
return self.settings.get(key)
def getint(self, key):
try:
return int(self.settings.get(key, 0)) # should already be int, but check by casting
except:
return 0
def set(self, key, val):
self.settings[key] = val
def close(self):
self.defaults.setPersistentDomain_forName_(self.settings, self.bundle)
self.defaults.synchronize()
self.defaults = None
elif platform=='win32':
def __init__(self):
CSIDL_PERSONAL = 0x0005
CSIDL_LOCAL_APPDATA = 0x001C
buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
ctypes.windll.shell32.SHGetSpecialFolderPathW(0, buf, CSIDL_LOCAL_APPDATA, 0)
self.app_dir = join(buf.value, appname)
if not isdir(self.app_dir):
mkdir(self.app_dir)
self.handle = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, r'Software\%s' % appname)
if not self.get('outdir') or not isdir(self.get('outdir')):
ctypes.windll.shell32.SHGetSpecialFolderPathW(0, buf, CSIDL_PERSONAL, 0)
self.set('outdir', buf.value)
def get(self, key):
try:
return _winreg.QueryValueEx(self.handle, key)[0]
except:
return None
def getint(self, key):
try:
return int(_winreg.QueryValueEx(self.handle, key)[0]) # should already be int, but check by casting
except:
return 0
def set(self, key, val):
if isinstance(val, basestring):
_winreg.SetValueEx(self.handle, key, 0, _winreg.REG_SZ, val)
elif isinstance(val, numbers.Integral):
_winreg.SetValueEx(self.handle, key, 0, _winreg.REG_DWORD, val)
else:
raise NotImplementedError()
def close(self):
_winreg.CloseKey(self.handle)
self.handle = None
elif platform=='linux2':
def __init__(self):
# http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
self.app_dir = join(getenv('XDG_DATA_HOME', expanduser('~/.local/share')), appname)
if not isdir(self.app_dir):
makedirs(self.app_dir)
self.filename = join(getenv('XDG_CONFIG_HOME', expanduser('~/.config')), appname, '%s.ini' % appname)
if not isdir(dirname(self.filename)):
makedirs(dirname(self.filename))
self.config = RawConfigParser()
try:
self.config.readfp(codecs.open(self.filename, 'r', 'utf-8'))
# XXX handle missing?
except:
self.config.add_section('DEFAULT')
#.........这里部分代码省略.........
示例11: RawConfigParser
loglevel = 'debug'
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)
示例12: _has_changed
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)
示例13: 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 list(repo.items()):
ConfigParser.set(self, repo.id, k, v)
示例14: write
def write(self):
if not self.manage_repos:
log.debug("Skipping write due to manage_repos setting: %s" %
self.path)
return
if self._has_changed():
f = open(self.path, 'w')
tidy_writer = TidyWriter(f)
ConfigParser.write(self, tidy_writer)
tidy_writer.close()
f.close()
示例15: __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 = manage_repos_enabled()
# 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 self.path_exists(self.repos_dir):
log.warn("%s does not exist, turning manage_repos off." %
self.repos_dir)
self.manage_repos = False
self.create()