def makeTransform(file): xsl = util.makeXsl(file) def t(xml, files, **params): xml = xsl(xml, **params) errors = extractLog(xsl.error_log) return xml, {}, errors return t
from tempfile import mkdtemp import subprocess from lxml import etree import urllib2 import module2dbk import collection2dbk import util DEBUG = 'DEBUG' in os.environ BASE_PATH = os.getcwd() # XSL files DOCBOOK2XHTML_XSL = util.makeXsl('dbk2epub.xsl') DOCBOOK_CLEANUP_XSL = util.makeXsl('dbk-clean-whole.xsl') def convert(dbk1, files): """ Converts a Docbook Element and a dictionary of files into a PDF. """ def transform(xslDoc, xmlDoc): """ Performs an XSLT transform and parses the <xsl:message /> text """ ret = xslDoc( xmlDoc ) # , **({'cnx.tempdir.path':"'%s'" % tempdir})) Don't set the tempdir. We don't need it for entry in xslDoc.error_log: # TODO: Log the errors (and convert JSON to python) instead of just printing print >> sys.stderr, entry.message.encode('utf-8') return ret
import os import Image from StringIO import StringIO from tempfile import mkstemp #try: # import json #except KeyError: # import simplejson as json from lxml import etree import urllib2 import module2dbk import util COLLXML_PARAMS = util.makeXsl('collxml-params-json.xsl') COLLXML2DOCBOOK_XSL = util.makeXsl('collxml2dbk.xsl') DOCBOOK_CLEANUP_XSL = util.makeXsl('dbk-clean-whole.xsl') DOCBOOK_NORMALIZE_PATHS_XSL = util.makeXsl('dbk2epub-normalize-paths.xsl') DOCBOOK_NORMALIZE_GLOSSARY_XSL = util.makeXsl('dbk-clean-whole-remove-duplicate-glossentry.xsl') XINCLUDE_XPATH = etree.XPath('//xi:include', namespaces=util.NAMESPACES) # etree.XSLT does not allow returning just a text node so the XSLT wraps it in a <root/> PARAMS_XPATH = etree.XPath('/root[1]/text()[1]', namespaces=util.NAMESPACES) def transform(xslDoc, xmlDoc): """ Performs an XSLT transform and parses the <xsl:message /> text """ ret = xslDoc(xmlDoc) for entry in xslDoc.error_log:
from tempfile import mkdtemp import subprocess from lxml import etree import urllib2 import module2dbk import collection2dbk import util DEBUG = "DEBUG" in os.environ BASE_PATH = os.getcwd() # XSL files DOCBOOK2XHTML_XSL = util.makeXsl("dbk2epub.xsl") DOCBOOK_CLEANUP_XSL = util.makeXsl("dbk-clean-whole.xsl") def convert(dbk1, files): """ Converts a Docbook Element and a dictionary of files into a PDF. """ def transform(xslDoc, xmlDoc): """ Performs an XSLT transform and parses the <xsl:message /> text """ ret = xslDoc(xmlDoc) # , **({'cnx.tempdir.path':"'%s'" % tempdir})) Don't set the tempdir. We don't need it for entry in xslDoc.error_log: # TODO: Log the errors (and convert JSON to python) instead of just printing print >> sys.stderr, entry.message.encode("utf-8") return ret # Step 0 (Sprinkle in some index hints whenever terms are used)
import os try: import Image except: from PIL import Image from StringIO import StringIO import subprocess from lxml import etree import urllib2 import util SAXON_PATH = util.resource_filename('lib', 'saxon9he.jar') MATH2SVG_PATH = util.resource_filename('xslt2', 'math2svg-in-docbook.xsl') DOCBOOK_BOOK_XSL = util.makeXsl('moduledbk2book.xsl') MATH_XPATH = etree.XPath('//mml:math', namespaces=util.NAMESPACES) DOCBOOK_SVG_IMAGE_XPATH = etree.XPath('//db:imagedata[svg:svg]', namespaces=util.NAMESPACES) DOCBOOK_SVG_XPATH = etree.XPath('svg:svg', namespaces=util.NAMESPACES) DOCBOOK_IMAGE_XPATH = etree.XPath('//db:imagedata[@fileref]', namespaces=util.NAMESPACES) # ----------------------------- # Transform Structure: # # Every transform takes in 3 arguments: # - xml doc # - dictionary of files (string name, string bytes) # - optional dictionary of parameters (string, string) # # Every transform returns:
except: from PIL import Image from StringIO import StringIO from tempfile import mkstemp #try: # import json #except KeyError: # import simplejson as json from lxml import etree import urllib2 import module2dbk import util COLLXML_PARAMS = util.makeXsl('collxml-params-json.xsl') COLLXML2DOCBOOK_XSL = util.makeXsl('collxml2dbk.xsl') DOCBOOK_CLEANUP_XSL = util.makeXsl('dbk-clean-whole.xsl') DOCBOOK_NORMALIZE_PATHS_XSL = util.makeXsl('dbk2epub-normalize-paths.xsl') DOCBOOK_NORMALIZE_GLOSSARY_XSL = util.makeXsl('dbk-clean-whole-remove-duplicate-glossentry.xsl') XINCLUDE_XPATH = etree.XPath('//xi:include', namespaces=util.NAMESPACES) # etree.XSLT does not allow returning just a text node so the XSLT wraps it in a <root/> PARAMS_XPATH = etree.XPath('/root[1]/text()[1]', namespaces=util.NAMESPACES) def transform(xslDoc, xmlDoc): """ Performs an XSLT transform and parses the <xsl:message /> text """ ret = xslDoc(xmlDoc) for entry in xslDoc.error_log:
from tempfile import mkdtemp import subprocess from lxml import etree import urllib2 import module2dbk import collection2dbk import util DEBUG= 'DEBUG' in os.environ BASE_PATH = os.getcwd() # XSL files DOCBOOK2XHTML_XSL=util.makeXsl('dbk2xhtml.xsl') DOCBOOK_CLEANUP_XSL = util.makeXsl('dbk-clean-whole.xsl') MODULES_XPATH = etree.XPath('//col:module/@document', namespaces=util.NAMESPACES) IMAGES_XPATH = etree.XPath('//c:*/@src[not(starts-with(.,"http:"))]', namespaces=util.NAMESPACES) def __doStuff(dir): collxml = etree.parse(os.path.join(dir, 'collection.xml')) moduleIds = MODULES_XPATH(collxml) modules = {} # {'m1000': (etree.Element, {'file.jpg':'23947239874'})} allFiles = {} for moduleId in moduleIds: print >> sys.stderr, "LOG: Starting on %s" % (moduleId)
from tempfile import mkdtemp import subprocess import shutil from lxml import etree import urllib2 import module2dbk import collection2dbk import util BASE_PATH = os.getcwd() DEBUG=True # XSL files DOCBOOK2XHTML_XSL=util.makeXsl('dbk2xhtml.xsl') DOCBOOK_CLEANUP_XSL = util.makeXsl('dbk-clean-whole.xsl') DOCBOOK2OPF = util.makeXsl('dbk2mobiopf.xsl') MODULES_XPATH = etree.XPath('//col:module/@document', namespaces=util.NAMESPACES) IMAGES_XPATH = etree.XPath('//c:*/@src[not(starts-with(.,"http:"))]', namespaces=util.NAMESPACES) def collection2xhtml(collection_dir, output_xhtml, reduce_quality=False): p = util.Progress() collxml = etree.parse(os.path.join(collection_dir, 'collection.xml')) moduleIds = MODULES_XPATH(collxml) modules = {} # {'m1000': (etree.Element, {'file.jpg':'23947239874'})}
from tempfile import mkdtemp import subprocess import shutil from lxml import etree import urllib2 import module2dbk import collection2dbk import util BASE_PATH = os.getcwd() DEBUG = True # XSL files DOCBOOK2XHTML_XSL = util.makeXsl("dbk2xhtml.xsl") DOCBOOK_CLEANUP_XSL = util.makeXsl("dbk-clean-whole.xsl") DOCBOOK2OPF = util.makeXsl("dbk2mobiopf.xsl") MODULES_XPATH = etree.XPath("//col:module/@document", namespaces=util.NAMESPACES) IMAGES_XPATH = etree.XPath('//c:*/@src[not(starts-with(.,"http:"))]', namespaces=util.NAMESPACES) def collection2xhtml(collection_dir, output_xhtml, reduce_quality=False): p = util.Progress() collxml = etree.parse(os.path.join(collection_dir, "collection.xml")) moduleIds = MODULES_XPATH(collxml)