summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-11-26 19:57:04 +0000
committerLennart Poettering <lennart@poettering.net>2005-11-26 19:57:04 +0000
commitce54ebb37035c080c1d2f5f17d88e28d495ecb94 (patch)
tree85d7920143d460f4afa37e44b303f4cefcc9764b
parent94e710bd9730b6e756254ce35162a68c1e70554c (diff)
some code to deal with bz2 files inside tar files
git-svn-id: file:///home/lennart/svn/public/sse/trunk@73 5fbabb74-0606-0410-a5e4-b5cc6a42724e
-rwxr-xr-xfeed/sse_tar.py46
1 files changed, 30 insertions, 16 deletions
diff --git a/feed/sse_tar.py b/feed/sse_tar.py
index b326d97..1b0ff05 100755
--- a/feed/sse_tar.py
+++ b/feed/sse_tar.py
@@ -5,22 +5,38 @@ import sse_feed, sse_db
from sse_config import *
from sse_defs import *
-import tarfile, zipfile, sys, os, time, zlib
+import tarfile, zipfile, sys, os, time, zlib, tempfile
from md5 import new as message_digest
tar_suffixes = [ ".tar.gz", ".tar.bz2", ".tgz", ".tbz2", ".tar" ]
-def uncompress_tar(archive, root, package_id, meta = {}, fo = None, descend = True, subarchive = None):
+def copy_file_to(dst, x):
+
+ if type(dst) is str:
+ o = file(dst, "w")
+ else:
+ o = dst
+
+ while True:
+ data = x.read(SSE_BLOCK_SIZE)
+
+ if len(data) <= 0:
+ break
+
+ o.write(data)
+ o.close()
+
+def uncompress_tar(archive, root, package_id, meta = {}, tmp = None, descend = True, subarchive = None):
global n_depth
n = 0
- if fo is None:
+ if tmp is None:
f = tarfile.open(archive, "r")
print "Processing TAR file %s." % archive
else:
- f = tarfile.open(subarchive, "r", fo)
- print "Processing subarchive TAR file %s." % subarchive
+ f = tarfile.open(tmp, "r")
+ print "Processing temporary TAR file %s." % tmp
while True:
@@ -51,7 +67,14 @@ def uncompress_tar(archive, root, package_id, meta = {}, fo = None, descend = Tr
except:
pass
- n += uncompress_tar(archive, root, package_id, meta, f.extractfile(i), False, i.name)
+ o, tmp_archive = tempfile.mkstemp()
+ copy_file_to(o, f.extractfile(i))
+
+ try:
+ n += uncompress_tar(archive, root, package_id, meta, tmp_archive, False, i.name)
+ finally:
+ unlink(tmp_archive)
+
print "Subarchive ended, continuing with top level archive..."
continue
@@ -63,16 +86,7 @@ def uncompress_tar(archive, root, package_id, meta = {}, fo = None, descend = Tr
except:
pass
- x = f.extractfile(i)
- o = file(dst, "w")
- while True:
- data = x.read(SSE_BLOCK_SIZE)
-
- if len(data) <= 0:
- break
-
- o.write(data)
- o.close()
+ copy_file_to(dst, f.extractfile(i))
os.utime(dst, (i.mtime, i.mtime))