switch all processors to generated shell scripts

This commit is contained in:
Martin A. Brown 2016-02-23 22:44:17 -08:00
parent ce359dfa32
commit fc2cdf975d
3 changed files with 42 additions and 299 deletions

View File

@ -134,6 +134,5 @@ ln \\
def buildall(self):
return self.shellscript(self.buildscript)
#
# -- end of file

View File

@ -179,215 +179,6 @@ ln \\
def buildall(self):
return self.shellscript(self.mainscript)
# buildorder = ['create_docindex_blank',
# 'create_docindex_data',
# 'create_docindex_full',
# 'move_docindex_to_source',
# 'create_htmls',
# 'create_pdf',
# 'create_txt',
# 'create_html',
# 'create_indexhtml',
# ]
#
# -- these names are (sort-of) chosen by the SGML toolchain
docindex = 'index.sgml'
docindexdata = 'HTML.index'
def create_docindex_blank(self):
stem = self.source.stem
exe = collateindex = self.config.docbooksgml_collateindex
outf = os.path.join(self.source.dirname, self.docindex)
cmd = [collateindex, '-N', '-o', outf]
logger.debug("%s creating blank %s (%s).", stem, outf, exe)
result = execute(cmd, logdir=self.output.logdir)
if result != 0:
return False
logger.info("%s created blank %s.", stem, outf)
return os.path.isfile(outf)
def create_docindex_data(self):
stem = self.source.stem
exe = openjade = self.config.docbooksgml_openjade
inf = self.source.filename
if not os.path.exists(inf):
return False
outf = os.path.join(self.output.dirname, self.docindexdata) # implicit
cmd = [openjade, '-t', 'sgml', '-V', 'html-index', '-d',
self.config.docbooksgml_docbookdsl, inf]
logger.debug("%s creating idata %s (%s).", stem, outf, exe)
result = execute(cmd, logdir=self.output.logdir)
if result != 0:
return False
logger.info("%s created idata %s.", stem, outf)
return os.path.isfile(outf)
def create_docindex_full(self):
stem = self.source.stem
exe = collateindex = self.config.docbooksgml_collateindex
inf = self.source.filename
docindexdata = os.path.join(self.output.dirname, self.docindexdata)
if (not os.path.exists(inf)) or (not os.path.exists(docindexdata)):
return False
outf = os.path.join(self.output.dirname, self.docindex)
cmd = [collateindex, '-g', '-t', 'Index', '-i', 'doc-index', '-o',
outf, docindexdata, inf]
logger.debug("%s creating index %s (%s).", stem, outf, exe)
result = execute(cmd, logdir=self.output.logdir)
if result != 0:
return False
logger.info("%s created index %s.", stem, outf)
return os.path.isfile(outf)
def move_docindex_to_source(self):
stem = self.source.stem
source = os.path.join(self.output.dirname, self.docindex)
target = os.path.join(self.source.dirname, self.docindex)
if os.path.exists(target):
try:
os.unlink(target)
logger.debug("%s unlinked index %s (old).", stem, target)
except OSError:
logger.debug("%s could not unlink old %s.", target)
logger.debug("%s renaming index %s to %s.", stem, source, target)
try:
os.rename(source, target)
logger.info("%s created index %s (new).", stem, target)
except OSError:
logger.info("%s failed renaming %s (new).", stem, target)
return os.path.isfile(target)
def post_move_docindex_to_source(self):
'''clear this directory (but no subdirectories)'''
stem = self.source.stem
dirname = self.output.dirname
for name in os.listdir(dirname):
fullname = os.path.join(dirname, name)
if os.path.isfile(fullname):
logger.debug("%s removing %s.", stem, fullname)
os.unlink(fullname)
else:
logger.debug("%s not removing %s.", stem, fullname)
return True
def create_html(self):
stem = self.source.stem
exe = jw = self.config.docbooksgml_jw
inf = self.source.filename
if not os.path.exists(inf):
return False
outf = self.output.name_indexhtml
cmd = [jw, '-f', 'docbook', '-b', 'html',
'--dsl', self.config.docbooksgml_ldpdsl + '#html',
'--output', '.', inf]
logger.debug("%s creating HTML %s (%s).", stem, outf, exe)
result = execute(cmd, logdir=self.output.logdir)
if result != 0:
return False
return os.path.isfile(outf)
def post_create_html(self):
stem = self.source.stem
outf = self.output.name_html
source = os.path.basename(self.output.name_indexhtml)
target = os.path.basename(outf)
logger.debug("%s renaming HTML %s (from %s).", stem, outf, source)
try:
os.rename(source, target)
logger.info("%s created HTML %s.", stem, outf)
except OSError:
logger.debug("%s failed renaming HTML file to %s.", stem, target)
return os.path.isfile(outf)
def create_htmls(self):
stem = self.source.stem
exe = jw = self.config.docbooksgml_jw
inf = self.source.filename
if not os.path.exists(inf):
return False
outf = self.output.name_html
cmd = [jw, '-f', 'docbook', '-b', 'html', '-V', 'nochunks',
'--dsl', self.config.docbooksgml_ldpdsl + '#html',
'--output', '.', inf]
logger.debug("%s creating HTMLS %s (%s).", stem, outf, exe)
result = execute(cmd, logdir=self.output.logdir)
if result != 0:
return False
return os.path.isfile(outf)
def post_create_htmls(self):
stem = self.source.stem
outf = self.output.name_htmls
source = os.path.basename(self.output.name_html)
target = os.path.basename(outf)
logger.debug("%s renaming HTMLS to %s.", stem, target)
try:
os.rename(source, target)
logger.info("%s created HTMLS %s.", stem, outf)
except OSError:
logger.debug("%s failed renaming HTML single file to %s.",
stem, target)
return os.path.isfile(outf)
def create_indexhtml(self):
stem = self.source.stem
outf = self.output.name_html
target = os.path.basename(outf)
linkname = self.output.name_indexhtml
symlink = os.path.basename(linkname)
logger.debug("%s creating index.html symlink to %s.", stem, target)
try:
os.symlink(target, symlink)
logger.info("%s created link %s to %s.", stem, linkname, target)
except OSError:
logger.debug("%s failed in creating index.html symlink.", stem)
return os.path.islink(linkname)
def create_pdf(self):
stem = self.source.stem
exe = jw = self.config.docbooksgml_jw
inf = self.source.filename
if not os.path.exists(inf):
return False
outf = self.output.name_pdf
cmd = [jw, '-f', 'docbook', '-b', 'pdf', '--output', '.', inf]
logger.debug("%s creating PDF %s (%s).", stem, outf, exe)
result = execute(cmd, logdir=self.output.logdir)
if result != 0:
return self.create_pdf_alternate()
logger.info("%s created PDF %s (%s).", stem, outf, exe)
return os.path.isfile(outf)
def create_pdf_alternate(self):
stem = self.source.stem
exe = dblatex = self.config.docbooksgml_dblatex
inf = self.source.filename
if not os.path.exists(inf):
return False
outf = self.output.name_pdf
cmd = [dblatex, '-F', 'sgml', '-t', 'pdf', '-o', outf, inf]
logger.debug("%s creating PDF %s (%s).", stem, outf, exe)
result = execute(cmd, logdir=self.output.logdir)
if result != 0:
return False
logger.info("%s created PDF %s (%s).", stem, outf, exe)
return os.path.isfile(outf)
def create_txt(self):
stem = self.source.stem
exe = html2text = self.config.docbooksgml_html2text
inf = self.output.name_htmls
if not os.path.exists(inf):
return False
outf = self.output.name_txt
cmd = [html2text, '-style', 'pretty', '-nobs', inf]
logger.debug("%s creating TXT %s (%s).", stem, outf, exe)
with open(outf, 'wx') as stdout:
result = execute(cmd, logdir=self.output.logdir, stdout=stdout)
if result != 0:
return False
logger.info("%s created TXT %s.", stem, outf)
return os.path.isfile(outf)
#
# -- end of file

View File

@ -32,101 +32,54 @@ class Linuxdoc(BaseDoctype, SignatureChecker):
'linuxdoc_htmldoc': isexecutable,
}
buildorder = ['create_htmls',
'create_pdf',
'create_txt',
'create_html',
'create_indexhtml',
]
buildorder = ['buildall']
buildscript = '''#! /bin/bash
#
# -- generate LDP outputs from DocBook XML 4.x
def create_txt(self):
exe = self.config.linuxdoc_html2text
inf = self.output.name_htmls
assert os.path.exists(inf)
outf = self.output.name_txt
stem = self.source.stem
logdir = self.output.logdir
cmd = [exe, '-style', 'pretty', '-nobs', inf]
logger.debug("%s creating TXT %s.", stem, outf)
with open(outf, 'wx') as stdout:
result = execute(cmd, logdir=logdir, stdout=stdout)
if result != 0:
return False
logger.info("%s created TXT %s.", stem, outf)
return os.path.isfile(outf)
set -x
set -e
set -o pipefail
def create_pdf(self):
exe = self.config.linuxdoc_htmldoc
inf = self.output.name_htmls
assert os.path.exists(inf)
outf = self.output.name_pdf
stem = self.source.stem
logdir = self.output.logdir
logger.debug("%s creating PDF %s.", stem, outf)
cmd = [exe, '--size', 'universal', '-t', 'pdf', '--firstpage', 'p1',
'--outfile', outf, inf]
result = execute(cmd, logdir=logdir)
if result != 0:
return False
logger.info("%s created PDF %s.", stem, outf)
return os.path.isfile(outf)
cd "{output.dirname}"
def create_html(self):
exe = self.config.linuxdoc_sgml2html
inf = self.source.filename
assert os.path.exists(inf)
outf = self.output.name_html
stem = self.source.stem
logdir = self.output.logdir
logger.debug("%s creating HTML %s, etc.", stem, outf)
cmd = [exe, inf]
result = execute(cmd, logdir=logdir)
if result != 0:
return False
logger.info("%s created HTML %s, etc.", stem, outf)
return os.path.isfile(outf)
# -- implicitly creates {output.name_html}
"{config.linuxdoc_sgml2html}" \\
--split=0 \\
"{source.filename}"
def create_indexhtml(self):
stem = self.source.stem
outf = self.output.name_html
target = os.path.basename(outf)
linkname = self.output.name_indexhtml
symlink = os.path.basename(linkname)
logger.debug("%s creating index.html symlink to %s.", stem, target)
try:
os.symlink(target, symlink)
logger.info("%s created link %s to %s.", stem, linkname, target)
except OSError:
logger.debug("%s failed in creating index.html symlink.", stem)
return os.path.islink(linkname)
# -- .... so, it must be rename to {output.name_htmls}
mv \\
--no-clobber \\
--verbose \\
-- "{output.name_html}" "{output.name_htmls}"
def create_htmls(self):
exe = self.config.linuxdoc_sgml2html
inf = self.source.filename
assert os.path.exists(inf)
outf = self.output.name_html
stem = self.source.stem
logdir = self.output.logdir
logger.debug("%s creating HTMLS %s.", stem, outf)
cmd = [exe, '--split=0', inf]
result = execute(cmd, logdir=logdir)
if result != 0:
return False
return os.path.isfile(outf)
"{config.linuxdoc_html2text}" > "{output.name_txt}" \\
-style pretty \\
-nobs \\
"{output.name_htmls}"
def post_create_htmls(self):
stem = self.source.stem
outf = self.output.name_htmls
source = os.path.basename(self.output.name_html)
target = os.path.basename(outf)
logger.debug("%s renaming HTMLS to %s.", stem, target)
try:
os.rename(source, target)
logger.info("%s created HTMLS %s.", stem, outf)
except OSError:
logger.debug("%s failed renaming HTML single file to %s.",
stem, target)
return os.path.isfile(outf)
"{config.linuxdoc_htmldoc}" \\
--size universal \\
-t pdf \\
--firstpage p1 \\
--outfile "{output.name_pdf}" \\
"{output.name_htmls}"
# -- implicitly creates {output.name_html}
"{config.linuxdoc_sgml2html}" \\
"{source.filename}"
ln \
--symbolic \
--relative \
--verbose \
-- "{output.name_html}" "{output.name_indexhtml}"
# -- end of file'''
def buildall(self):
return self.shellscript(self.buildscript)
#
# -- end of file