Skip to content

Commit ff5abe7

Browse files
committed
update doxbuild.py
1 parent 9cc0bb8 commit ff5abe7

1 file changed

Lines changed: 39 additions & 38 deletions

File tree

doxybuild.py

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22
"""
33
from __future__ import print_function
44
from devtools import tarball
5+
from contextlib import contextmanager
6+
import subprocess
57
import re
68
import os
7-
import os.path
89
import sys
910
import shutil
1011

12+
@contextmanager
13+
def cd(newdir):
14+
"""
15+
http://stackoverflow.com/questions/431684/how-do-i-cd-in-python
16+
"""
17+
prevdir = os.getcwd()
18+
os.chdir(newdir)
19+
try:
20+
yield
21+
finally:
22+
os.chdir(prevdir)
23+
1124
def find_program(*filenames):
1225
"""find a program in folders path_lst, and sets env[var]
1326
@param filenames: a list of possible names of the program to search for
@@ -28,51 +41,39 @@ def do_subst_in_file(targetfile, sourcefile, dict):
2841
For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
2942
then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
3043
"""
31-
try:
32-
f = open(sourcefile, 'rb')
44+
with open(sourcefile, 'rb') as f:
3345
contents = f.read()
34-
f.close()
35-
except:
36-
print("Can't read source file %s"%sourcefile)
37-
raise
3846
for (k,v) in list(dict.items()):
3947
v = v.replace('\\','\\\\')
4048
contents = re.sub(k, v, contents)
41-
try:
42-
f = open(targetfile, 'wb')
49+
with open(targetfile, 'wb') as f:
4350
f.write(contents)
44-
f.close()
45-
except:
46-
print("Can't write target file %s"%targetfile)
47-
raise
51+
52+
def getstatusoutput(cmd):
53+
"""cmd is a list.
54+
"""
55+
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
56+
output, _ = process.communicate()
57+
status = process.returncode
58+
return status, output
59+
60+
def run_cmd(cmd, silent=False):
61+
print('Running:', repr(' '.join(cmd)), 'in', repr(os.getcwd()))
62+
sys.stdout.flush()
63+
if silent:
64+
status, output = getstatusoutput(cmd)
65+
else:
66+
status, output = os.system(' '.join(cmd)), ''
67+
if status:
68+
msg = 'error=%d, output="""\n%s\n"""' %(status, output)
69+
print(msg)
70+
#raise Exception(msg)
4871

4972
def run_doxygen(doxygen_path, config_file, working_dir, is_silent):
5073
config_file = os.path.abspath(config_file)
51-
doxygen_path = doxygen_path
52-
old_cwd = os.getcwd()
53-
try:
54-
os.chdir(working_dir)
74+
with cd(working_dir):
5575
cmd = [doxygen_path, config_file]
56-
print('Running:', ' '.join(cmd))
57-
try:
58-
import subprocess
59-
except:
60-
if os.system(' '.join(cmd)) != 0:
61-
print('Documentation generation failed')
62-
return False
63-
else:
64-
if is_silent:
65-
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
66-
else:
67-
process = subprocess.Popen(cmd)
68-
stdout, _ = process.communicate()
69-
if process.returncode:
70-
print('Documentation generation failed:')
71-
print(stdout)
72-
return False
73-
return True
74-
finally:
75-
os.chdir(old_cwd)
76+
run_cmd(cmd, is_silent)
7677

7778
def build_doc(options, make_release=False):
7879
if make_release:
@@ -113,7 +114,7 @@ def yesno(bool):
113114
os.makedirs(output_dir)
114115

115116
do_subst_in_file('doc/doxyfile', 'doc/doxyfile.in', subst_keys)
116-
ok = run_doxygen(options.doxygen_path, 'doc/doxyfile', 'doc', is_silent=options.silent)
117+
run_doxygen(options.doxygen_path, 'doc/doxyfile', 'doc', is_silent=options.silent)
117118
if not options.silent:
118119
print(open(warning_log_path, 'rb').read())
119120
index_path = os.path.abspath(os.path.join('doc', subst_keys['%HTML_OUTPUT%'], 'index.html'))

0 commit comments

Comments
 (0)