mirror of https://github.com/tLDP/python-tldp
improving cleaning, esp. index.html
This commit is contained in:
parent
cc6caec3a4
commit
68e3b2f0cb
|
@ -10,7 +10,8 @@ from .utils import logger
|
||||||
|
|
||||||
class OutputNamingConvention(object):
|
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):
|
def __init__(self, stem, dirname):
|
||||||
self.stem = stem
|
self.stem = stem
|
||||||
|
@ -32,6 +33,10 @@ class OutputNamingConvention(object):
|
||||||
def name_htmls(self):
|
def name_htmls(self):
|
||||||
return os.path.join(self.dirname, self.stem + '-single.html')
|
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):
|
class OutputDirectory(OutputNamingConvention):
|
||||||
|
|
||||||
|
@ -47,14 +52,16 @@ class OutputDirectory(OutputNamingConvention):
|
||||||
os.mkdir(dirname)
|
os.mkdir(dirname)
|
||||||
super(OutputDirectory, self).__init__(self.stem, self.dirname)
|
super(OutputDirectory, self).__init__(self.stem, self.dirname)
|
||||||
|
|
||||||
def clear(self):
|
def clean(self):
|
||||||
logger.info("%s clearing directory", self.stem, self.dirname)
|
logger.info("%s cleaning directory %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):
|
if os.path.exists(name) or os.path.islink(name):
|
||||||
logger.info("%s removing file %s", self.stem, name)
|
logger.info("%s cleaning directory %s, removing file %s",
|
||||||
|
self.stem, self.dirname, os.path.basename(name))
|
||||||
os.unlink(name)
|
os.unlink(name)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class OutputTree(object):
|
class OutputTree(object):
|
||||||
|
@ -68,7 +75,7 @@ class OutputTree(object):
|
||||||
logger.critical("Directory %s must already exist.", dirname)
|
logger.critical("Directory %s must already exist.", dirname)
|
||||||
raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), dirname)
|
raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), dirname)
|
||||||
self.dirname = dirname
|
self.dirname = dirname
|
||||||
self.docs = list()
|
self.docs = dict()
|
||||||
self.enumerateDocuments()
|
self.enumerateDocuments()
|
||||||
|
|
||||||
def enumerateDocuments(self):
|
def enumerateDocuments(self):
|
||||||
|
@ -77,7 +84,9 @@ class OutputTree(object):
|
||||||
if not os.path.isdir(name):
|
if not os.path.isdir(name):
|
||||||
logger.warning("Skipping non-directory %s (in %s)",
|
logger.warning("Skipping non-directory %s (in %s)",
|
||||||
name, self.dirname)
|
name, self.dirname)
|
||||||
self.docs.append(OutputDirectory(name))
|
o = OutputDirectory(name)
|
||||||
|
assert not self.docs.has_key(o.stem)
|
||||||
|
self.docs[o.stem] = o
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue