[kupfer: 2/27] archiveinside: Detect if archive is modified, sort properly



commit d130a7883c68956ed19014405a5cb68e0ad4f60f
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Fri Jan 22 17:06:37 2010 +0100

    archiveinside: Detect if archive is modified, sort properly

 kupfer/plugin/archiveinside.py |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/kupfer/plugin/archiveinside.py b/kupfer/plugin/archiveinside.py
index abbdfa1..4db3865 100644
--- a/kupfer/plugin/archiveinside.py
+++ b/kupfer/plugin/archiveinside.py
@@ -7,7 +7,6 @@ Issues to resolve:
  * Refuse looking into archives over a certain size
  * Add option to clean up at Kupfer's exit
  * Handle zip, tar.gz and anything we can
- * Detect when the archive has changed.
 """
 __kupfer_name__ = _("Look inside Archives")
 __kupfer_contents__ = ("ArchiveContent", )
@@ -18,7 +17,6 @@ __author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
 import hashlib
 import os
 import tarfile
-import zipfile
 
 from kupfer.objects import Source, FileLeaf
 from kupfer.obj.sources import DirectorySource
@@ -27,6 +25,7 @@ from kupfer import utils
 
 
 class ArchiveContent (Source):
+	_unarchived_files = []
 	def __init__(self, fileleaf):
 		Source.__init__(self, _("Content of %s") % fileleaf)
 		self.path = fileleaf.object
@@ -38,12 +37,14 @@ class ArchiveContent (Source):
 		# always use the same destination for the same file
 		basename = os.path.basename(os.path.normpath(self.path))
 		root, ext = os.path.splitext(basename)
-		fileid = hashlib.sha1(self.path).hexdigest()
+		mtime = os.stat(self.path).st_mtime
+		fileid = hashlib.sha1("%s%s" % (self.path, mtime)).hexdigest()
 		pth = os.path.join("/tmp", "kupfer-%s-%s" % (root, fileid, ))
 		if not os.path.exists(pth):
 			zf = tarfile.TarFile.gzopen(self.path)
 			zf.extractall(path=pth)
-		files = list(DirectorySource(pth).get_items())
+			self._unarchived_files.append(zf)
+		files = list(DirectorySource(pth).get_leaves())
 		if len(files) == 1 and files[0].has_content():
 			return files[0].content_source().get_leaves()
 		return files
@@ -58,7 +59,7 @@ class ArchiveContent (Source):
 	@classmethod
 	def decorate_item(cls, leaf):
 		root, ext = os.path.splitext(leaf.object)
-		if ext.lower() in (".gz", ".zip"):
+		if leaf.object.lower().endswith(".tar.gz"):
 			return cls(leaf)
 		return None
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]