move method shellscript into BaseDoctype

and fix a few errors in the generated DocBook XML 4.x script
This commit is contained in:
Martin A. Brown 2016-02-23 21:58:03 -08:00
parent f1343deb00
commit ad2a1763ec
2 changed files with 45 additions and 38 deletions

View File

@ -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

View File

@ -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)
#