1
################################################################################
9
from helpers import ProgressIndicator
11
################################################################################
14
if isinstance(cmd, str):
17
cmd = [c for c in cmd if c]
18
if sys.platform == 'win32': cmd = subprocess.list2cmdline(cmd)
19
else: cmd = ' '.join(cmd)
22
def log_cmd(cmd, dir):
23
print "executing:", cmd, 'from dir', os.path.abspath(dir or os.getcwd())
25
################################################################################
27
def ExecuteAssertSuccess(cmd, *args, **keywords):
28
retcode, output = GetReturnCodeAndOutput(cmd, *args, **keywords)
30
cmd_line = get_cmd_str(cmd)
31
raise Exception("calling: "+cmd_line+" failed with output:\n"+output)
32
return retcode, output
34
################################################################################
36
def GetReturnCodeAndOutput(cmd, dir=None, env=None, bufsize=-1, lineprintdiv=1):
37
cmd = get_cmd_str(cmd)
40
proc = subprocess.Popen (
41
cmd, cwd = dir, env = env, shell = True, bufsize = bufsize,
42
stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
43
universal_newlines = 1,
47
progress = ProgressIndicator(lineprintdiv)
49
while proc.poll() is None:
50
response += [proc.stdout.readline()]
51
if response[-1] is "": break
55
return proc.wait(), ''.join(response) + proc.stdout.read() # needed ubuntu
57
################################################################################
59
def InteractiveGetReturnCodeAndOutput(cmd, input_string, dir=None,
60
env=None, bufsize=-1):
61
cmd = get_cmd_str(cmd)
64
proc = subprocess.Popen (
65
cmd, cwd = dir, env = env, shell = True, bufsize = bufsize,
66
stdin = subprocess.PIPE, stdout = subprocess.PIPE,
67
stderr = subprocess.STDOUT, universal_newlines = 1
70
print "---------------"
71
response = proc.communicate(input_string)[0]
72
return proc.wait(), response
74
################################################################################
b'\\ No newline at end of file'