mirror of https://github.com/tLDP/python-tldp
repair mtime comparison logic
repair mtime comparison logic for source and output directories after generalizing the statfiles() function in utils.py add a __repr__ to the Inventory object
This commit is contained in:
parent
46edc205e0
commit
a8284f3afa
|
@ -4,7 +4,7 @@ from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
from .utils import logger, statfiles, max_mtime, mtime_gt
|
from .utils import logger, max_mtime, mtime_gt
|
||||||
|
|
||||||
from .sources import SourceCollection
|
from .sources import SourceCollection
|
||||||
from .outputs import OutputCollection
|
from .outputs import OutputCollection
|
||||||
|
@ -14,6 +14,15 @@ from argparse import Namespace
|
||||||
|
|
||||||
class Inventory(object):
|
class Inventory(object):
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<%s: %d published, %d orphans, %d new, %d stale>' % (
|
||||||
|
self.__class__.__name__,
|
||||||
|
len(self.published),
|
||||||
|
len(self.orphans),
|
||||||
|
len(self.new),
|
||||||
|
len(self.stale),
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self, pubdir, sourcedirs):
|
def __init__(self, pubdir, sourcedirs):
|
||||||
self.outputs = OutputCollection(pubdir)
|
self.outputs = OutputCollection(pubdir)
|
||||||
self.sources = SourceCollection(sourcedirs)
|
self.sources = SourceCollection(sourcedirs)
|
||||||
|
@ -22,6 +31,8 @@ class Inventory(object):
|
||||||
sset = set(s.keys())
|
sset = set(s.keys())
|
||||||
oset = set(o.keys())
|
oset = set(o.keys())
|
||||||
|
|
||||||
|
# -- orphan identification
|
||||||
|
#
|
||||||
self.orphans = OutputCollection()
|
self.orphans = OutputCollection()
|
||||||
for doc in oset.difference(sset):
|
for doc in oset.difference(sset):
|
||||||
self.orphans[doc] = o[doc]
|
self.orphans[doc] = o[doc]
|
||||||
|
@ -30,6 +41,8 @@ class Inventory(object):
|
||||||
logger.info("Identified %d orphaned documents: %r.", len(self.orphans),
|
logger.info("Identified %d orphaned documents: %r.", len(self.orphans),
|
||||||
self.orphans.keys())
|
self.orphans.keys())
|
||||||
|
|
||||||
|
# -- unpublished ('new') identification
|
||||||
|
#
|
||||||
self.new = SourceCollection()
|
self.new = SourceCollection()
|
||||||
for doc in sset.difference(oset):
|
for doc in sset.difference(oset):
|
||||||
self.new[doc] = s[doc]
|
self.new[doc] = s[doc]
|
||||||
|
@ -38,7 +51,7 @@ class Inventory(object):
|
||||||
logger.info("Identified %d new documents: %r.", len(self.new),
|
logger.info("Identified %d new documents: %r.", len(self.new),
|
||||||
self.new.keys())
|
self.new.keys())
|
||||||
|
|
||||||
# -- sources + outputs should be same size now
|
# -- published identification; sources and outputs should be same size
|
||||||
assert len(s) == len(o)
|
assert len(s) == len(o)
|
||||||
for stem, odoc in o.items():
|
for stem, odoc in o.items():
|
||||||
sdoc = s[stem]
|
sdoc = s[stem]
|
||||||
|
@ -48,13 +61,16 @@ class Inventory(object):
|
||||||
self.published = s
|
self.published = s
|
||||||
logger.info("Identified %d published documents.", len(self.published))
|
logger.info("Identified %d published documents.", len(self.published))
|
||||||
|
|
||||||
|
# -- stale identification
|
||||||
|
#
|
||||||
self.stale = SourceCollection()
|
self.stale = SourceCollection()
|
||||||
for stem, sdoc in s.items():
|
for stem, sdoc in s.items():
|
||||||
odoc = sdoc.output
|
odoc = sdoc.output
|
||||||
mtime = max_mtime(statfiles(odoc.dirname, odoc.fileset))
|
mtime = max_mtime(odoc.statinfo)
|
||||||
fset = mtime_gt(mtime, statfiles(sdoc.dirname, sdoc.fileset))
|
fset = mtime_gt(mtime, sdoc.statinfo)
|
||||||
if fset:
|
if fset:
|
||||||
logger.debug("%s stale files %r", stem, fset)
|
for f in fset:
|
||||||
|
logger.info("%s updated source file %s", stem, f)
|
||||||
odoc.status = sdoc.status = 'stale'
|
odoc.status = sdoc.status = 'stale'
|
||||||
self.stale[stem] = sdoc
|
self.stale[stem] = sdoc
|
||||||
logger.info("Identified %d stale documents: %r.", len(self.stale),
|
logger.info("Identified %d stale documents: %r.", len(self.stale),
|
||||||
|
@ -77,7 +93,7 @@ def print_sources(scollection, config=None):
|
||||||
if config.verbose:
|
if config.verbose:
|
||||||
fields = [doc.stem, doc.status, doc.filename, str(doc.doctype),
|
fields = [doc.stem, doc.status, doc.filename, str(doc.doctype),
|
||||||
doc.doctype.formatname]
|
doc.doctype.formatname]
|
||||||
fields.extend(sorted(doc.fileset))
|
fields.append(str(len(doc.statinfo)) + ' files')
|
||||||
print(config.sep.join(fields))
|
print(config.sep.join(fields))
|
||||||
else:
|
else:
|
||||||
print(doc.stem)
|
print(doc.stem)
|
||||||
|
@ -90,6 +106,7 @@ def print_outputs(ocollection, config=None):
|
||||||
doc = ocollection[stem]
|
doc = ocollection[stem]
|
||||||
if config.verbose:
|
if config.verbose:
|
||||||
fields = [doc.stem, doc.status, doc.dirname]
|
fields = [doc.stem, doc.status, doc.dirname]
|
||||||
|
fields.append(str(len(doc.statinfo)) + ' files')
|
||||||
print(config.sep.join(fields))
|
print(config.sep.join(fields))
|
||||||
else:
|
else:
|
||||||
print(doc.stem)
|
print(doc.stem)
|
||||||
|
|
Loading…
Reference in New Issue