|
@ -14,7 +14,6 @@ import subprocess |
|
|
import copy |
|
|
import copy |
|
|
import shlex |
|
|
import shlex |
|
|
import platform |
|
|
import platform |
|
|
from pprint import pformat |
|
|
|
|
|
from collections import OrderedDict |
|
|
from collections import OrderedDict |
|
|
|
|
|
|
|
|
SCRIPTS_DIR = os.path.dirname(os.path.realpath(__file__)) |
|
|
SCRIPTS_DIR = os.path.dirname(os.path.realpath(__file__)) |
|
@ -100,7 +99,7 @@ def show_and_return(cmd, enable_collect=False, cwd=None, shell=False): |
|
|
# <https://cyberciti.biz/faq/python-run-external-command-and-get-output/>) |
|
|
# <https://cyberciti.biz/faq/python-run-external-command-and-get-output/>) |
|
|
if shell not in [None, True, False]: |
|
|
if shell not in [None, True, False]: |
|
|
raise ValueError("Expected None, True, or False for shell but got %s" |
|
|
raise ValueError("Expected None, True, or False for shell but got %s" |
|
|
% pformat(shell)) |
|
|
% repr(shell)) |
|
|
if cwd is None: |
|
|
if cwd is None: |
|
|
cwd = os.getcwd() |
|
|
cwd = os.getcwd() |
|
|
if shell and not hasattr(cmd, "split"): |
|
|
if shell and not hasattr(cmd, "split"): |
|
@ -140,7 +139,7 @@ def show_and_return(cmd, enable_collect=False, cwd=None, shell=False): |
|
|
cmd = ["bash", "-c", "cd '" + cwd + "'; " + pre_bin + shlex.join(cmd)] |
|
|
cmd = ["bash", "-c", "cd '" + cwd + "'; " + pre_bin + shlex.join(cmd)] |
|
|
else: |
|
|
else: |
|
|
cmd = ["bash", "-c", "cd '" + cwd + "'; " + pre_bin + cmd] |
|
|
cmd = ["bash", "-c", "cd '" + cwd + "'; " + pre_bin + cmd] |
|
|
run_msg = prefix+"Running %s" % pformat(cmd) |
|
|
run_msg = prefix+"Running %s" % repr(cmd) |
|
|
run_msg += ' # shell=%s in "%s"' % (shell, cwd) |
|
|
run_msg += ' # shell=%s in "%s"' % (shell, cwd) |
|
|
echo0(run_msg) |
|
|
echo0(run_msg) |
|
|
if cwd is not None: |
|
|
if cwd is not None: |
|
@ -298,7 +297,7 @@ def show_and_return(cmd, enable_collect=False, cwd=None, shell=False): |
|
|
if len(meta['string']) > 0: |
|
|
if len(meta['string']) > 0: |
|
|
raise NotImplementedError( |
|
|
raise NotImplementedError( |
|
|
"The remaining %s wasn't processed: %s" |
|
|
"The remaining %s wasn't processed: %s" |
|
|
% (_, pformat(meta['string'])) |
|
|
% (_, repr(meta['string'])) |
|
|
) |
|
|
) |
|
|
return { |
|
|
return { |
|
|
'code': code, |
|
|
'code': code, |
|
@ -387,7 +386,7 @@ def main(): |
|
|
if count < 1: |
|
|
if count < 1: |
|
|
cmd_msg = cmd if isinstance(cmd, str) else shlex.join(cmd) |
|
|
cmd_msg = cmd if isinstance(cmd, str) else shlex.join(cmd) |
|
|
print(" (Output of `%s` had %s line(s) of output.)" |
|
|
print(" (Output of `%s` had %s line(s) of output.)" |
|
|
% (pformat(cmd_msg), count), |
|
|
% (repr(cmd_msg), count), |
|
|
file=sys.stderr) |
|
|
file=sys.stderr) |
|
|
else: |
|
|
else: |
|
|
print("", file=sys.stderr) |
|
|
print("", file=sys.stderr) |
|
|