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

Python iutil.execReadlines函数代码示例

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

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



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

示例1: exec_readlines_test_filter_stderr

    def exec_readlines_test_filter_stderr(self):
        """Test execReadlines and filter_stderr."""

        # Test that stderr is normally included
        with tempfile.NamedTemporaryFile(mode="w+t") as testscript:
            testscript.write("""#!/bin/sh
echo "one"
echo "two" >&2
echo "three"
exit 0
""")
            testscript.flush()

            with timer(5):
                rl_iterator = iutil.execReadlines("/bin/sh", [testscript.name])
                self.assertEqual(next(rl_iterator), "one")
                self.assertEqual(next(rl_iterator), "two")
                self.assertEqual(next(rl_iterator), "three")
                self.assertRaises(StopIteration, rl_iterator.__next__)

        # Test that filter stderr removes the middle line
        with tempfile.NamedTemporaryFile(mode="w+t") as testscript:
            testscript.write("""#!/bin/sh
echo "one"
echo "two" >&2
echo "three"
exit 0
""")
            testscript.flush()

            with timer(5):
                rl_iterator = iutil.execReadlines("/bin/sh", [testscript.name], filter_stderr=True)
                self.assertEqual(next(rl_iterator), "one")
                self.assertEqual(next(rl_iterator), "three")
                self.assertRaises(StopIteration, rl_iterator.__next__)
开发者ID:jaymzh,项目名称:anaconda,代码行数:35,代码来源:iutil_test.py


示例2: exec_readlines_test_signals

    def exec_readlines_test_signals(self):
        """Test execReadlines and signal receipt."""

        # ignored signal
        old_HUP_handler = signal.signal(signal.SIGHUP, signal.SIG_IGN)
        try:
            with tempfile.NamedTemporaryFile(mode="wt") as testscript:
                testscript.write(
                    """#!/bin/sh
echo "one"
kill -HUP $PPID
echo "two"
echo -n "three"
exit 0
"""
                )
                testscript.flush()

                with timer(5):
                    rl_iterator = iutil.execReadlines("/bin/sh", [testscript.name])
                    self.assertEqual(next(rl_iterator), "one")
                    self.assertEqual(next(rl_iterator), "two")
                    self.assertEqual(next(rl_iterator), "three")
                    self.assertRaises(StopIteration, rl_iterator.__next__)
        finally:
            signal.signal(signal.SIGHUP, old_HUP_handler)

        # caught signal
        def _hup_handler(signum, frame):
            pass

        old_HUP_handler = signal.signal(signal.SIGHUP, _hup_handler)
        try:
            with tempfile.NamedTemporaryFile(mode="wt") as testscript:
                testscript.write(
                    """#!/bin/sh
echo "one"
kill -HUP $PPID
echo "two"
echo -n "three"
exit 0
"""
                )
                testscript.flush()

                with timer(5):
                    rl_iterator = iutil.execReadlines("/bin/sh", [testscript.name])
                    self.assertEqual(next(rl_iterator), "one")
                    self.assertEqual(next(rl_iterator), "two")
                    self.assertEqual(next(rl_iterator), "three")
                    self.assertRaises(StopIteration, rl_iterator.__next__)
        finally:
            signal.signal(signal.SIGHUP, old_HUP_handler)
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:53,代码来源:iutil_test.py


示例3: exec_readlines_test

    def exec_readlines_test(self):
        """Test execReadlines."""

        # test no lines are returned
        self.assertEqual(list(iutil.execReadlines("true", [])), [])

        # test some lines are returned
        self.assertGreater(len(list(iutil.execReadlines("ls", ["--help"]))), 0)

        # check that it always returns an iterator for both
        # if there is some output and if there isn't any
        self.assertTrue(hasattr(iutil.execReadlines("ls", ["--help"]), "__iter__"))
        self.assertTrue(hasattr(iutil.execReadlines("true", []), "__iter__"))
开发者ID:cyclefusion,项目名称:anaconda,代码行数:13,代码来源:iutil_test.py


示例4: exec_readlines_test

    def exec_readlines_test(self):
        """Test execReadlines."""

        # test no lines are returned
        self.assertEqual(list(iutil.execReadlines("true", [])), [])

        # test some lines are returned
        self.assertGreater(len(list(iutil.execReadlines("ls", ["--help"]))), 0)

        # check that it always returns a generator for both
        # if there is some output and if there isn't any
        self.assertIsInstance(iutil.execReadlines("ls", ["--help"]),
                              types.GeneratorType)
        self.assertIsInstance(iutil.execReadlines("true", []),
                              types.GeneratorType)
开发者ID:pombreda,项目名称:anaconda,代码行数:15,代码来源:iutil_test.py


示例5: exec_readlines_auto_kill_test

    def exec_readlines_auto_kill_test(self):
        """Test execReadlines with reading only part of the output"""

        with tempfile.NamedTemporaryFile() as testscript:
            testscript.write("""#!/bin/sh
# Output forever
while true; do
echo hey
done
""")
            testscript.flush()

            with timer(5):
                rl_iterator = iutil.execReadlines("/bin/sh", [testscript.name])

                # Save the process context
                proc = rl_iterator._proc

                # Read two lines worth
                self.assertEqual(rl_iterator.next(), "hey")
                self.assertEqual(rl_iterator.next(), "hey")

                # Delete the iterator and wait for the process to be killed
                del rl_iterator
                proc.communicate()

            # Check that the process is gone
            self.assertIsNotNone(proc.poll())
开发者ID:cyclefusion,项目名称:anaconda,代码行数:28,代码来源:iutil_test.py


示例6: exec_readlines_test_normal_output

    def exec_readlines_test_normal_output(self):
        """Test the output of execReadlines."""

        # Test regular-looking output
        with tempfile.NamedTemporaryFile(mode="w+t") as testscript:
            testscript.write(
                """#!/bin/sh
echo "one"
echo "two"
echo "three"
exit 0
"""
            )
            testscript.flush()

            with timer(5):
                rl_iterator = iutil.execReadlines("/bin/sh", [testscript.name])
                self.assertEqual(next(rl_iterator), "one")
                self.assertEqual(next(rl_iterator), "two")
                self.assertEqual(next(rl_iterator), "three")
                self.assertRaises(StopIteration, rl_iterator.__next__)

        # Test output with no end of line
        with tempfile.NamedTemporaryFile(mode="w+t") as testscript:
            testscript.write(
                """#!/bin/sh
echo "one"
echo "two"
echo -n "three"
exit 0
"""
            )
            testscript.flush()

            with timer(5):
                rl_iterator = iutil.execReadlines("/bin/sh", [testscript.name])
                self.assertEqual(next(rl_iterator), "one")
                self.assertEqual(next(rl_iterator), "two")
                self.assertEqual(next(rl_iterator), "three")
                self.assertRaises(StopIteration, rl_iterator.__next__)
开发者ID:nandakishore1006,项目名称:anaconda,代码行数:40,代码来源:iutil_test.py


示例7: journalctl_callback

def journalctl_callback():
    """Callback to get logs from journalctl."""

    # regex to filter log messages from anaconda's process (we have that in our
    # logs)
    anaconda_log_line = re.compile(r"\[%d\]:" % os.getpid())
    ret = ""
    for line in iutil.execReadlines("journalctl", ["-b"]):
        if anaconda_log_line.search(line) is None:
            # not an anaconda's message
            ret += line + "\n"

    return ret
开发者ID:josefbacik,项目名称:anaconda,代码行数:13,代码来源:exception.py


示例8: resolve_date_format_test

    def resolve_date_format_test(self):
        """All locales' date formats should be properly resolved."""

        locales = (line.strip() for line in execReadlines("locale", ["-a"]))
        for locale in locales:
            try:
                locale_mod.setlocale(locale_mod.LC_ALL, locale)
            except locale_mod.Error:
                # cannot set locale (a bug in the locale module?)
                continue

            order = localization.resolve_date_format(1, 2, 3, fail_safe=False)[0]
            for i in (1, 2, 3):
                self.assertIn(i, order)
开发者ID:cyclefusion,项目名称:anaconda,代码行数:14,代码来源:localization_test.py


示例9: run_grubby

def run_grubby(args=None):
    """ Run grubby and retrieve the kernel, initrd and boot arguments

        :param list args: Arguments to pass to grubby.
        :returns: kernel path, initrd path, root device, kernel cmdline args.
        :rtype: namedtuple
        :raises: some error on failure

        The returned namedtuple contains the following attributes:
            kernel, initrd, root, args
    """
    boot_info = _BootInfo()
    attrs = list(_BootInfo._fields)

    if not args:
        args = ["--info", "DEFAULT"]

    # Run grubby and fill in the boot_info with the first values seen, exit the
    # loop when all of the needed values have been gathered.
    try:

        for line in execReadlines("grubby", args, root=getSysroot()):
            key, _sep, value = line.partition("=")
            value = unquote(value)
            if key in attrs:
                setattr(boot_info, key, value)
                attrs.remove(key)
            if not attrs:
                break
    except OSError as e:
        log.error("run_grubby failed: %s", e)
        raise GrubbyInfoError(e)

    if len(attrs) > 0:
        raise GrubbyInfoError("Missing values: %s" % ", ".join(attrs))

    log.info("grubby boot info for (%s): %s", args, boot_info)
    return boot_info
开发者ID:bwann,项目名称:anaconda,代码行数:38,代码来源:kexec.py


示例10: execParseKickstart

 def execParseKickstart(self, ks_file):
     return list(iutil.execReadlines(self.command, ["--tmpdir", self.tmpdir, ks_file]))
开发者ID:jresch,项目名称:anaconda,代码行数:2,代码来源:parse-kickstart_test.py


示例11: exec_readlines_test_exits

    def exec_readlines_test_exits(self):
        """Test execReadlines in different child exit situations."""

        # Tests that exit on signal will raise OSError once output
        # has been consumed, otherwise the test will exit normally.

        # Test a normal, non-0 exit
        with tempfile.NamedTemporaryFile() as testscript:
            testscript.write("""#!/bin/sh
echo "one"
echo "two"
echo "three"
exit 1
""")
            testscript.flush()

            with timer(5):
                rl_iterator = iutil.execReadlines("/bin/sh", [testscript.name])
                self.assertEqual(rl_iterator.next(), "one")
                self.assertEqual(rl_iterator.next(), "two")
                self.assertEqual(rl_iterator.next(), "three")
                self.assertRaises(OSError, rl_iterator.next)

        # Test exit on signal
        with tempfile.NamedTemporaryFile() as testscript:
            testscript.write("""#!/bin/sh
echo "one"
echo "two"
echo "three"
kill -TERM $$
""")
            testscript.flush()

            with timer(5):
                rl_iterator = iutil.execReadlines("/bin/sh", [testscript.name])
                self.assertEqual(rl_iterator.next(), "one")
                self.assertEqual(rl_iterator.next(), "two")
                self.assertEqual(rl_iterator.next(), "three")
                self.assertRaises(OSError, rl_iterator.next)

        # Repeat the above two tests, but exit before a final newline
        with tempfile.NamedTemporaryFile() as testscript:
            testscript.write("""#!/bin/sh
echo "one"
echo "two"
echo -n "three"
exit 1
""")
            testscript.flush()

            with timer(5):
                rl_iterator = iutil.execReadlines("/bin/sh", [testscript.name])
                self.assertEqual(rl_iterator.next(), "one")
                self.assertEqual(rl_iterator.next(), "two")
                self.assertEqual(rl_iterator.next(), "three")
                self.assertRaises(OSError, rl_iterator.next)

        with tempfile.NamedTemporaryFile() as testscript:
            testscript.write("""#!/bin/sh
echo "one"
echo "two"
echo -n "three"
kill -TERM $$
""")
            testscript.flush()

            with timer(5):
                rl_iterator = iutil.execReadlines("/bin/sh", [testscript.name])
                self.assertEqual(rl_iterator.next(), "one")
                self.assertEqual(rl_iterator.next(), "two")
                self.assertEqual(rl_iterator.next(), "three")
                self.assertRaises(OSError, rl_iterator.next)
开发者ID:cyclefusion,项目名称:anaconda,代码行数:72,代码来源:iutil_test.py


示例12: get_doc_type

 def get_doc_type(file_path):
     for line in execReadlines("oscap", ["info", file_path]):
         if line.startswith("Document type:"):
             _prefix, _sep, type_info = line.partition(":")
             return type_info.strip()
开发者ID:M4rtinK,项目名称:oscap-anaconda-addon,代码行数:5,代码来源:content_handling.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python iutil.execWithCapture函数代码示例发布时间:2022-05-25
下一篇:
Python iutil.eintr_retry_call函数代码示例发布时间: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