提交 981b3ba4 编写于 作者: C Cleber Rosa

Merge remote-tracking branch 'ldoktor/qemu-bin2'

......@@ -27,3 +27,20 @@ script:
- python setup.py develop
- ./selftests/run
- ./selftests/check_tmp_dirs
- |
ERR=""
MASTER=$(git rev-parse origin/master)
echo Master is $MASTER
for COMMIT in $(git rev-list origin..HEAD); do
echo
echo "--------------------< $(git log -1 --oneline $COMMIT) >--------------------"
echo
echo
git checkout $COMMIT || ERR=$(echo -e "$ERR\nUnable to checkout $(git log -1 --oneline $COMMIT)")
python setup.py develop && make smokecheck || ERR=$(echo -e "$ERR\n$(git log -1 --oneline)")
done
if [ "$ERR" ]; then
echo
echo "Incremental smokecheck failed: $ERR"
exit -1
fi
......@@ -123,6 +123,9 @@ requirements:
requirements-selftests: requirements
- grep -v '^#' requirements-selftests.txt | xargs -n 1 pip install --upgrade
smokecheck:
./scripts/avocado run passtest
check: clean check_cyclical modules_boundaries
selftests/checkall
selftests/check_tmp_dirs
......
......@@ -18,6 +18,7 @@ Functions dedicated to find and run external commands.
import logging
import os
import re
import StringIO
import signal
import time
......@@ -63,6 +64,10 @@ WRAP_PROCESS_NAMES_EXPR = []
UNDEFINED_BEHAVIOR_EXCEPTION = None
# variable=value bash assignment
_RE_BASH_SET_VARIABLE = re.compile(r"[a-zA-Z]\w*=.*")
class CmdError(Exception):
def __init__(self, command=None, result=None, additional_text=None):
......@@ -178,6 +183,27 @@ def get_children_pids(ppid):
return system_output("ps -L --ppid=%d -o lwp" % ppid, verbose=False).split('\n')[1:]
def binary_from_shell_cmd(cmd):
"""
Tries to find the first binary path from a simple shell-like command.
:note: It's a naive implementation, but for commands like:
`VAR=VAL binary -args || true` gives the right resutl (binary)
:param cmd: simple shell-like binary
:return: first found binary from the cmd
"""
try:
cmds = shlex.split(cmd)
except ValueError:
log.warning("binary_from_shell_cmd: Shlex split of %s failed, using "
"using simple split.", cmd)
cmds = cmd.split(" ")
for item in cmds:
if not _RE_BASH_SET_VARIABLE.match(item):
return item
raise ValueError("Unable to parse first binary from '%s'" % cmd)
class CmdResult(object):
"""
......
......@@ -202,5 +202,21 @@ class TestProcessRun(unittest.TestCase):
p = process.run(cmd='ls -l', sudo=True, shell=True, ignore_status=True)
self.assertEqual(p.command, expected_command)
class MiscProcessTests(unittest.TestCase):
def test_binary_from_shell(self):
self.assertEqual("binary", process.binary_from_shell_cmd("binary"))
res = process.binary_from_shell_cmd("MY_VAR=foo myV4r=123 "
"quote='a b c' QUOTE=\"1 2 && b\" "
"QuOtE=\"1 2\"foo' 3 4' first_bin "
"second_bin VAR=xyz")
self.assertEqual("first_bin", res)
res = process.binary_from_shell_cmd("VAR=VALUE 1st_binary var=value "
"second_binary")
self.assertEqual("1st_binary", res)
res = process.binary_from_shell_cmd("FOO=bar ./bin var=value")
self.assertEqual("./bin", res)
if __name__ == "__main__":
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册