mirror of https://github.com/tLDP/python-tldp
include hooks for prebuild and postbuild states
This commit is contained in:
parent
bc810dd36c
commit
fd3b931423
|
@ -31,13 +31,9 @@ class BaseDoctype(object):
|
||||||
self.output = kwargs.get('output', None)
|
self.output = kwargs.get('output', None)
|
||||||
self.platform = kwargs.get('platform', None)
|
self.platform = kwargs.get('platform', None)
|
||||||
assert None not in (self.source, self.output, self.platform)
|
assert None not in (self.source, self.output, self.platform)
|
||||||
self.logdir = os.path.join(self.output.dirname, 'logs')
|
|
||||||
if os.path.exists(self.logdir):
|
|
||||||
logger.warning("Found existing logs directory: %s", self.logdir)
|
|
||||||
else:
|
|
||||||
os.mkdir(self.logdir)
|
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
|
self.output.prebuild_hook()
|
||||||
os.chdir(self.output.dirname)
|
os.chdir(self.output.dirname)
|
||||||
vector = [self.output.clean(),
|
vector = [self.output.clean(),
|
||||||
self.platform_check(),
|
self.platform_check(),
|
||||||
|
@ -47,6 +43,10 @@ class BaseDoctype(object):
|
||||||
self.create_html(),
|
self.create_html(),
|
||||||
]
|
]
|
||||||
result = all(vector)
|
result = all(vector)
|
||||||
|
if result:
|
||||||
|
self.output.build_success_hook()
|
||||||
|
else:
|
||||||
|
self.output.build_failure_hook()
|
||||||
logger.info("%s generation of all documents %s",
|
logger.info("%s generation of all documents %s",
|
||||||
self.source.stem, result)
|
self.source.stem, result)
|
||||||
return all(vector)
|
return all(vector)
|
||||||
|
|
|
@ -4,9 +4,10 @@ from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import errno
|
import errno
|
||||||
|
import shutil
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
from .utils import logger, statfiles
|
from .utils import logger, logdir, statfiles
|
||||||
|
|
||||||
|
|
||||||
class OutputNamingConvention(object):
|
class OutputNamingConvention(object):
|
||||||
|
@ -51,24 +52,37 @@ class OutputDirectory(OutputNamingConvention):
|
||||||
if not os.path.isdir(parent):
|
if not os.path.isdir(parent):
|
||||||
logger.critical("Missing output tree %s.", parent)
|
logger.critical("Missing output tree %s.", parent)
|
||||||
raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), parent)
|
raise IOError(errno.ENOENT, os.strerror(errno.ENOENT), parent)
|
||||||
if not os.path.isdir(self.dirname):
|
|
||||||
logger.info("%s creating output directory %s.", self.stem, dirname)
|
|
||||||
os.mkdir(dirname)
|
|
||||||
self.statinfo = statfiles(self.dirname, relative=self.dirname)
|
self.statinfo = statfiles(self.dirname, relative=self.dirname)
|
||||||
self.status = 'output'
|
self.status = 'output'
|
||||||
|
self.logdir = os.path.join(self.dirname, logdir)
|
||||||
super(OutputDirectory, self).__init__(self.dirname, self.stem)
|
super(OutputDirectory, self).__init__(self.dirname, self.stem)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
logger.info("%s cleaning directory %s.", self.stem, self.dirname)
|
logger.info("%s cleaning dir %s.", self.stem, self.dirname)
|
||||||
for oformat in self.expected:
|
for oformat in self.expected:
|
||||||
name = getattr(self, oformat, None)
|
name = getattr(self, oformat, None)
|
||||||
assert name is not None
|
assert name is not None
|
||||||
if os.path.exists(name) or os.path.islink(name):
|
if os.path.exists(name) or os.path.islink(name):
|
||||||
logger.info("%s cleaning directory %s, removing file %s",
|
logger.info("%s cleaning dir %s, removing file %s",
|
||||||
self.stem, self.dirname, os.path.basename(name))
|
self.stem, self.dirname, os.path.basename(name))
|
||||||
os.unlink(name)
|
os.unlink(name)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def prebuild_hook(self):
|
||||||
|
for d in (self.dirname, self.logdir):
|
||||||
|
if not os.path.isdir(d):
|
||||||
|
logger.info("%s creating dir %s.", self.stem, d)
|
||||||
|
os.mkdir(d)
|
||||||
|
|
||||||
|
def build_failure_hook(self):
|
||||||
|
logger.critical("%s FAILURE, see logs in %s", self.stem, self.logdir)
|
||||||
|
|
||||||
|
def build_success_hook(self):
|
||||||
|
logger.info("%s SUCCESS!", self.stem)
|
||||||
|
logger.debug("%s removing logs %s)", self.stem, self.logdir)
|
||||||
|
if os.path.isdir(self.logdir):
|
||||||
|
shutil.rmtree(logdir)
|
||||||
|
|
||||||
|
|
||||||
class OutputCollection(collections.MutableMapping):
|
class OutputCollection(collections.MutableMapping):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue