diff --git a/lib/Bastion/Packers/TARs.py b/lib/Bastion/Packers/TARs.py index 7ded4ce..473de1b 100644 --- a/lib/Bastion/Packers/TARs.py +++ b/lib/Bastion/Packers/TARs.py @@ -11,6 +11,7 @@ from Bastion.Common import * from Bastion.CARP import ReportException +from Bastion.Chronology import logger = logging.getLogger(__name__) @@ -192,4 +193,17 @@ def unpack(self, halo, root, **kwargs): raise NotImplementedError - +def catalog(tarp): + """ + I answer the catalog of a tar file at the given path, tarp. + The catalog is a list of entries of the form (size, modified, path) + where size is in bytes, modified is the quantim of the file's mod timestamp, and path is a pathlib.Path object + """ + cats = [ ] + with tarfile.open(tarp) as tark: + for info in tark.getmembers(): + sz = info.size + mq = quantim( datetime.datetime.fromtimestamp(info.mtime) ) + pt = pathlib.PurePosixPath(info.name) + cats.append( (sz, mq, pt) ) + return cats