diff --git a/tldp/doctypes/common.py b/tldp/doctypes/common.py index 7d888f1..4d31dcc 100644 --- a/tldp/doctypes/common.py +++ b/tldp/doctypes/common.py @@ -4,7 +4,10 @@ from __future__ import absolute_import, division, print_function import os -from ..utils import logger +import stat +from tempfile import NamedTemporaryFile as ntf + +from tldp.utils import logger, execute class SignatureChecker(object): @@ -45,6 +48,29 @@ class BaseDoctype(object): assert validator(thing) return True + def shellscript(self, script): + source = self.source + output = self.output + config = self.config + + logdir = output.logdir + prefix = source.doctype.__name__ + '-' + + s = script.format(output=output, source=source, config=config) + tf = ntf(dir=logdir, prefix=prefix, suffix='.sh', delete=False) + tf.write(s) + tf.close() + + mode = stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR + os.chmod(tf.name, mode) + + cmd = [tf.name] + result = execute(cmd, logdir=logdir) + if result != 0: + return False + logger.debug("%s checking for complete set of files", source.stem) + return self.output.iscomplete + def generate(self): # -- the output directory gets to prepare; must return True # @@ -57,8 +83,9 @@ class BaseDoctype(object): # -- the processor gets to prepare; must return True # if not self.build_precheck(): - logger.warning("%s build_precheck failed (%s), skipping to next build", - self.source.stem, self.source.doctype.formatname) + logger.warning("%s %s failed (%s), skipping to next build", + 'build_precheck', self.source.stem, + self.source.doctype.formatname) return False # -- now, we can walk through build targets, and record a vector diff --git a/tldp/doctypes/docbook4xml.py b/tldp/doctypes/docbook4xml.py index adbb8e5..5f9e5d9 100644 --- a/tldp/doctypes/docbook4xml.py +++ b/tldp/doctypes/docbook4xml.py @@ -3,11 +3,7 @@ from __future__ import absolute_import, division, print_function -import os -import stat -from tempfile import NamedTemporaryFile as ntf - -from tldp.utils import logger, which, execute, firstfoundfile +from tldp.utils import logger, which, firstfoundfile from tldp.utils import arg_isexecutable, isexecutable from tldp.utils import arg_isreadablefile, isreadablefile @@ -73,8 +69,9 @@ class Docbook4XML(BaseDoctype, SignatureChecker): 'docbook4xml_xslprint': isreadablefile, } - buildorder = ['shellscript'] - script = '''#! /bin/bash + buildorder = ['buildall'] + + buildscript = '''#! /bin/bash # # -- generate LDP outputs from DocBook XML 4.x @@ -103,13 +100,16 @@ cd "{output.dirname}" "{config.docbook4xml_fop}" \\ -fo "{output.name_fo}" \\ -pdf "{output.name_pdf}" \\ - && rm -f -- "{output.name_fo}" -# "{config.docbook4xml_dblatex}" \\ -# -F xml \\ -# -t pdf \\ -# -o "{output.name_pdf}" \\ -# "{source.filename}" +test -e "{output.name_pdf}" \\ + || "{config.docbook4xml_dblatex}" \\ + -F xml \\ + -t pdf \\ + -o "{output.name_pdf}" \\ + "{source.filename}" + +test -e "{output.name_fo}" \\ + && rm -f -- "{output.name_fo}" "{config.docbook4xml_xsltproc}" \\ --nonet \\ @@ -131,28 +131,8 @@ ln \\ # -- end of file''' - def shellscript(self): - source = self.source - output = self.output - logdir = self.output.logdir - config = self.config - - s = self.script.format(output=self.output, - source=self.source, - config=self.config) - tf = ntf(dir=self.output.logdir, prefix='docbook4xml-shell-', - suffix='.sh', delete=False) - tf.write(s) - tf.close() - - mode = stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR - os.chmod(tf.name, mode) - - cmd = [tf.name] - result = execute(cmd, logdir=logdir) - if result != 0: - return False - return self.output.iscomplete + def buildall(self): + return self.shellscript(self.buildscript) #