''' Functions to build the SNO+ manuals, search index, and coding standards. Also contains function to update the RAT version. ''' from __future__ import print_function from __future__ import absolute_import from __future__ import division import os import subprocess from build_search import build_search from SCons.Errors import BuildError def write_rat_doc_version(target, source, env): ''' Write the RAT version file. ''' with open(source[0].path, "r") as f: raw = f.read() out = raw.format(rat_version=env['RATVERSION']) with open(target[0].path, "w") as f: f.write(out) def make_manual(indexpage): ''' Create a SNO+ manual via latex2html given an index page. ''' print("Building {}".format(indexpage)) # Check file exists if not os.path.isfile(indexpage): raise BuildError(errstr="{} does not exist".format(indexpage)) # Create /html at same level as /tex texdir = os.path.dirname(indexpage) rootdir = os.path.dirname(texdir) htmldir = os.path.abspath(os.path.join(rootdir, "html")) if not os.path.isdir(htmldir): os.mkdir(htmldir) # Latex2html # Build from /tex to find .inc_tex files sconsdir = os.getcwd() os.chdir(texdir) try: init_file = os.path.join(sconsdir, 'doc', '.latex2html-init') subprocess.check_call(["latex2html", "-init_file", init_file, "-verbosity", "0", "-dir", htmldir, indexpage]) except: raise BuildError(errstr="latex2html failed: {}".format(indexpage)) finally: os.chdir(sconsdir) # Copy .css options docdir = os.path.dirname(rootdir) manualcss = indexpage.replace(".tex", ".css") standardcss = os.path.join(docdir, "css", "style.css") if not os.path.isfile(standardcss): raise BuildError(errstr="{} does not exist".format(standardcss)) with open(standardcss, "r") as std: with open(manualcss, "w") as man: man.write(std.read()) # Build external links externaldir = os.path.join(htmldir, "external") if not os.path.isdir(externaldir): os.mkdir(externaldir) try: subprocess.check_call(["perl", os.path.join(docdir, "make_external_links.pl"), os.path.join(htmldir, "labels.pl"), externaldir]) except: raise BuildError(errstr="failed building external links: {}".format(indexpage)) def make_companion(target, source, env): ''' Create the entire RAT companion by generating all of the SNO+ manuals. Create a search index. ''' # Unused, but required arguments. del target del env for manual in source: try: make_manual(manual.path) except BuildError as exc: raise exc build_search("doc/search_index.js", "doc", strip_basedir=True, verbose=False) print("Companion complete")