mirror of https://github.com/tLDP/python-tldp
generalizing build sequence logic
ready for use in first doctype (linuxdoc)
This commit is contained in:
parent
08df7acbe2
commit
df75f051db
|
@ -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
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue