mirror of https://github.com/tLDP/python-tldp
switch to the DAG model
This commit is contained in:
parent
84477c0f45
commit
3a0bb65961
|
@ -3,14 +3,17 @@
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
|
import os
|
||||||
import logging
|
import logging
|
||||||
logger = logging.getLogger(__name__)
|
import networkx as nx
|
||||||
|
|
||||||
from tldp.utils import which, firstfoundfile
|
from tldp.utils import which, firstfoundfile
|
||||||
from tldp.utils import arg_isexecutable, isexecutable
|
from tldp.utils import arg_isexecutable, isexecutable
|
||||||
from tldp.utils import arg_isreadablefile, isreadablefile
|
from tldp.utils import arg_isreadablefile, isreadablefile
|
||||||
|
|
||||||
from tldp.doctypes.common import BaseDoctype, SignatureChecker
|
from tldp.doctypes.common import BaseDoctype, SignatureChecker, depends
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def xslchunk_finder():
|
def xslchunk_finder():
|
||||||
|
@ -48,70 +51,99 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
|
||||||
'docbook4xml_xslprint': isreadablefile,
|
'docbook4xml_xslprint': isreadablefile,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
graph = nx.DiGraph()
|
||||||
|
|
||||||
buildorder = ['buildall']
|
buildorder = ['buildall']
|
||||||
|
|
||||||
buildscript = '''#! /bin/bash
|
def chdir_output(self):
|
||||||
#
|
os.chdir(self.output.dirname)
|
||||||
# -- generate LDP outputs from DocBook XML 4.x
|
return True
|
||||||
|
|
||||||
set -x
|
@depends(graph, chdir_output)
|
||||||
set -e
|
def make_name_htmls(self):
|
||||||
set -o pipefail
|
'''create a single page HTML output'''
|
||||||
|
s = '''"{config.docbook4xml_xsltproc}" > "{output.name_htmls}" \\
|
||||||
|
--nonet \\
|
||||||
|
--stringparam admon.graphics.path images/ \\
|
||||||
|
--stringparam base.dir . \\
|
||||||
|
"{config.docbook4xml_xslsingle}" \\
|
||||||
|
"{source.filename}"'''
|
||||||
|
return self.shellscript(s)
|
||||||
|
|
||||||
cd "{output.dirname}"
|
@depends(graph, make_name_htmls)
|
||||||
|
def make_name_txt(self):
|
||||||
|
'''create text output'''
|
||||||
|
s = '''"{config.docbook4xml_html2text}" > "{output.name_txt}" \\
|
||||||
|
-style pretty \\
|
||||||
|
-nobs \\
|
||||||
|
"{output.name_htmls}"'''
|
||||||
|
return self.shellscript(s)
|
||||||
|
|
||||||
"{config.docbook4xml_xsltproc}" > "{output.name_htmls}" \\
|
@depends(graph, chdir_output)
|
||||||
--nonet \\
|
def make_fo(self):
|
||||||
--stringparam admon.graphics.path images/ \\
|
'''generate the Formatting Objects intermediate output'''
|
||||||
--stringparam base.dir . \\
|
s = '''"{config.docbook4xml_xsltproc}" > "{output.name_fo}" \\
|
||||||
"{config.docbook4xml_xslsingle}" \\
|
"{config.docbook4xml_xslprint}" \\
|
||||||
"{source.filename}"
|
"{source.filename}"'''
|
||||||
|
self.removals.append(self.output.name_fo)
|
||||||
|
return self.shellscript(s)
|
||||||
|
|
||||||
"{config.docbook4xml_html2text}" > "{output.name_txt}" \\
|
# -- this is conditionally built--see logic in make_name_pdf() below
|
||||||
-style pretty \\
|
# @depends(graph, make_fo)
|
||||||
-nobs \\
|
def make_pdf_with_fop(self):
|
||||||
"{output.name_htmls}"
|
'''use FOP to create a PDF'''
|
||||||
|
s = '''"{config.docbook4xml_fop}" \\
|
||||||
|
-fo "{output.name_fo}" \\
|
||||||
|
-pdf "{output.name_pdf}"'''
|
||||||
|
return self.shellscript(s)
|
||||||
|
|
||||||
"{config.docbook4xml_xsltproc}" > "{output.name_fo}" \\
|
# -- this is conditionally built--see logic in make_name_pdf() below
|
||||||
"{config.docbook4xml_xslprint}" \\
|
# @depends(graph, chdir_output)
|
||||||
"{source.filename}"
|
def make_pdf_with_dblatex(self):
|
||||||
|
'''use dblatex (fallback) to create a PDF'''
|
||||||
|
s = '''"{config.docbook4xml_dblatex}" \\
|
||||||
|
-F xml \\
|
||||||
|
-t pdf \\
|
||||||
|
-o "{output.name_pdf}" \\
|
||||||
|
"{source.filename}"'''
|
||||||
|
return self.shellscript(s)
|
||||||
|
|
||||||
"{config.docbook4xml_fop}" \\
|
@depends(graph, make_fo)
|
||||||
-fo "{output.name_fo}" \\
|
def make_name_pdf(self):
|
||||||
-pdf "{output.name_pdf}" \\
|
stem = self.source.stem
|
||||||
|
classname = self.__class__.__name__
|
||||||
|
logger.info("%s calling method %s.%s",
|
||||||
|
stem, classname, 'make_pdf_with_fop')
|
||||||
|
if self.make_pdf_with_fop():
|
||||||
|
return True
|
||||||
|
logger.error("%s %s failed creating PDF, falling back to dblatex...",
|
||||||
|
stem, self.config.docbook4xml_fop)
|
||||||
|
logger.info("%s calling method %s.%s",
|
||||||
|
stem, classname, 'make_pdf_with_dblatex')
|
||||||
|
return self.make_pdf_with_dblatex()
|
||||||
|
|
||||||
test -e "{output.name_pdf}" \\
|
@depends(graph, make_name_htmls)
|
||||||
|| "{config.docbook4xml_dblatex}" \\
|
def make_html(self):
|
||||||
-F xml \\
|
'''create chunked HTML output'''
|
||||||
-t pdf \\
|
s = '''"{config.docbook4xml_xsltproc}" \\
|
||||||
-o "{output.name_pdf}" \\
|
--nonet \\
|
||||||
"{source.filename}"
|
--stringparam admon.graphics.path images/ \\
|
||||||
|
--stringparam base.dir . \\
|
||||||
|
"{config.docbook4xml_xslchunk}" \\
|
||||||
|
"{source.filename}"'''
|
||||||
|
return self.shellscript(s)
|
||||||
|
|
||||||
test -e "{output.name_fo}" \\
|
@depends(graph, make_html)
|
||||||
&& rm -f -- "{output.name_fo}"
|
def make_name_html(self):
|
||||||
|
'''rename xsltproc/docbook-XSL's index.html to LDP standard STEM.html'''
|
||||||
|
s = 'mv -v --no-clobber -- "{output.name_indexhtml}" "{output.name_html}"'
|
||||||
|
return self.shellscript(s)
|
||||||
|
|
||||||
"{config.docbook4xml_xsltproc}" \\
|
@depends(graph, make_name_html)
|
||||||
--nonet \\
|
def make_name_indexhtml(self):
|
||||||
--stringparam admon.graphics.path images/ \\
|
'''create final index.html symlink'''
|
||||||
--stringparam base.dir . \\
|
s = 'ln -svr -- "{output.name_html}" "{output.name_indexhtml}"'
|
||||||
"{config.docbook4xml_xslchunk}" \\
|
return self.shellscript(s)
|
||||||
"{source.filename}"
|
|
||||||
|
|
||||||
mv \\
|
|
||||||
--no-clobber \\
|
|
||||||
--verbose \\
|
|
||||||
-- "{output.name_indexhtml}" "{output.name_html}"
|
|
||||||
|
|
||||||
ln \\
|
|
||||||
--symbolic \\
|
|
||||||
--relative \\
|
|
||||||
--verbose \\
|
|
||||||
-- "{output.name_html}" "{output.name_indexhtml}"
|
|
||||||
|
|
||||||
# -- end of file'''
|
|
||||||
|
|
||||||
def buildall(self):
|
|
||||||
return self.shellscript(self.buildscript)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def argparse(p):
|
def argparse(p):
|
||||||
|
@ -137,7 +169,5 @@ ln \\
|
||||||
default=which('dblatex'),
|
default=which('dblatex'),
|
||||||
help='full path to dblatex [%(default)s]')
|
help='full path to dblatex [%(default)s]')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# -- end of file
|
# -- end of file
|
||||||
|
|
Loading…
Reference in New Issue