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

Python utilities.sos_get_command_output函数代码示例

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

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



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

示例1: get_command_output

    def get_command_output(self, prog, timeout=300, stderr=True,
                           chroot=True, runat=None):
        if chroot or self.commons['cmdlineopts'].chroot == 'always':
            root = self.sysroot
        else:
            root = None

        result = sos_get_command_output(prog, timeout=timeout, stderr=stderr,
                                        chroot=root, chdir=runat)

        if result['status'] == 124:
            self._log_warn("command '%s' timed out after %ds"
                           % (prog, timeout))

        # command not found or not runnable
        if result['status'] == 126 or result['status'] == 127:
            # automatically retry chroot'ed commands in the host namespace
            if chroot and self.commons['cmdlineopts'].chroot != 'always':
                self._log_info("command '%s' not found in %s - "
                               "re-trying in host root"
                               % (prog.split()[0], root))
                return self.get_command_output(prog, timeout=timeout,
                                               chroot=False, runat=runat)
            self._log_debug("could not run '%s': command not found" % prog)
        return result
开发者ID:MikeDawg,项目名称:sos,代码行数:25,代码来源:__init__.py


示例2: get_command_output

 def get_command_output(self, prog, timeout=300):
     (status, output, runtime) = sos_get_command_output(prog, timeout)
     if status == 124:
         self.soslog.warning("command '%s' timed out after %ds" % (prog, timeout))
     if status == 127:
         self.soslog.info("could not run '%s': command not found" % prog)
     return (status, output, runtime)
开发者ID:kiiofkirc,项目名称:sosreport,代码行数:7,代码来源:__init__.py


示例3: get_cmd_output_now

    def get_cmd_output_now(self, exe, suggest_filename=None, root_symlink=False, timeout=300):
        """Execute a command and save the output to a file for inclusion in the
        report.
        """
        if self.commons['cmdlineopts'].profiler:
            start_time = time()

        # pylint: disable-msg = W0612
        status, shout, runtime = sos_get_command_output(exe, timeout=timeout)
        if (status == 127):
            self.soslog.debug("could not run '%s': command not found" % exe)
            return None

        if suggest_filename:
            outfn = self.make_command_filename(suggest_filename)
        else:
            outfn = self.make_command_filename(exe)

        outfn_strip = outfn[len(self.commons['cmddir'])+1:]
        self.archive.add_string(shout, outfn)
        if root_symlink:
            self.archive.add_link(outfn, root_symlink)

        # save info for later
        self.executed_commands.append({'exe': exe, 'file':outfn_strip}) # save in our list
        self.commons['xmlreport'].add_command(cmdline=exe,exitcode=status,f_stdout=outfn_strip,runtime=runtime)

        if self.commons['cmdlineopts'].profiler:
            time_passed = time() - start_time
            self.proflog.debug("output: %-75s time: %f" % (exe, time_passed))

        return outfn
开发者ID:jamesodhunt,项目名称:sosreport,代码行数:32,代码来源:__init__.py


示例4: _compress

    def _compress(self):
        methods = []
        # Make sure that valid compression commands exist.
        for method in ['xz', 'bzip2', 'gzip']:
            if is_executable(method):
                methods.append(method)
            else:
                self.log_info("\"%s\" compression method unavailable" % method)
        if self.method in methods:
            methods = [self.method]

        exp_msg = "No compression utilities found."
        last_error = Exception(exp_msg)
        for cmd in methods:
            suffix = "." + cmd.replace('ip', '')
            cmd = self._policy.get_cmd_for_compress_method(cmd, self._threads)
            try:
                exec_cmd = "%s %s" % (cmd, self.name())
                r = sos_get_command_output(exec_cmd, stderr=True, timeout=0)

                if r['status']:
                    self.log_error(r['output'])
                    raise Exception("%s exited with %s" % (exec_cmd,
                                    r['status']))

                self._suffix += suffix
                return self.name()

            except Exception as e:
                last_error = e
        raise last_error
开发者ID:nijinashok,项目名称:sos,代码行数:31,代码来源:archive.py


示例5: _compress

    def _compress(self):
        methods = []
        # Make sure that valid compression commands exist.
        for method in ['xz', 'bzip2', 'gzip']:
            if is_executable(method):
                methods.append(method)
            else:
                self.log_error("\"%s\" command not found." % method)
        if self.method in methods:
            methods = [self.method]

        exp_msg = "No compression utilities found."
        last_error = Exception(exp_msg)
        for cmd in methods:
            suffix = "." + cmd.replace('ip', '')
            # use fast compression if using xz or bz2
            if cmd != "gzip":
                cmd = "%s -1" % cmd
            try:
                r = sos_get_command_output("%s %s" % (cmd, self.name()),
                                           timeout=0)

                if r['status']:
                    self.log_info(r['output'])

                self._suffix += suffix
                return self.name()

            except Exception as e:
                last_error = e
        raise last_error
开发者ID:pierg75,项目名称:pier-sosreport,代码行数:31,代码来源:archive.py


示例6: get_command_output

 def get_command_output(self, prog, timeout=300, runat=None, stderr=True):
     result = sos_get_command_output(prog, timeout=timeout, runat=runat, stderr=stderr)
     if result["status"] == 124:
         self._log_warn("command '%s' timed out after %ds" % (prog, timeout))
     # 126 means 'found but not executable'
     if result["status"] == 126 or result["status"] == 127:
         self._log_debug("could not run '%s': command not found" % prog)
     return result
开发者ID:navidshaikh,项目名称:sos,代码行数:8,代码来源:__init__.py


示例7: get_command_output

 def get_command_output(self, prog, timeout=300, runat=None):
     result = sos_get_command_output(prog, timeout=timeout, runat=runat)
     if result['status'] == 124:
         self.log_warn("command '%s' timed out after %ds"
                 % (prog, timeout))
     if result['status'] == 127:
         self.log_debug("could not run '%s': command not found" % prog)
     return result
开发者ID:iweiss,项目名称:sos,代码行数:8,代码来源:__init__.py


示例8: _query_service

 def _query_service(self, name):
     """Query an individual service"""
     if self.query_cmd:
         try:
             return sos_get_command_output("%s %s" % (self.query_cmd, name))
         except Exception:
             return None
     return None
开发者ID:TurboTurtle,项目名称:sos,代码行数:8,代码来源:__init__.py


示例9: _query_service

 def _query_service(self, name):
     """Query an individual service"""
     if self.query_cmd:
         res = sos_get_command_output("%s %s" % (self.query_cmd, name))
         if res['status'] == 0:
             return res
         else:
             return None
     return None
开发者ID:jcastill,项目名称:sos,代码行数:9,代码来源:__init__.py


示例10: _encrypt

    def _encrypt(self, archive):
        """Encrypts the compressed archive using GPG.

        If encryption fails for any reason, it should be logged by sos but not
        cause execution to stop. The assumption is that the unencrypted archive
        would still be of use to the user, and/or that the end user has another
        means of securing the archive.

        Returns the name of the encrypted archive, or raises an exception to
        signal that encryption failed and the unencrypted archive name should
        be used.
        """
        arc_name = archive.replace("sosreport-", "secured-sosreport-")
        arc_name += ".gpg"
        enc_cmd = "gpg --batch -o %s " % arc_name
        env = None
        if self.enc_opts["key"]:
            # need to assume a trusted key here to be able to encrypt the
            # archive non-interactively
            enc_cmd += "--trust-model always -e -r %s " % self.enc_opts["key"]
            enc_cmd += archive
        if self.enc_opts["password"]:
            # prevent change of gpg options using a long password, but also
            # prevent the addition of quote characters to the passphrase
            passwd = "%s" % self.enc_opts["password"].replace('\'"', '')
            env = {"sos_gpg": passwd}
            enc_cmd += "-c --passphrase-fd 0 "
            enc_cmd = "/bin/bash -c \"echo $sos_gpg | %s\"" % enc_cmd
            enc_cmd += archive
        r = sos_get_command_output(enc_cmd, timeout=0, env=env)
        if r["status"] == 0:
            return arc_name
        elif r["status"] == 2:
            if self.enc_opts["key"]:
                msg = "Specified key not in keyring"
            else:
                msg = "Could not read passphrase"
        else:
            # TODO: report the actual error from gpg. Currently, we cannot as
            # sos_get_command_output() does not capture stderr
            msg = "gpg exited with code %s" % r["status"]
        raise Exception(msg)
开发者ID:nijinashok,项目名称:sos,代码行数:42,代码来源:archive.py


示例11: _compress

    def _compress(self):
        methods = ['xz', 'bzip2', 'gzip']
        if self.method in methods:
            methods = [self.method]

        last_error = Exception("compression failed")

        for cmd in methods:
            suffix = "." + cmd.replace('ip', '')
            # use fast compression if using xz or bz2
            if cmd != "gzip":
                cmd = "%s -1" % cmd
            try:
                r = sos_get_command_output("%s %s" % (cmd, self.name()))

                if r['status']:
                    self.log_info(r['output'])

                self._suffix += suffix
                return self.name()

            except Exception as e:
                last_error = e
        raise last_error
开发者ID:Akasurde,项目名称:sos,代码行数:24,代码来源:archive.py


示例12: test_output_non_exe

 def test_output_non_exe(self):
     path = os.path.join(TEST_DIR, "utility_tests.py")
     result = sos_get_command_output(path)
     self.assertEquals(result["status"], 127)
     self.assertEquals(result["output"], "")
开发者ID:RobertMcDermot,项目名称:sos,代码行数:5,代码来源:utilities_tests.py


示例13: test_output

 def test_output(self):
     path = os.path.join(TEST_DIR, 'test_exe.py')
     result = sos_get_command_output(path)
     self.assertEquals(result['status'], 0)
     self.assertEquals(result['output'], "executed\n")
开发者ID:knoha-rh,项目名称:sos,代码行数:5,代码来源:utilities_tests.py


示例14: test_output_non_exe

 def test_output_non_exe(self):
     path = os.path.join(TEST_DIR, 'utility_tests.py')
     ret, out, junk = sos_get_command_output(path)
     self.assertEquals(ret, 127)
     self.assertEquals(out, "")
开发者ID:bcrochet,项目名称:sosreport,代码行数:5,代码来源:utilities_tests.py


示例15: test_output

 def test_output(self):
     path = os.path.join(TEST_DIR, 'test_exe.py')
     ret, out, junk = sos_get_command_output(path)
     self.assertEquals(ret, 0)
     self.assertEquals(out, "executed\n")
开发者ID:bcrochet,项目名称:sosreport,代码行数:5,代码来源:utilities_tests.py


示例16: call_ext_prog

 def call_ext_prog(self, prog, timeout=300):
     """Execute a command independantly of the output gathering part of
     sosreport.
     """
     # pylint: disable-msg = W0612
     return sos_get_command_output(prog, timeout)
开发者ID:jamesodhunt,项目名称:sosreport,代码行数:6,代码来源:__init__.py


示例17: test_output_chdir

 def test_output_chdir(self):
     cmd = "/bin/bash -c 'echo $PWD'"
     result = sos_get_command_output(cmd, chdir=TEST_DIR)
     print(result)
     self.assertEquals(result['status'], 0)
     self.assertEquals(result['output'].strip(), TEST_DIR)
开发者ID:knoha-rh,项目名称:sos,代码行数:6,代码来源:utilities_tests.py


示例18: _get_scls

 def _get_scls(self):
     output = sos_get_command_output("scl -l")["output"]
     return [scl.strip() for scl in output.splitlines()]
开发者ID:jmagrini,项目名称:sos,代码行数:3,代码来源:__init__.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python sos_testing.check_response函数代码示例发布时间:2022-05-27
下一篇:
Python utilities.grep函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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