Merge "Wrap exceptions that occur while running external process"
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
def run_cmd(*args, **kwargs):
|
def run_cmd(*args, **kwargs):
|
||||||
@@ -25,17 +26,23 @@ def run_cmd(*args, **kwargs):
|
|||||||
def preexec_fn():
|
def preexec_fn():
|
||||||
return os.chdir(kwargs['chdir'])
|
return os.chdir(kwargs['chdir'])
|
||||||
|
|
||||||
proc = subprocess.Popen(args, stdin=subprocess.PIPE,
|
try:
|
||||||
stdout=subprocess.PIPE,
|
proc = subprocess.Popen(args, stdin=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT, env=os.environ,
|
stdout=subprocess.PIPE,
|
||||||
preexec_fn=preexec_fn)
|
stderr=subprocess.STDOUT, env=os.environ,
|
||||||
|
preexec_fn=preexec_fn)
|
||||||
|
|
||||||
if 'confirm' in kwargs and kwargs['confirm']:
|
if 'confirm' in kwargs and kwargs['confirm']:
|
||||||
proc.stdin.write('yes'.encode())
|
proc.stdin.write('yes'.encode())
|
||||||
proc.stdin.flush()
|
proc.stdin.flush()
|
||||||
|
|
||||||
out, err = proc.communicate()
|
out, err = proc.communicate()
|
||||||
out = out.decode('utf-8')
|
out = out.decode('utf-8')
|
||||||
|
except Exception:
|
||||||
|
raise Exception(
|
||||||
|
"Exception while processing the command:\n%s.\n%s" %
|
||||||
|
(' '.join(args), traceback.format_exc())
|
||||||
|
)
|
||||||
|
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
|
Reference in New Issue
Block a user