Commit bf1c400c authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Modify build_version to run sphinx via a docker container.

parent ce51d38a
......@@ -58,19 +58,22 @@ VERSION = "VERSION"
APP_DIR = os.getcwd()
APP_STATIC = opj(APP_DIR, "static")
CHANGELOG = opj(APP_STATIC, "CHANGELOG")
DOCS_DIR = opj(APP_STATIC, "docs")
DBUISRC = opj(APP_STATIC, "plugin_dbui", "src")
EXTJSSRC = opj(APP_STATIC, "plugin_extjs", "src")
JSDOC = opj(APP_STATIC, "docs", "jsduck")
JSDOC = opj(DOCS_DIR, "jsduck")
JSLIBDEBUG = opj(APP_STATIC, "%s-debug.js" % APP)
JSLIBMIN = opj(APP_STATIC, "%s-min.js" % APP)
JSLIBSRC = opj(APP_STATIC, APP, "src")
PDFDOC = opj(APP_STATIC, "docs", PDF)
PDFDOC = opj(DOCS_DIR, PDF)
# path running behind a docker container
W2P_DIR_CNT = "/opt/web2py"
APP_DIR_CNT = opj(W2P_DIR_CNT, "applications", APP)
APP_STATIC_CNT = opj(APP_DIR_CNT, "static")
DBUISRC_CNT = opj(APP_STATIC_CNT, "plugin_dbui", "src")
DOCS_DIR_CNT = opj(APP_STATIC_CNT, "docs")
DOCSRC_CNT = opj(APP_DIR_CNT, "docs")
EXTJSSRC_CNT = opj(APP_STATIC_CNT, "plugin_extjs", "src")
JSDOC_CNT = opj(APP_STATIC_CNT, "docs", "jsduck")
JSLIBDEBUG_CNT = opj(APP_STATIC_CNT, "%s-debug.js" % APP)
......@@ -140,10 +143,7 @@ def build_html():
jsduck()
for doc in (API, REFERENCE, USER):
docsrc = opj(DOCSRC, doc)
if os.path.exists(docsrc):
sphinx("-b html", docsrc, opj(DOCS, doc))
sphinx("html", doc)
def build_pdf(doc):
......@@ -160,42 +160,53 @@ def build_pdf(doc):
print '\tSkip this step.\n'
return
latexdoc = opj(DOCS, LATEX)
srcdir = opj(DOCSRC, doc)
if not os.path.exists(srcdir):
print "\n\tNo source file,", srcdir
print "\tSkip this step.\n"
return
# directories
cwd = os.getcwd()
latexdir = opj(DOCS_DIR, LATEX)
if not os.path.exists(PDFDOC):
os.mkdir(PDFDOC)
# generate the latex
sphinx("-b latex", opj(DOCSRC, doc), latexdoc)
sphinx("latex", doc)
# the current directory
cwd = os.getcwd()
# process the tex file twice to get reference right
os.chdir(latexdir)
# find the name of the tex file
os.chdir(latexdoc)
filenames = [el for el in os.listdir('.') if el.endswith('.tex')]
filename = (filenames[0] if len(filenames) == 1 else None)
if not filename:
print "\n\tNo latex file !"
print "\n\tNo latex file !\n"
return
# process the latex file twice
call(["pdflatex", filename])
call(["pdflatex", filename])
try:
check_output(["pdflatex", "-interaction", "nonstopmode", filename])
# move the pdf file
os.chdir(cwd)
except CalledProcessError:
print "\n\tFailled to generate PDF file !"
print "\tCheck LaTeX file in", latexdir, "\n"
return
check_output(["pdflatex", filename])
pdfdir = opj(DOCS, PDF)
if not os.path.exists(pdfdir):
os.mkdir(pdfdir)
os.chdir(cwd)
fin = filename.replace('.tex', '.pdf')
# rename the pdf file as application_doctype.pdf
fpdf = filename.replace('.tex', '.pdf')
fout = "%s_%s.pdf" % (os.path.splitext(filename)[0], doc)
os.rename(opj(latexdoc, fin), opj(pdfdir, fout))
os.rename(opj(latexdir, fpdf), opj(PDFDOC, fout))
# remove the latex directory
call(["rm", "-rf", latexdoc])
call(["rm", "-rf", latexdir])
print "PDF documentation in", PDFDOC
print "\tPDF file", opj(PDFDOC, fout)
def change_log():
......@@ -569,32 +580,74 @@ def set_version(version):
fichier.write(version)
def sphinx(*args, **kwargs):
"""run the sphinx-build:
def sphinx(builder, doc):
"""run the sphinx-build.
Args:
*args: list of variable arguments containing the sphinx-build options.
The buildir depend on the builder. for HTML:
static/docs/api
static/docs/reference
static/docs/user
**kwargs: keyword argument of the function ``subprocess.call``.
For latex:
Examples:
* static/docs/latex
* the pdf is in static/docs/pdf
* the file name is application_doc.pdf
where doc = api, reference or user
sphinx("-b html sourcedir outdir")
sphinx("-b html", sourcedir, outdir)
Args:
builder (str): sphinx builder. Possible values are html, latex, ...
doc (str): possible value are api, reference, user
"""
if not which("sphinx-build"):
print '\n\tThe application sphinx is missing !'
print '\tSkip this step.\n'
print "\nBuild", builder, "documentation for", doc, "...\n"
cmd = which("sphinx-build")
if len(cmd) == 0:
print "\n\tThe application sphinx is missing !"
print "\tSkip this step.\n"
return
cmd = ["sphinx-build"]
cmd.extend(args[0].split())
srcdir = opj(DOCSRC, doc)
if not os.path.exists(srcdir):
print "\n\tNo source file", srcdir
print "\tSkip this step.\n"
return
if len(args) > 1:
cmd.extend(args[1:])
bdrdir = (LATEX if builder == "latex" else doc)
outdir = opj(DOCS_DIR, bdrdir)
call(cmd, **kwargs)
# clean existing directory
if os.path.exists(outdir):
call(["rm", "-rf", outdir])
# NOTE
# the processing depend on the localisation of jsduck
# either on the localhost or behind a docker container
# the length of the cmd list allows to separate the two cases
# NOTE
# container is running as root
# permissions have to be changed for the current user
# NOTE
# build directory also depends on the builder
is_behind_cnt = len(cmd) > 1
if is_behind_cnt:
srcdir = opj(DOCSRC_CNT, doc)
outdir = opj(DOCS_DIR_CNT, bdrdir)
# process -- only warning appears on the console
cmd.extend(["-b", builder, "-q", srcdir, outdir])
call(cmd)
if is_behind_cnt:
cnt = ARGS.docker_container
call(["docker", "exec", cnt, "chown", "-R", get_perm(), outdir])
print "\n\t%s documentation in" % builder.upper(), outdir
def start_release():
......@@ -758,7 +811,7 @@ if __name__ == '__main__':
ARGS = APS.parse_args()
if ARGS.api_doc:
sphinx("-b html", opj(DOCSRC, API), opj(DOCS, API))
sphinx("html", API)
if ARGS.api_pdf:
build_pdf(API)
......@@ -782,7 +835,7 @@ if __name__ == '__main__':
set_version(raw_input(MSG_RELEASE))
if ARGS.reference_doc:
sphinx("-b html", opj(DOCSRC, REFERENCE), opj(DOCS, REFERENCE))
sphinx("html", REFERENCE)
if ARGS.reference_pdf:
build_pdf(REFERENCE)
......@@ -791,7 +844,7 @@ if __name__ == '__main__':
start_release()
if ARGS.user_doc:
sphinx("-b html", opj(DOCSRC, USER), opj(DOCS, USER))
sphinx("html", USER)
if ARGS.user_pdf:
build_pdf(USER)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment