'''Functions to build the SNO+ manuals, search index and coding standards. And to update the rat version Jack Dunger October 2014 A.Mastbaum , October 2012 ''' import os import glob import build_search import string import subprocess 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 = string.Template(f.read()) out = raw.safe_substitute(RATVERSION = env['RATVERSION']) with open(target[0].path, "w") as f: f.write(out) return None def make_manual(indexpage): print "Building", indexpage # Check file exists if not os.path.isfile(indexpage): raise BuildError(errstr = "%s does not exist" %(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: subprocess.check_call(["latex2html","-verbosity","0","-dir",htmldir,indexpage]) except: raise BuildError(errstr = "latex2html failed: %s" %(indexpage)) 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 = "%s does not exist" %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: %s" %(indexpage)) def make_companion(target,source,env): for manual in source: try: make_manual(manual.path) except BuildError as exc: raise exc build_search.build_search("doc/search_index.js") print "Companion complete"