build() only returns 0 (success) for all builds

before, the build() function lacked the logic to retain, and return that there
was a failure during the building of one of the documents; it now returns
a 1, which is passed directly to sys.exit(), if any single build fails
This commit is contained in:
Martin A. Brown 2016-03-01 22:21:29 -08:00
parent 97181b167a
commit 9cb92dce7c
4 changed files with 30 additions and 6 deletions

View File

@ -10,8 +10,6 @@ python-tldp TODO
* add a manpage
* build should return 0, only if all documents build successfully
* figure out how/if to build the outputs in a separate place
rather than in the real output directory

View File

@ -196,5 +196,22 @@ class TestDriverBuild(TestInventoryBase):
doc = docs.pop(0)
def test_build_one_broken(self):
c = self.config
self.add_new('Frobnitz-DocBook-XML-4-HOWTO', example.ex_docbook4xml)
# -- mangle the content of a valid DocBook XML file
borked = example.ex_docbook4xml.content[:-12]
example.ex_docbook4xml, content=borked)
c.docbook4xml_xslsingle = os.path.join(extras, 'ldp-html.xsl')
c.docbook4xml_xslprint = os.path.join(extras, 'ldp-print.xsl')
c.docbook4xml_xslchunk = os.path.join(extras, 'ldp-html-chunk.xsl')
inv = tldp.inventory.Inventory(c.pubdir, c.sourcedir)
self.assertEquals(2, len(inv.all.keys()))
docs = inv.all.values()
result =, docs)
self.assertEquals(1, result)
# -- end of file

View File

@ -169,10 +169,13 @@ class TestInventoryBase(unittest.TestCase):
assert fname is not None
def add_new(self, stem, ex):
def add_new(self, stem, ex, content=None):
c = self.config
mysource = TestSourceDocSkeleton(c.sourcedir)
mysource.addsourcefile(stem + ex.ext, ex.filename)
if content:
mysource.addsourcefile(stem + ex.ext, content)
mysource.addsourcefile(stem + ex.ext, ex.filename)
def add_orphan(self, stem, ex):
c = self.config

View File

@ -63,6 +63,7 @@ def detail(config, docs, **kwargs):
def build(config, docs, **kwargs):
result = list()
for x, source in enumerate(docs, 1):
if not isinstance(source, tldp.sources.SourceDocument):"%s (%d of %d) skipping, no source for orphan",
@ -79,8 +80,13 @@ def build(config, docs, **kwargs):
runner = source.doctype(source=source, output=output, config=config)"%s (%d of %d) initiating build",
source.stem, x, len(docs))
return 0
if all(result):
return 0
for errcode, source in zip(result, docs):
if not errcode:
logger.error("%s build failed", source.stem)
return 1
# def script(config, docs, inv, **kwargs):