mirror of https://github.com/tLDP/python-tldp
massive simplification of generate() method
move hook_build_success() and hook_build_failure() into BaseDoctype; subclasses can always override, if need be
This commit is contained in:
parent
89d8f14231
commit
80d692efba
|
@ -72,7 +72,7 @@ class BaseDoctype(object):
|
||||||
removals = getattr(self, 'removals', None)
|
removals = getattr(self, 'removals', None)
|
||||||
if removals:
|
if removals:
|
||||||
for fn in removals:
|
for fn in removals:
|
||||||
logger.debug("%s cleaning up file %s", stem, fn)
|
logger.debug("%s cleaning up intermediate file %s", stem, fn)
|
||||||
try:
|
try:
|
||||||
os.unlink(fn)
|
os.unlink(fn)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
@ -92,6 +92,12 @@ class BaseDoctype(object):
|
||||||
assert validator(thing)
|
assert validator(thing)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def hook_build_success(self):
|
||||||
|
self.cleanup()
|
||||||
|
|
||||||
|
def hook_build_failure(self):
|
||||||
|
self.cleanup()
|
||||||
|
|
||||||
def shellscript(self, script, preamble=preamble, postamble=postamble):
|
def shellscript(self, script, preamble=preamble, postamble=postamble):
|
||||||
source = self.source
|
source = self.source
|
||||||
output = self.output
|
output = self.output
|
||||||
|
@ -155,41 +161,9 @@ class BaseDoctype(object):
|
||||||
'build_precheck', stem, classname)
|
'build_precheck', stem, classname)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# -- now, we can walk through build targets, and record a vector
|
# -- now, we can try to build everything; this is the BIG WORK!
|
||||||
# of success or failure
|
|
||||||
#
|
#
|
||||||
vector = list()
|
result = self.buildall()
|
||||||
|
|
||||||
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():
|
|
||||||
logger.warning("%s pre_%s failed, skipping to next build",
|
|
||||||
stem, target)
|
|
||||||
break
|
|
||||||
|
|
||||||
vector.append(mainmethod())
|
|
||||||
if not last_command():
|
|
||||||
logger.warning("%s %s failed, skipping to next build",
|
|
||||||
stem, target)
|
|
||||||
break
|
|
||||||
|
|
||||||
if postmethod:
|
|
||||||
vector.append(postmethod())
|
|
||||||
if not last_command():
|
|
||||||
logger.warning("%s post_%s failed, skipping to next build",
|
|
||||||
stem, target)
|
|
||||||
break
|
|
||||||
|
|
||||||
result = all(vector)
|
|
||||||
|
|
||||||
if result:
|
if result:
|
||||||
self.hook_build_success() # -- processor
|
self.hook_build_success() # -- processor
|
||||||
|
|
Loading…
Reference in New Issue