本文整理汇总了Python中pyanaconda.simpleconfig.SimpleConfigFile.get方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleConfigFile.get方法的具体用法?Python SimpleConfigFile.get怎么用?Python SimpleConfigFile.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyanaconda.simpleconfig.SimpleConfigFile
的用法示例。
在下文中一共展示了SimpleConfigFile.get方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: comment_test
# 需要导入模块: from pyanaconda.simpleconfig import SimpleConfigFile [as 别名]
# 或者: from pyanaconda.simpleconfig.SimpleConfigFile import get [as 别名]
def comment_test(self):
with tempfile.NamedTemporaryFile(mode="wt") as testconfig:
testconfig.write(self.TEST_CONFIG)
testconfig.flush()
config = SimpleConfigFile(testconfig.name)
config.read()
self.assertEqual(config.get("ESSID"), "Example Network #1")
self.assertEqual(config.get("ESSID2"), "Network #2")
self.assertEqual(config.get("COMMENT"), "Save this string")
self.assertEqual(str(config), self.TEST_CONFIG)
示例2: set_and_get_test
# 需要导入模块: from pyanaconda.simpleconfig import SimpleConfigFile [as 别名]
# 或者: from pyanaconda.simpleconfig.SimpleConfigFile import get [as 别名]
def set_and_get_test(self):
"""Setting and getting values"""
scf = SimpleConfigFile()
scf.set(('key1', 'value1'))
self.assertEqual(scf.get('key1'), 'value1')
scf.set(('KEY2', 'value2'))
self.assertEqual(scf.get('key2'), 'value2')
scf.set(('KEY3', 'value3'))
self.assertEqual(scf.get('KEY3'), 'value3')
scf.set(('key4', 'value4'))
self.assertEqual(scf.get('KEY4'), 'value4')
示例3: no_append_test
# 需要导入模块: from pyanaconda.simpleconfig import SimpleConfigFile [as 别名]
# 或者: from pyanaconda.simpleconfig.SimpleConfigFile import get [as 别名]
def no_append_test(self):
with tempfile.NamedTemporaryFile(mode="wt") as testconfig:
testconfig.write(self.TEST_CONFIG)
testconfig.flush()
keys = [("BOOT", "BOOT=sometimes"), ("NEWKEY", "NEWKEY=froboz")]
simple_replace(testconfig.name, keys, add=False)
config = SimpleConfigFile(testconfig.name)
config.read()
self.assertEqual(config.get("BOOT"), "sometimes")
self.assertEqual(config.get("NEWKEY"), "")
示例4: remove_key_test
# 需要导入模块: from pyanaconda.simpleconfig import SimpleConfigFile [as 别名]
# 或者: from pyanaconda.simpleconfig.SimpleConfigFile import get [as 别名]
def remove_key_test(self):
with tempfile.NamedTemporaryFile(mode="wt") as testconfig:
testconfig.write(self.TEST_CONFIG)
testconfig.flush()
scf = SimpleConfigFile()
scf.read(testconfig.name)
self.assertEqual(scf.get("BOOT"), "always")
scf.unset("BOOT")
scf.write(testconfig.name)
testconfig.flush()
scf.reset()
scf.read(testconfig.name)
self.assertEqual(scf.get("BOOT"), "")
示例5: read_test
# 需要导入模块: from pyanaconda.simpleconfig import SimpleConfigFile [as 别名]
# 或者: from pyanaconda.simpleconfig.SimpleConfigFile import get [as 别名]
def read_test(self):
with tempfile.NamedTemporaryFile(mode="wt") as testconfig:
scf = SimpleConfigFile()
open(testconfig.name, 'w').write('KEY1="value1"\n')
testconfig.flush()
scf.read(testconfig.name)
self.assertEqual(scf.get('key1'), 'value1')
示例6: execute
# 需要导入模块: from pyanaconda.simpleconfig import SimpleConfigFile [as 别名]
# 或者: from pyanaconda.simpleconfig.SimpleConfigFile import get [as 别名]
def execute(self, storage, ksdata, instClass, users, payload):
""" Execute the addon
:param storage: Blivet storage object
:param ksdata: Kickstart data object
:param instClass: Anaconda installclass object
:param users: Anaconda users object
:param payload: object managing packages and environment groups
for the installation
"""
if not self.enabled:
return
log.info("Executing docker addon")
# This gets called after installation, before initramfs regeneration and kickstart %post scripts.
execWithRedirect("mount", ["-o", "bind", getSysroot()+"/var/lib/docker", "/var/lib/docker"])
execWithRedirect("mount", ["-o", "bind", getSysroot()+"/etc/docker", "/etc/docker"])
# Start up the docker daemon
log.debug("Starting docker daemon")
docker_cmd = ["docker", "daemon"]
if ksdata.selinux.selinux:
docker_cmd += ["--selinux-enabled"]
# Add storage specific arguments to the command
docker_cmd += self.storage.docker_cmd(storage, ksdata, instClass, users)
docker_cmd += ["--ip-forward=false", "--iptables=false"]
docker_cmd += self.extra_args
docker_proc = startProgram(docker_cmd, stdout=open("/tmp/docker-daemon.log", "w"), reset_lang=True)
log.debug("Running docker commands")
script = AnacondaKSScript(self.content, inChroot=False, logfile="/tmp/docker-addon.log")
script.run("/")
# Kill the docker process
log.debug("Shutting down docker daemon")
docker_proc.kill()
log.debug("Writing docker configs")
self.storage.write_configs(storage, ksdata, instClass, users)
# Rewrite the OPTIONS entry with the extra args and/or storage specific changes
try:
docker_cfg = SimpleConfigFile(getSysroot()+"/etc/sysconfig/docker")
docker_cfg.read()
options = self.storage.options(docker_cfg.get("OPTIONS"))
if self.save_args:
log.info("Adding extra args to docker OPTIONS")
options += " " + " ".join(self.extra_args)
docker_cfg.set(("OPTIONS", options))
docker_cfg.write()
except IOError as e:
log.error("Error updating OPTIONS in /etc/sysconfig/docker: %s", e)
# Copy the log files to the system
dstdir = "/var/log/anaconda/"
os.makedirs(dstdir, exist_ok=True)
for l in ["docker-daemon.log", "docker-addon.log"]:
shutil.copy2("/tmp/"+l, dstdir+l)
示例7: execute
# 需要导入模块: from pyanaconda.simpleconfig import SimpleConfigFile [as 别名]
# 或者: from pyanaconda.simpleconfig.SimpleConfigFile import get [as 别名]
def execute(self, storage, ksdata, instClass, users):
""" Execute the addon
:param storage: Blivet storage object
:param ksdata: Kickstart data object
:param instClass: Anaconda installclass object
:param users: Anaconda users object
"""
log.info("Executing docker addon")
# This gets called after installation, before initramfs regeneration and kickstart %post scripts.
execWithRedirect("mount", ["-o", "bind", getSysroot()+"/var/lib/docker", "/var/lib/docker"])
execWithRedirect("mount", ["-o", "bind", getSysroot()+"/etc/docker", "/etc/docker"])
# Start up the docker daemon
log.debug("Starting docker daemon")
dm_fs = "dm.fs=%s" % self.fstype
pool_name = "dm.thinpooldev=/dev/mapper/%s-docker--pool" % self.vgname
docker_cmd = ["docker", "daemon"]
if ksdata.selinux.selinux:
docker_cmd += ["--selinux-enabled"]
docker_cmd += ["--storage-driver", "devicemapper",
"--storage-opt", dm_fs,
"--storage-opt", pool_name, "--ip-forward=false", "--iptables=false"]
docker_cmd += self.extra_args
docker_proc = startProgram(docker_cmd, stdout=open("/tmp/docker-daemon.log", "w"), reset_lang=True)
log.debug("Running docker commands")
script = AnacondaKSScript(self.content, inChroot=False, logfile="/tmp/docker-addon.log")
script.run("/")
# Kill the docker process
log.debug("Shutting down docker daemon")
docker_proc.kill()
log.debug("Writing docker configs")
with open(getSysroot()+"/etc/sysconfig/docker-storage", "w") as fp:
fp.write('DOCKER_STORAGE_OPTIONS="--storage-driver devicemapper '
'--storage-opt %s --storage-opt %s"\n' % (dm_fs, pool_name))
with open(getSysroot()+"/etc/sysconfig/docker-storage-setup", "a") as fp:
fp.write("VG=%s\n" % self.vgname)
# Rewrite the OPTIONS entry with the extra args, if requested.
if self.extra_args and self.save_args:
try:
docker_cfg = SimpleConfigFile(getSysroot()+"/etc/sysconfig/docker")
docker_cfg.read()
options = docker_cfg.get("OPTIONS")+" " + " ".join(self.extra_args)
docker_cfg.set(("OPTIONS", options))
docker_cfg.write()
except IOError as e:
log.error("Error updating OPTIONS in /etc/sysconfig/docker: %s", e)
# Copy the log files to the system
dstdir = "/var/log/anaconda/"
os.makedirs(dstdir, exist_ok=True)
for l in ["docker-daemon.log", "docker-addon.log"]:
shutil.copy2("/tmp/"+l, dstdir+l)
示例8: remove_key_test
# 需要导入模块: from pyanaconda.simpleconfig import SimpleConfigFile [as 别名]
# 或者: from pyanaconda.simpleconfig.SimpleConfigFile import get [as 别名]
def remove_key_test(self):
from pyanaconda.simpleconfig import SimpleConfigFile
scf = SimpleConfigFile()
scf.read(self.PATH)
scf.unset("BOOT")
scf.write("/tmp/file")
scf.reset()
scf.read("/tmp/file")
self.assertEqual(scf.get("BOOT"), "")
示例9: append_test
# 需要导入模块: from pyanaconda.simpleconfig import SimpleConfigFile [as 别名]
# 或者: from pyanaconda.simpleconfig.SimpleConfigFile import get [as 别名]
def append_test(self):
with tempfile.NamedTemporaryFile(mode="wt") as testconfig:
testconfig.write(self.TEST_CONFIG)
testconfig.flush()
keys = [("NEWKEY", "NEWKEY=froboz")]
simple_replace(testconfig.name, keys)
config = SimpleConfigFile(testconfig.name)
config.read()
self.assertEqual(config.get("NEWKEY"), "froboz")
示例10: replace_test
# 需要导入模块: from pyanaconda.simpleconfig import SimpleConfigFile [as 别名]
# 或者: from pyanaconda.simpleconfig.SimpleConfigFile import get [as 别名]
def replace_test(self):
with tempfile.NamedTemporaryFile(mode="wt") as testconfig:
testconfig.write(self.TEST_CONFIG)
testconfig.flush()
keys = [("BOOT", "BOOT=never")]
simple_replace(testconfig.name, keys)
config = SimpleConfigFile(testconfig.name)
config.read()
self.assertEqual(config.get("BOOT"), "never")
示例11: unset_test
# 需要导入模块: from pyanaconda.simpleconfig import SimpleConfigFile [as 别名]
# 或者: from pyanaconda.simpleconfig.SimpleConfigFile import get [as 别名]
def unset_test(self):
scf = SimpleConfigFile()
scf.set(('key1', 'value1'))
scf.unset(('key1'))
self.assertEqual(scf.get('key1'), '')