[Pkg-bazaar-commits] r166 ./bzr-builddeb/trunk: Corrects repack from tar.bz2 to tar.gz

Frederic Brin frederic.brin at assonetworx.com
Mon Aug 20 14:54:52 UTC 2007


------------------------------------------------------------
revno: 166
committer: Frederic Brin <frederic.brin at assonetworx.com>
branch nick: bzr-builddeb-co2
timestamp: Mon 2007-08-20 16:54:52 +0200
message:
  Corrects repack from tar.bz2 to tar.gz
  ======================================
  
  Currently the repacking go wrong. Only tar info appeared in the imported files.
modified:
  repack_tarball.py
-------------- next part --------------
=== modified file 'repack_tarball.py'
--- a/repack_tarball.py	2007-07-08 10:06:35 +0000
+++ b/repack_tarball.py	2007-08-20 14:54:52 +0000
@@ -22,6 +22,7 @@
 import os
 import shutil
 import tarfile
+import bz2
 
 from bzrlib.errors import (NoSuchFile,
                            FileExists,
@@ -50,7 +51,7 @@
   :param new_name: the desired name of the tarball
   :type new_name: string
   :keyword target_dir: the directory to consider new_name relative to, and
-                       will be created if non-extant.
+                       will be created if non-existant.
   :type target_dir: string
   :return: None
   :warning: .zip files are currently unsupported.
@@ -78,6 +79,8 @@
   else:
     if isinstance(orig_name, unicode):
       orig_name = orig_name.encode('utf-8')
+    if isinstance(new_name, unicode):
+      new_name = new_name.encode('utf-8')
     base_dir, path = urlutils.split(orig_name)
     transport = get_transport(base_dir)
     trans_file = transport.get(path)
@@ -95,16 +98,13 @@
         finally:
           gz.close()
       elif orig_name.endswith('.tar.bz2'):
-        old_tar = tarfile.open(orig_name, 'r|bz2', trans_file)
+        old_tar_content = trans_file.read()
+        old_tar_content_decompressed = bz2.decompress(old_tar_content)
+        gz = gzip.GzipFile(new_name, 'w')
         try:
-          new_tar = tarfile.open(new_name, 'w|gz')
-          try:
-            for old_member in old_tar.getmembers():
-              new_tar.addfile(old_member)
-          finally:
-            new_tar.close()
+          gz.write(old_tar_content_decompressed)
         finally:
-          old_tar.close()
+          gz.close()
       else:
         raise BzrCommandError('Unsupported format for repack: %s' % orig_name)
       # TODO: handle zip files.



More information about the Pkg-bazaar-commits mailing list