|
4 | 4 | from devtools import tarball |
5 | 5 | from contextlib import contextmanager |
6 | 6 | import subprocess |
| 7 | +import traceback |
7 | 8 | import re |
8 | 9 | import os |
9 | 10 | import sys |
@@ -52,24 +53,39 @@ def do_subst_in_file(targetfile, sourcefile, dict): |
52 | 53 | def getstatusoutput(cmd): |
53 | 54 | """cmd is a list. |
54 | 55 | """ |
55 | | - process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
56 | | - output, _ = process.communicate() |
57 | | - status = process.returncode |
| 56 | + try: |
| 57 | + process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 58 | + output, _ = process.communicate() |
| 59 | + status = process.returncode |
| 60 | + except: |
| 61 | + status = -1 |
| 62 | + output = traceback.format_exc() |
58 | 63 | return status, output |
59 | 64 |
|
60 | 65 | def run_cmd(cmd, silent=False): |
61 | | - print('Running:', repr(' '.join(cmd)), 'in', repr(os.getcwd())) |
| 66 | + """Raise exception on failure. |
| 67 | + """ |
| 68 | + info = 'Running: %r in %r' %(' '.join(cmd), os.getcwd()) |
| 69 | + print(info) |
62 | 70 | sys.stdout.flush() |
63 | 71 | if silent: |
64 | 72 | status, output = getstatusoutput(cmd) |
65 | 73 | else: |
66 | 74 | status, output = os.system(' '.join(cmd)), '' |
67 | 75 | if status: |
68 | | - msg = 'error=%d, output="""\n%s\n"""' %(status, output) |
69 | | - print(msg) |
70 | | - #raise Exception(msg) |
| 76 | + msg = 'Error while %s ...\n\terror=%d, output="""%s"""' %(info, status, output) |
| 77 | + raise Exception(msg) |
| 78 | + |
| 79 | +def assert_is_exe(path): |
| 80 | + if not path: |
| 81 | + raise Exception('path is empty.') |
| 82 | + if not os.path.isfile(path): |
| 83 | + raise Exception('%r is not a file.' %path) |
| 84 | + if not os.access(path, os.X_OK): |
| 85 | + raise Exception('%r is not executable by this user.' %path) |
71 | 86 |
|
72 | 87 | def run_doxygen(doxygen_path, config_file, working_dir, is_silent): |
| 88 | + assert_is_exe(doxygen_path) |
73 | 89 | config_file = os.path.abspath(config_file) |
74 | 90 | with cd(working_dir): |
75 | 91 | cmd = [doxygen_path, config_file] |
|
0 commit comments