diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-03-28 20:22:32 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-03-28 20:22:32 (GMT) |
commit | 335d3d25e07ddcf7c00ba3b2550858a2374dd3db (patch) | |
tree | 26a5d95818e3e12ac2811903fe815044fa7f6d73 /DocBook/SCons | |
parent | 3afa4f741c26360245dc313bc368f508b26a6b96 (diff) | |
download | swift-contrib-335d3d25e07ddcf7c00ba3b2550858a2374dd3db.zip swift-contrib-335d3d25e07ddcf7c00ba3b2550858a2374dd3db.tar.bz2 |
Moved DocBook module.
Diffstat (limited to 'DocBook/SCons')
-rw-r--r-- | DocBook/SCons/DocBook.py | 86 | ||||
-rw-r--r-- | DocBook/SCons/FO.py | 45 | ||||
-rw-r--r-- | DocBook/SCons/XSLT.py | 63 |
3 files changed, 0 insertions, 194 deletions
diff --git a/DocBook/SCons/DocBook.py b/DocBook/SCons/DocBook.py deleted file mode 100644 index 8d0b171..0000000 --- a/DocBook/SCons/DocBook.py +++ /dev/null @@ -1,86 +0,0 @@ -################################################################################ -# DocBook pseudobuilder -################################################################################ - -import SCons.Util, SCons.Action -import xml.dom.minidom, re, os.path, sys - -def generate(env) : - # Location of stylesheets and catalogs - docbook_dir = "#/DocBook" - docbook_xsl_style_dir = env.Dir(docbook_dir + "/Stylesheets").abspath - docbook_xml_catalog = env.File("catalog.xml").abspath - docbook_xml_dir = env.Dir("#/3rdParty/DocBook/XML").abspath - docbook_xsl_dir = env.Dir("#/3rdParty/DocBook/XSL").abspath - fop_fonts_dir = env.Dir(docbook_dir + "/Fonts").abspath - - # Generates a catalog from paths to external tools - def buildCatalog(target, source, env) : - catalog = """<?xml version='1.0'?> -<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="public"> - <rewriteSystem - systemIdStartString="http://www.oasis-open.org/docbook/xml/4.5/" - rewritePrefix="%(docbook_xml_dir)s/" /> - <rewriteSystem - systemIdStartString="docbook-xsl:/" - rewritePrefix="%(docbook_xsl_dir)s/" /> -</catalog>""" - - file = open(target[0].abspath, "w") - file.write(catalog % { - "docbook_xml_dir" : source[0].get_contents(), - "docbook_xsl_dir" : source[1].get_contents(), - }) - file.close() - - # Generates a FOP config file - def buildFopConfig(target, source, env) : - fopcfg = """<fop version=\"1.0\"> - <renderers> - <renderer mime=\"application/pdf\"> - <fonts> - <directory recursive=\"true\">%(fonts_dir)s</directory> - </fonts> - </renderer> - </renderers> -</fop>""" - - file = open(target[0].abspath, "w") - file.write(fopcfg % { - "fonts_dir" : source[0].get_contents() - }) - file.close() - - # Builds a DocBook file - def buildDocBook(env, source) : - db_env = env.Clone() - db_env["XMLCATALOGS"] = [docbook_xml_catalog] - db_env["ENV"].update({"OS" : os.environ.get("OS", "")}) - - # PDF generation - fo = db_env.XSLT(os.path.splitext(source)[0] + ".fo", source, - XSLTSTYLESHEET = db_env["DOCBOOK_XSL_FO"]) - pdf = db_env.FO(fo) - - # HTML generation - db_env.XSLT(os.path.splitext(source)[0] + ".html", source, - XSLTSTYLESHEET = db_env["DOCBOOK_XSL_HTML"]) - - # Import tools - env.Tool("FO", toolpath = [docbook_dir + "/SCons"]) - env.Tool("XSLT", toolpath = [docbook_dir + "/SCons"]) - - # Catalog file generation - env.Command("catalog.xml", [env.Value(docbook_xml_dir), env.Value(docbook_xsl_dir)], SCons.Action.Action(buildCatalog, cmdstr = "$GENCOMSTR")) - - # FO config file generation - env["FOCFG"] = env.File("fop.cfg").abspath - env.Command("fop.cfg", [env.Value(fop_fonts_dir)], SCons.Action.Action(buildFopConfig, cmdstr = "$GENCOMSTR")) - - # DocBook stylesheets - env["DOCBOOK_XSL_FO"] = docbook_xsl_style_dir + "/fo/docbook.xsl" - env["DOCBOOK_XSL_HTML"] = docbook_xsl_style_dir + "/html/docbook.xsl" - env.AddMethod(buildDocBook, "DocBook") - -def exists(env) : - return True diff --git a/DocBook/SCons/FO.py b/DocBook/SCons/FO.py deleted file mode 100644 index c7596d6..0000000 --- a/DocBook/SCons/FO.py +++ /dev/null @@ -1,45 +0,0 @@ -import SCons.Util -import xml.dom.minidom, re - -################################################################################ -# XSL-FO builder -################################################################################ - -def generate(env) : - def generate_actions(source, target, env, for_signature) : - if len(env["FOCFG"]) > 0 : - cmd = "$FO -c $FOCFG $FOFLAGS $SOURCE $TARGET" - else : - cmd = "$FO $FOFLAGS $SOURCE $TARGET" - return SCons.Action.Action(cmd, cmdstr = "$FOCOMSTR") - - def modify_sources(target, source, env) : - if len(env["FOCFG"]) > 0 : - source.append(env["FOCFG"]) - return target, source - - def scan_fo(node, env, path) : - dependencies = set() - try : - document = xml.dom.minidom.parseString(node.get_contents()) - except xml.parsers.expat.ExpatError: - return [] - for include in document.getElementsByTagNameNS("http://www.w3.org/1999/XSL/Format", "external-graphic") : - m = re.match("url\((.*)\)", include.getAttribute("src")) - if m : - dependencies.add(m.group(1)) - return list(dependencies) - - env["FO"] = "fop" - env["FOFLAGS"] = "" - env["FOCFG"] = "" - env["BUILDERS"]["FO"] = SCons.Builder.Builder( - generator = generate_actions, - emitter = modify_sources, - source_scanner = SCons.Scanner.Scanner(function = scan_fo, skeys = [".fo"]), - suffix = ".pdf", - src_suffix = ".fo" - ) - -def exists(env) : - return True diff --git a/DocBook/SCons/XSLT.py b/DocBook/SCons/XSLT.py deleted file mode 100644 index 83b5ec2..0000000 --- a/DocBook/SCons/XSLT.py +++ /dev/null @@ -1,63 +0,0 @@ -import SCons.Util -import xml.dom.minidom, os, os.path - -################################################################################ -# XSLT processor -################################################################################ - -def generate(env) : - def generate_actions(source, target, env, for_signature) : - if not env.has_key("XSLTSTYLESHEET") : - raise SCons.Errors.UserError, "The XSLTSTYLESHEET construction variable must be defined" - - # Process the XML catalog files - # FIXME: It's probably not clean to do an ENV assignment globally - env["ENV"]["XML_CATALOG_FILES"] = " ".join(env.get("XMLCATALOGS", "")) - - # Build the XMLLint command - xmllintcmd = ["$XMLLINT", "--nonet", "--xinclude", "--postvalid", "--noout", "$SOURCE"] - - # Build the XSLT command - xsltcmd = ["$XSLT", "--nonet", "--xinclude"] - for (param, value) in env["XSLTPARAMS"] : - xsltcmd += ["--stringparam", param, value] - xsltcmd += ["-o", "$TARGET", "$XSLTSTYLESHEET", "$SOURCE"] - - return [ - SCons.Action.Action([xmllintcmd], cmdstr = "$XMLLINTCOMSTR"), - SCons.Action.Action([xsltcmd], cmdstr = "$XSLTCOMSTR")] - - def modify_sources(target, source, env) : - if len(env["FOCFG"]) > 0 : - source.append(env["FOCFG"]) - source.append(env.get("XMLCATALOGS", [])) - return target, source - - def scan_xml(node, env, path) : - dependencies = set() - nodes = [node] - while len(nodes) > 0 : - node = nodes.pop() - try : - document = xml.dom.minidom.parseString(node.get_contents()) - except xml.parsers.expat.ExpatError: - continue - for include in document.getElementsByTagNameNS("http://www.w3.org/2001/XInclude", "include") : - include_file = include.getAttribute("href") - dependencies.add(include_file) - if include.getAttribute("parse") != "text" : - nodes.append(env.File(include_file)) - return list(dependencies) - - env["XMLLINT"] = "xmllint" - env["XSLT"] = "xsltproc" - env["XSLTPARAMS"] = [] - env["BUILDERS"]["XSLT"] = SCons.Builder.Builder( - generator = generate_actions, - emitter = modify_sources, - source_scanner = SCons.Scanner.Scanner(function = scan_xml), - src_suffix = ".xml" - ) - -def exists(env) : - return True |