improving cleaning, esp. index.html

This commit is contained in:
Martin A. Brown 2016-02-15 21:04:41 -08:00
parent cc6caec3a4
commit 68e3b2f0cb
1 changed files with 16 additions and 7 deletions

View File

@ -10,7 +10,8 @@ from .utils import logger
class OutputNamingConvention(object):
expected = ['name_txt', 'name_pdf', 'name_htmls', 'name_html']
expected = ['name_txt', 'name_pdf', 'name_htmls', 'name_html',
'name_index']
def __init__(self, stem, dirname):
self.stem = stem
@ -32,6 +33,10 @@ class OutputNamingConvention(object):
def name_htmls(self):
return os.path.join(self.dirname, self.stem + '-single.html')
@property
def name_index(self):
return os.path.join(self.dirname, 'index.html')
class OutputDirectory(OutputNamingConvention):
@ -47,14 +52,16 @@ class OutputDirectory(OutputNamingConvention):
os.mkdir(dirname)
super(OutputDirectory, self).__init__(self.stem, self.dirname)
def clear(self):
logger.info("%s clearing directory", self.stem, self.dirname)
def clean(self):
logger.info("%s cleaning directory %s.", self.stem, self.dirname)
for oformat in self.expected:
name = getattr(self, oformat, None)
assert name is not None
if os.path.exists(name):
logger.info("%s removing file %s", self.stem, name)
if os.path.exists(name) or os.path.islink(name):
logger.info("%s cleaning directory %s, removing file %s",
self.stem, self.dirname, os.path.basename(name))
os.unlink(name)
return True
class OutputTree(object):
@ -68,7 +75,7 @@ class OutputTree(object):
logger.critical("Directory %s must already exist.", dirname)
raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), dirname)
self.dirname = dirname
self.docs = list()
self.docs = dict()
self.enumerateDocuments()
def enumerateDocuments(self):
@ -77,7 +84,9 @@ class OutputTree(object):
if not os.path.isdir(name):
logger.warning("Skipping non-directory %s (in %s)",
name, self.dirname)
self.docs.append(OutputDirectory(name))
o = OutputDirectory(name)
assert not self.docs.has_key(o.stem)
self.docs[o.stem] = o
#