mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2024-12-13 10:22:55 +01:00
update doxbuild.py
This commit is contained in:
parent
9cc0bb80b2
commit
ff5abe76a5
77
doxybuild.py
77
doxybuild.py
@ -2,12 +2,25 @@
|
|||||||
"""
|
"""
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from devtools import tarball
|
from devtools import tarball
|
||||||
|
from contextlib import contextmanager
|
||||||
|
import subprocess
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import os.path
|
|
||||||
import sys
|
import sys
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def cd(newdir):
|
||||||
|
"""
|
||||||
|
http://stackoverflow.com/questions/431684/how-do-i-cd-in-python
|
||||||
|
"""
|
||||||
|
prevdir = os.getcwd()
|
||||||
|
os.chdir(newdir)
|
||||||
|
try:
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
os.chdir(prevdir)
|
||||||
|
|
||||||
def find_program(*filenames):
|
def find_program(*filenames):
|
||||||
"""find a program in folders path_lst, and sets env[var]
|
"""find a program in folders path_lst, and sets env[var]
|
||||||
@param filenames: a list of possible names of the program to search for
|
@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):
|
|||||||
For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
|
For example, if dict is {'%VERSION%': '1.2345', '%BASE%': 'MyProg'},
|
||||||
then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
|
then all instances of %VERSION% in the file will be replaced with 1.2345 etc.
|
||||||
"""
|
"""
|
||||||
try:
|
with open(sourcefile, 'rb') as f:
|
||||||
f = open(sourcefile, 'rb')
|
|
||||||
contents = f.read()
|
contents = f.read()
|
||||||
f.close()
|
|
||||||
except:
|
|
||||||
print("Can't read source file %s"%sourcefile)
|
|
||||||
raise
|
|
||||||
for (k,v) in list(dict.items()):
|
for (k,v) in list(dict.items()):
|
||||||
v = v.replace('\\','\\\\')
|
v = v.replace('\\','\\\\')
|
||||||
contents = re.sub(k, v, contents)
|
contents = re.sub(k, v, contents)
|
||||||
try:
|
with open(targetfile, 'wb') as f:
|
||||||
f = open(targetfile, 'wb')
|
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
f.close()
|
|
||||||
except:
|
def getstatusoutput(cmd):
|
||||||
print("Can't write target file %s"%targetfile)
|
"""cmd is a list.
|
||||||
raise
|
"""
|
||||||
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
|
output, _ = process.communicate()
|
||||||
|
status = process.returncode
|
||||||
|
return status, output
|
||||||
|
|
||||||
|
def run_cmd(cmd, silent=False):
|
||||||
|
print('Running:', repr(' '.join(cmd)), 'in', repr(os.getcwd()))
|
||||||
|
sys.stdout.flush()
|
||||||
|
if silent:
|
||||||
|
status, output = getstatusoutput(cmd)
|
||||||
|
else:
|
||||||
|
status, output = os.system(' '.join(cmd)), ''
|
||||||
|
if status:
|
||||||
|
msg = 'error=%d, output="""\n%s\n"""' %(status, output)
|
||||||
|
print(msg)
|
||||||
|
#raise Exception(msg)
|
||||||
|
|
||||||
def run_doxygen(doxygen_path, config_file, working_dir, is_silent):
|
def run_doxygen(doxygen_path, config_file, working_dir, is_silent):
|
||||||
config_file = os.path.abspath(config_file)
|
config_file = os.path.abspath(config_file)
|
||||||
doxygen_path = doxygen_path
|
with cd(working_dir):
|
||||||
old_cwd = os.getcwd()
|
|
||||||
try:
|
|
||||||
os.chdir(working_dir)
|
|
||||||
cmd = [doxygen_path, config_file]
|
cmd = [doxygen_path, config_file]
|
||||||
print('Running:', ' '.join(cmd))
|
run_cmd(cmd, is_silent)
|
||||||
try:
|
|
||||||
import subprocess
|
|
||||||
except:
|
|
||||||
if os.system(' '.join(cmd)) != 0:
|
|
||||||
print('Documentation generation failed')
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
if is_silent:
|
|
||||||
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
||||||
else:
|
|
||||||
process = subprocess.Popen(cmd)
|
|
||||||
stdout, _ = process.communicate()
|
|
||||||
if process.returncode:
|
|
||||||
print('Documentation generation failed:')
|
|
||||||
print(stdout)
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
finally:
|
|
||||||
os.chdir(old_cwd)
|
|
||||||
|
|
||||||
def build_doc(options, make_release=False):
|
def build_doc(options, make_release=False):
|
||||||
if make_release:
|
if make_release:
|
||||||
@ -113,7 +114,7 @@ def build_doc(options, make_release=False):
|
|||||||
os.makedirs(output_dir)
|
os.makedirs(output_dir)
|
||||||
|
|
||||||
do_subst_in_file('doc/doxyfile', 'doc/doxyfile.in', subst_keys)
|
do_subst_in_file('doc/doxyfile', 'doc/doxyfile.in', subst_keys)
|
||||||
ok = run_doxygen(options.doxygen_path, 'doc/doxyfile', 'doc', is_silent=options.silent)
|
run_doxygen(options.doxygen_path, 'doc/doxyfile', 'doc', is_silent=options.silent)
|
||||||
if not options.silent:
|
if not options.silent:
|
||||||
print(open(warning_log_path, 'rb').read())
|
print(open(warning_log_path, 'rb').read())
|
||||||
index_path = os.path.abspath(os.path.join('doc', subst_keys['%HTML_OUTPUT%'], 'index.html'))
|
index_path = os.path.abspath(os.path.join('doc', subst_keys['%HTML_OUTPUT%'], 'index.html'))
|
||||||
|
Loading…
Reference in New Issue
Block a user