From df75f051dbaf8efa0cd71ab0a5f149cd2aaa561e Mon Sep 17 00:00:00 2001 From: "Martin A. Brown" Date: Tue, 23 Feb 2016 11:56:58 -0800 Subject: [PATCH] generalizing build sequence logic ready for use in first doctype (linuxdoc) --- tldp/doctypes/common.py | 59 ++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/tldp/doctypes/common.py b/tldp/doctypes/common.py index e2be5af..50f8509 100644 --- a/tldp/doctypes/common.py +++ b/tldp/doctypes/common.py @@ -34,24 +34,53 @@ class BaseDoctype(object): assert None not in (self.source, self.output, self.config) def generate(self): - def last(l): - return l[-1] - self.output.prebuild_hook() - os.chdir(self.output.dirname) - command = list() - command.append(self.build_precheck()) - if not last(command): - return False - command.append(self.create_htmls()) - command.append(self.create_pdf()) - command.append(self.create_txt()) - command.append(self.create_html()) + # -- the output directory gets to prepare; must return True + # + if not self.output.hook_prebuild(): + return False - result = all(command) + opwd = os.getcwd() + os.chdir(self.output.dirname) + + # -- the processor gets to prepare; must return True + # + if not self.build_precheck(): + return False + + # -- now, we can walk through build targets, and record a vector + # of success or failure + # + vector = list() + + def last_command(): + return vector[-1] + + for target in self.buildorder: + premethod = getattr(self, 'pre_' + target, None) + mainmethod = getattr(self, target, None) + postmethod = getattr(self, 'post_' + target, None) + assert mainmethod is not None + + if premethod: + vector.append(premethod()) + if not last_command(): + continue + + vector.append(mainmethod()) + if not last_command(): + continue + + if postmethod: + vector.append(postmethod()) + if not last_command(): + continue + + result = all(vector) if result: - self.output.build_success_hook() + self.output.hook_build_success() else: - self.output.build_failure_hook() + self.output.hook_build_failure() + os.chdir(opwd) return result #