summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-03-28 19:43:32 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-03-28 19:44:49 (GMT)
commit3afa4f741c26360245dc313bc368f508b26a6b96 (patch)
tree4fc9fedac990a099010fed8a4ee09ddc51c21cc5 /DocBook/SCons/DocBook.py
parent7548dabae7d10e48816142e508be651ada9f7bc3 (diff)
downloadswift-contrib-3afa4f741c26360245dc313bc368f508b26a6b96.zip
swift-contrib-3afa4f741c26360245dc313bc368f508b26a6b96.tar.bz2
Added DocBook infrastructure.
Imported most of "DocBook kit". Added placeholder for Swiften developers guide.
Diffstat (limited to 'DocBook/SCons/DocBook.py')
-rw-r--r--DocBook/SCons/DocBook.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/DocBook/SCons/DocBook.py b/DocBook/SCons/DocBook.py
new file mode 100644
index 0000000..8d0b171
--- /dev/null
+++ b/DocBook/SCons/DocBook.py
@@ -0,0 +1,86 @@
+################################################################################
+# 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