• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python simpleconfig.SimpleConfigFile类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyanaconda.simpleconfig.SimpleConfigFile的典型用法代码示例。如果您正苦于以下问题:Python SimpleConfigFile类的具体用法?Python SimpleConfigFile怎么用?Python SimpleConfigFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SimpleConfigFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: write_test

 def write_test(self):
     with tempfile.NamedTemporaryFile(mode="wt") as testconfig:
         scf = SimpleConfigFile()
         scf.set(('key1', 'value1'))
         scf.write(testconfig.name)
         testconfig.flush()
         self.assertEqual(open(testconfig.name).read(), 'KEY1=value1\n')
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:7,代码来源:simpleconfig_test.py


示例2: read_test

 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')
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:7,代码来源:simpleconfig_test.py


示例3: write

 def write(self, filename=None, use_tmp=False):
     if self._dirty or filename:
         # ifcfg-rh is using inotify IN_CLOSE_WRITE event so we don't use
         # temporary file for new configuration
         ifcfglog.debug("IfcfgFile.write %s:\n%s", self.filename, self.__str__())
         SimpleConfigFile.write(self, filename, use_tmp=use_tmp)
         self._dirty = False
开发者ID:uofis,项目名称:qubes-installer-qubes-os,代码行数:7,代码来源:network.py


示例4: set

 def set(self, *args):
     for (key, data) in args:
         if self.get(key) != data:
             break
     else:
         return
     ifcfglog.debug("IfcfgFile.set %s: %s", self.filename, args)
     SimpleConfigFile.set(self, *args)
     self._dirty = True
开发者ID:uofis,项目名称:qubes-installer-qubes-os,代码行数:9,代码来源:network.py


示例5: unset

 def unset(self, *args):
     for key in args:
         if self.get(key):
             self._dirty = True
             break
     else:
         return
     ifcfglog.debug("IfcfgFile.unset %s: %s", self.filename, args)
     SimpleConfigFile.unset(self, *args)
开发者ID:uofis,项目名称:qubes-installer-qubes-os,代码行数:9,代码来源:network.py


示例6: read_write_test

    def read_write_test(self):
        with tempfile.NamedTemporaryFile(mode="wt") as testconfig:
            testconfig.write(self.TEST_CONFIG)
            testconfig.flush()

            scf = SimpleConfigFile()
            scf.read(testconfig.name)
            scf.write(testconfig.name)
            testconfig.flush()
            self.assertEqual(open(testconfig.name).read(), self.TEST_CONFIG)
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:10,代码来源:simpleconfig_test.py


示例7: append_test

    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")
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:11,代码来源:simpleconfig_test.py


示例8: replace_test

    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")
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:11,代码来源:simpleconfig_test.py


示例9: no_append_test

    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"), "")
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:12,代码来源:simpleconfig_test.py


示例10: execute

    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)
开发者ID:rhinstaller,项目名称:docker-anaconda-addon,代码行数:60,代码来源:docker.py


示例11: execute

    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)
开发者ID:bcl,项目名称:docker-anaconda-addon,代码行数:58,代码来源:docker.py


示例12: read_write__perms_test

    def read_write__perms_test(self):
        with tempfile.NamedTemporaryFile(mode="wt") as testconfig:
            testconfig.write(self.TEST_CONFIG)
            testconfig.flush()

            # Change original file's permissions
            os.chmod(testconfig.name, 0o0764)

            scf = SimpleConfigFile()
            scf.read(testconfig.name)
            scf.write(testconfig.name)
            testconfig.flush()

            # Write uses a tmpfile and renames it in place
            # Make sure the permissions are still 0764
            self.assertEqual(os.stat(testconfig.name).st_mode, 0o100764)
开发者ID:rvykydal,项目名称:anaconda,代码行数:16,代码来源:simpleconfig_test.py


示例13: write_new_keys_test

 def write_new_keys_test(self):
     from pyanaconda.simpleconfig import SimpleConfigFile
     scf = SimpleConfigFile()
     scf.read(self.PATH)
     scf.set(("key1", "value1"))
     scf.write("/tmp/file")
     self.assertEqual(open("/tmp/file").read(),
                      self.CONTENT+"KEY1=value1\n")
开发者ID:Sabayon,项目名称:anaconda,代码行数:8,代码来源:simpleconfig_test.py


示例14: write_new_keys_test

    def write_new_keys_test(self):
        with tempfile.NamedTemporaryFile(mode="wt") as testconfig:
            testconfig.write(self.TEST_CONFIG)
            testconfig.flush()

            scf = SimpleConfigFile()
            scf.read(testconfig.name)
            scf.set(("key1", "value1"))
            scf.write(testconfig.name)
            testconfig.flush()

            self.assertEqual(open(testconfig.name).read(),
                             self.TEST_CONFIG+"KEY1=value1\n")
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:13,代码来源:simpleconfig_test.py


示例15: comment_test

    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)
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:11,代码来源:simpleconfig_test.py


示例16: no_use_tmp_test

    def no_use_tmp_test(self):
        with tempfile.NamedTemporaryFile(mode="w+t") as testconfig:
            # Write a starting file and keep the handle open
            testconfig.write("KEY1=value1\n")
            testconfig.flush()
            testconfig.seek(0)

            # Overwrite the value and write a new file
            scf = SimpleConfigFile()
            scf.read(testconfig.name)
            scf.set(('key1', 'value2'))
            scf.write(testconfig.name, use_tmp=False)

            # Check the new contents
            self.assertEqual(open(testconfig.name).read(), 'KEY1=value2\n')

            # Check that the original file handle points to the replaced contents
            self.assertEqual(testconfig.read(), 'KEY1=value2\n')
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:18,代码来源:simpleconfig_test.py


示例17: use_tmp_multifs_test

    def use_tmp_multifs_test(self):
        # Open a file on a non-default filesystem
        with tempfile.NamedTemporaryFile(dir='/dev/shm', mode='w+t') as testconfig:
            # Write a starting file and keep the handle open
            testconfig.write("KEY1=value1\n")
            testconfig.flush()
            testconfig.seek(0)

            # Overwrite the value and write a new file
            scf = SimpleConfigFile()
            scf.read(testconfig.name)
            scf.set(('key1', 'value2'))
            scf.write(testconfig.name, use_tmp=True)

            # Check the new contents
            self.assertEqual(open(testconfig.name).read(), 'KEY1=value2\n')

            # Check that the original file handle still points to the old contents
            self.assertEqual(testconfig.read(), 'KEY1=value1\n')
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:19,代码来源:simpleconfig_test.py


示例18: execute

    def execute(self):
        security_proxy = SECURITY.get_proxy()
        selinux = security_proxy.SELinux

        if selinux == SELINUX_DEFAULT:
            selinux_log.debug("Use SELinux default configuration.")
            return

        if selinux not in self.SELINUX_STATES:
            selinux_log.error("Unknown SELinux state for %s.", selinux)
            return

        try:
            selinux_cfg = SimpleConfigFile(util.getSysroot() + "/etc/selinux/config")
            selinux_cfg.read()
            selinux_cfg.set(("SELINUX", self.SELINUX_STATES[selinux]))
            selinux_cfg.write()
        except IOError as msg:
            selinux_log.error("SELinux configuration failed: %s", msg)
开发者ID:rvykydal,项目名称:anaconda,代码行数:19,代码来源:kickstart.py


示例19: read_write_test

 def read_write_test(self):
     from pyanaconda.simpleconfig import SimpleConfigFile
     scf = SimpleConfigFile()
     scf.read(self.PATH)
     scf.write("/tmp/file")
     self.assertEqual(open("/tmp/file").read(), self.CONTENT)
开发者ID:Sabayon,项目名称:anaconda,代码行数:6,代码来源:simpleconfig_test.py


示例20: remove_key_test

    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"), "")
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:14,代码来源:simpleconfig_test.py



注:本文中的pyanaconda.simpleconfig.SimpleConfigFile类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python threadMgr.add函数代码示例发布时间:2022-05-25
下一篇:
Python progressQ.send_message函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap