Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
avocado
提交
0edfd1ec
A
avocado
项目概览
openeuler
/
avocado
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
avocado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0edfd1ec
编写于
3月 23, 2018
作者:
C
Cleber Rosa
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'hsmj1412/py3commands'
Signed-off-by:
N
Cleber Rosa
<
crosa@redhat.com
>
上级
9ee24688
afbc1a90
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
175 addition
and
24 deletion
+175
-24
avocado/utils/process.py
avocado/utils/process.py
+175
-24
未找到文件。
avocado/utils/process.py
浏览文件 @
0edfd1ec
...
...
@@ -1219,14 +1219,23 @@ def run(cmd, timeout=None, verbose=True, ignore_status=False,
:param ignore_status: Whether to raise an exception when command returns
=! 0 (False), or not (True).
:type ignore_status: bool
:param allow_output_check: Whether to log the command stream outputs
(stdout and stderr) in the test stream
files. Valid values: 'stdout', for
allowing only standard output, 'stderr',
to allow only standard error, 'all',
to allow both standard output and error
(default), and 'none', to allow
none to be recorded.
:param allow_output_check: Whether to record the output from this
process (from stdout and stderr) in the
test's output record files. Valid values:
'stdout', for standard output *only*,
'stderr' for standard error *only*,
'both' for both standard output and error
in separate files, 'combined' for
standard output and error in a single file,
and 'none' to disable all recording. 'all'
is also a valid, but deprecated, option that
is a synonym of 'both'. If an explicit value
is not given to this parameter, that is, if
None is given, it defaults to using the module
level configuration, as set by
:data:`OUTPUT_CHECK_RECORD_MODE`. If the
module level configuration itself is not set,
it defaults to 'none'.
:type allow_output_check: str
:param shell: Whether to run the command on a subshell
:type shell: bool
...
...
@@ -1271,14 +1280,23 @@ def system(cmd, timeout=None, verbose=True, ignore_status=False,
:param ignore_status: Whether to raise an exception when command returns
=! 0 (False), or not (True).
:type ignore_status: bool
:param allow_output_check: Whether to log the command stream outputs
(stdout and stderr) in the test stream
files. Valid values: 'stdout', for
allowing only standard output, 'stderr',
to allow only standard error, 'all',
to allow both standard output and error
(default), and 'none', to allow
none to be recorded.
:param allow_output_check: Whether to record the output from this
process (from stdout and stderr) in the
test's output record files. Valid values:
'stdout', for standard output *only*,
'stderr' for standard error *only*,
'both' for both standard output and error
in separate files, 'combined' for
standard output and error in a single file,
and 'none' to disable all recording. 'all'
is also a valid, but deprecated, option that
is a synonym of 'both'. If an explicit value
is not given to this parameter, that is, if
None is given, it defaults to using the module
level configuration, as set by
:data:`OUTPUT_CHECK_RECORD_MODE`. If the
module level configuration itself is not set,
it defaults to 'none'.
:type allow_output_check: str
:param shell: Whether to run the command on a subshell
:type shell: bool
...
...
@@ -1319,14 +1337,23 @@ def system_output(cmd, timeout=None, verbose=True, ignore_status=False,
:type verbose: bool
:param ignore_status: Whether to raise an exception when command returns
=! 0 (False), or not (True).
:param allow_output_check: Whether to log the command stream outputs
(stdout and stderr) in the test stream
files. Valid values: 'stdout', for
allowing only standard output, 'stderr',
to allow only standard error, 'all',
to allow both standard output and error
(default), and 'none', to allow
none to be recorded.
:param allow_output_check: Whether to record the output from this
process (from stdout and stderr) in the
test's output record files. Valid values:
'stdout', for standard output *only*,
'stderr' for standard error *only*,
'both' for both standard output and error
in separate files, 'combined' for
standard output and error in a single file,
and 'none' to disable all recording. 'all'
is also a valid, but deprecated, option that
is a synonym of 'both'. If an explicit value
is not given to this parameter, that is, if
None is given, it defaults to using the module
level configuration, as set by
:data:`OUTPUT_CHECK_RECORD_MODE`. If the
module level configuration itself is not set,
it defaults to 'none'.
:type allow_output_check: str
:param shell: Whether to run the command on a subshell
:type shell: bool
...
...
@@ -1354,3 +1381,127 @@ def system_output(cmd, timeout=None, verbose=True, ignore_status=False,
if
strip_trail_nl
:
return
cmd_result
.
stdout
.
rstrip
(
b
'
\n\r
'
)
return
cmd_result
.
stdout
def
getoutput
(
cmd
,
timeout
=
None
,
verbose
=
False
,
ignore_status
=
True
,
allow_output_check
=
'combined'
,
shell
=
True
,
env
=
None
,
sudo
=
False
,
ignore_bg_processes
=
False
):
"""
Because commands module is removed in Python3 and it redirect stderr
to stdout, we port commands.getoutput to make code compatible
Return output (stdout or stderr) of executing cmd in a shell.
:param cmd: Command line to run.
:type cmd: str
:param timeout: Time limit in seconds before attempting to kill the
running process. This function will take a few seconds
longer than 'timeout' to complete if it has to kill the
process.
:type timeout: float
:param verbose: Whether to log the command run and stdout/stderr.
:type verbose: bool
:param ignore_status: Whether to raise an exception when command returns
=! 0 (False), or not (True).
:param allow_output_check: Whether to record the output from this
process (from stdout and stderr) in the
test's output record files. Valid values:
'stdout', for standard output *only*,
'stderr' for standard error *only*,
'both' for both standard output and error
in separate files, 'combined' for
standard output and error in a single file,
and 'none' to disable all recording. 'all'
is also a valid, but deprecated, option that
is a synonym of 'both'. If an explicit value
is not given to this parameter, that is, if
None is given, it defaults to using the module
level configuration, as set by
:data:`OUTPUT_CHECK_RECORD_MODE`. If the
module level configuration itself is not set,
it defaults to 'none'.
:type allow_output_check: str
:param shell: Whether to run the command on a subshell
:type shell: bool
:param env: Use extra environment variables
:type env: dict
:param sudo: Whether the command requires admin privileges to run,
so that sudo will be prepended to the command.
The assumption here is that the user running the command
has a sudo configuration such that a password won't be
prompted. If that's not the case, the command will
straight out fail.
:type sudo: bool
:param ignore_bg_processes: Whether to ignore background processes
:type ignore_bg_processes: bool
:return: Command output(stdout or stderr).
:rtype: str
"""
return
getstatusoutput
(
cmd
=
cmd
,
timeout
=
timeout
,
verbose
=
verbose
,
ignore_status
=
ignore_status
,
allow_output_check
=
allow_output_check
,
shell
=
shell
,
env
=
env
,
sudo
=
sudo
,
ignore_bg_processes
=
ignore_bg_processes
)[
1
]
def
getstatusoutput
(
cmd
,
timeout
=
None
,
verbose
=
False
,
ignore_status
=
True
,
allow_output_check
=
'combined'
,
shell
=
True
,
env
=
None
,
sudo
=
False
,
ignore_bg_processes
=
False
):
"""
Because commands module is removed in Python3 and it redirect stderr
to stdout, we port commands.getstatusoutput to make code compatible
Return (status, output) of executing cmd in a shell.
:param cmd: Command line to run.
:type cmd: str
:param timeout: Time limit in seconds before attempting to kill the
running process. This function will take a few seconds
longer than 'timeout' to complete if it has to kill the
process.
:type timeout: float
:param verbose: Whether to log the command run and stdout/stderr.
:type verbose: bool
:param ignore_status: Whether to raise an exception when command returns
=! 0 (False), or not (True).
:param allow_output_check: Whether to record the output from this
process (from stdout and stderr) in the
test's output record files. Valid values:
'stdout', for standard output *only*,
'stderr' for standard error *only*,
'both' for both standard output and error
in separate files, 'combined' for
standard output and error in a single file,
and 'none' to disable all recording. 'all'
is also a valid, but deprecated, option that
is a synonym of 'both'. If an explicit value
is not given to this parameter, that is, if
None is given, it defaults to using the module
level configuration, as set by
:data:`OUTPUT_CHECK_RECORD_MODE`. If the
module level configuration itself is not set,
it defaults to 'none'.
:type allow_output_check: str
:param shell: Whether to run the command on a subshell
:type shell: bool
:param env: Use extra environment variables
:type env: dict
:param sudo: Whether the command requires admin privileges to run,
so that sudo will be prepended to the command.
The assumption here is that the user running the command
has a sudo configuration such that a password won't be
prompted. If that's not the case, the command will
straight out fail.
:type sudo: bool
:param ignore_bg_processes: Whether to ignore background processes
:type ignore_bg_processes: bool
:return: Exit status and command output(stdout and stderr).
:rtype: tuple
"""
cmd_result
=
run
(
cmd
=
cmd
,
timeout
=
timeout
,
verbose
=
verbose
,
ignore_status
=
ignore_status
,
allow_output_check
=
allow_output_check
,
shell
=
shell
,
env
=
env
,
sudo
=
sudo
,
ignore_bg_processes
=
ignore_bg_processes
)
text
=
cmd_result
.
stdout_text
sts
=
cmd_result
.
exit_status
if
text
[
-
1
:]
==
'
\n
'
:
text
=
text
[:
-
1
]
return
(
sts
,
text
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录