[Pkg-bazaar-commits] ./bzr-builddeb/trunk.old r268: Add support for repacking zip files. Thanks Daniel Hahler.

James Westby jw+debian at jameswestby.net
Wed Dec 10 08:33:02 UTC 2008


------------------------------------------------------------
revno: 268
committer: James Westby <jw+debian at jameswestby.net>
branch nick: trunk
timestamp: Fri 2008-08-29 13:46:07 +0100
message:
  Add support for repacking zip files. Thanks Daniel Hahler.
  
  I'm not convinced that I have the conversion exactly right, but
  zip files seem pretty horrible.
modified:
  __init__.py
  debian/changelog
  repack_tarball.py
  tests/__init__.py
    ------------------------------------------------------------
    revno: 226.8.1
    committer: Daniel Hahler <ubuntu-launchpad at thequod.de>
    branch nick: builddeb
    timestamp: Sat 2008-07-05 02:45:40 +0200
    message:
      Substitute filename (dest_name) in 'target file already exists' error
    modified:
      __init__.py
    ------------------------------------------------------------
    revno: 226.8.2
    committer: Daniel Hahler <ubuntu-launchpad at thequod.de>
    branch nick: builddeb
    timestamp: Sat 2008-07-05 02:46:39 +0200
    message:
      Fix typo in MissingChangelogError text
    modified:
      __init__.py
    ------------------------------------------------------------
    revno: 226.8.3
    committer: Daniel Hahler <ubuntu-launchpad at thequod.de>
    branch nick: builddeb
    timestamp: Sat 2008-07-05 03:24:34 +0200
    message:
      repack_tarball: add support for zip files
    modified:
      repack_tarball.py
    ------------------------------------------------------------
    revno: 226.8.4
    committer: Daniel Hahler <ubuntu-launchpad at thequod.de>
    branch nick: builddeb
    timestamp: Wed 2008-07-09 23:25:36 +0200
    message:
      Use system commands (unzip + tar) for zip repacking, since using zipfile/tarfile is more complex and does not keep file permissions etc.
    modified:
      repack_tarball.py
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2008-08-27 21:18:08 +0000
+++ b/__init__.py	2008-08-29 12:46:07 +0000
@@ -424,19 +424,19 @@
             if tree.changes_from(tree.basis_tree()).has_changed():
                 raise BzrCommandError("There are uncommitted changes in the "
                         "working tree. You must commit before using this "
-                        "command")
+                        "command.")
             config = debuild_config(tree, tree, no_user_config)
             if config.merge:
-                raise BzrCommandError("Merge upstream in merge mode is not yet "
-                        "supported")
+                raise BzrCommandError("Merge upstream in merge mode is not "
+                        "yet supported.")
             if config.native:
-                raise BzrCommandError("Merge upstream in native mode is not yet "
-                        "supported")
+                raise BzrCommandError("Merge upstream in native mode is not "
+                        "yet supported.")
             if config.export_upstream:
                 raise BzrCommandError("Export upstream mode is not yet "
-                        "supported")
+                        "supported.")
             if config.split:
-                raise BzrCommandError("Split mode is not yet supported")
+                raise BzrCommandError("Split mode is not yet supported.")
 
             try:
                 changelog = find_changelog(tree, False)[0]
@@ -447,10 +447,10 @@
                 current_version = None
 
             if package is None:
-                raise BzrCommandError("You did not specify --package, and there "
-                        "is no changelog from which to determine the package "
-                        "name, which is needed to know the name to give the "
-                        ".orig.tar.gz. Please specify --package.")
+                raise BzrCommandError("You did not specify --package, and "
+                        "there is no changelog from which to determine the "
+                        "package name, which is needed to know the name to "
+                        "give the .orig.tar.gz. Please specify --package.")
 
             orig_dir = config.orig_dir or default_orig_dir
             orig_dir = os.path.join(tree.basedir, orig_dir)
@@ -458,10 +458,11 @@
             try:
                 repack_tarball(tarball, dest_name, target_dir=orig_dir)
             except FileExists:
-                raise BzrCommandError("The target file %s already exists, and is either "
-                                      "different to the new upstream tarball, or they "
-                                      "are of different formats. Either delete the target "
-                                      "file, or use it as the argument to import.")
+                raise BzrCommandError("The target file %s already exists, and "
+                        "is either different to the new upstream tarball, or "
+                        "they are of different formats. Either delete the "
+                        "target file, or use it as the argument to import." \
+                        % dest_name)
             tarball_filename = os.path.join(orig_dir, dest_name)
             distribution = distribution.lower()
             distribution_name = lookup_distribution(distribution)

=== modified file 'debian/changelog'
--- a/debian/changelog	2008-08-28 12:41:37 +0000
+++ b/debian/changelog	2008-08-29 12:46:07 +0000
@@ -1,8 +1,6 @@
 bzr-builddeb (2.1) UNRELEASED; urgency=low
 
-  * Fix retrieval of the upstream source from a watch file of the archive.
-    - It would download to the specified tarball directory, but then
-      report it as stored in the compatibility directory.
+  * Support repacking of .zips. Thanks Daniel Hahler.
 
  -- James Westby <james.westby at canonical.com>  Thu, 28 Aug 2008 11:41:35 +0100
 

=== modified file 'repack_tarball.py'
--- a/repack_tarball.py	2007-10-31 21:07:48 +0000
+++ b/repack_tarball.py	2008-08-29 12:46:07 +0000
@@ -20,9 +20,11 @@
 
 import gzip
 import os
+from StringIO import StringIO
 import tarfile
 import bz2
 import sha
+import zipfile
 
 from bzrlib.errors import (
                            FileExists,
@@ -54,12 +56,11 @@
                        will be created if non-existant.
   :type target_dir: string
   :return: None
-  :warning: .zip files are currently unsupported.
   :throws NoSuchFile: if orig_name doesn't exist.
   :throws NotADirectory: if target_dir exists and is not a directory.
   :throws FileExists: if the target filename (after considering target_dir)
                       exists, and is not identical to the source.
-  :throes BzrCommandError: if the source isn't supported for repacking.
+  :throws BzrCommandError: if the source isn't supported for repacking.
   """
   if target_dir is not None:
     if not os.path.exists(target_dir):
@@ -119,9 +120,30 @@
           gz.write(old_tar_content_decompressed)
         finally:
           gz.close()
+      elif orig_name.endswith('.zip') or zipfile.is_zipfile(orig_name):
+        import time
+        zip = zipfile.ZipFile(trans_file, "r")
+        try:
+          tar = tarfile.open(new_name, 'w:gz')
+          try:
+            for info in zip.infolist():
+              tarinfo = tarfile.TarInfo(info.filename)
+              tarinfo.size = info.file_size
+              tarinfo.mtime = time.mktime(info.date_time + (0, 1, -1))
+              if info.filename.endswith("/"):
+                  tarinfo.mode = 0755
+                  tarinfo.type = tarfile.DIRTYPE
+              else:
+                  tarinfo.mode = 0644
+                  tarinfo.type = tarfile.REGTYPE
+              contents = StringIO(zip.read(info.filename))
+              tar.addfile(tarinfo, contents)
+          finally:
+            tar.close()
+        finally:
+          zip.close()
       else:
         raise BzrCommandError('Unsupported format for repack: %s' % orig_name)
-      # TODO: handle zip files.
     finally:
       trans_file.close()
 

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2008-08-27 15:15:19 +0000
+++ b/tests/__init__.py	2008-08-29 12:46:07 +0000
@@ -101,9 +101,6 @@
   def adapt(self, test):
     result = TestSuite()
     for (name, function, source) in tarball_functions:
-      # XXX: Zip files are horrible, but work out how to repack them.
-      if name == '.zip':
-        continue
       new_test = deepcopy(test)
       source = os.path.basename(source)
       new_test.build_tarball = function(source)



More information about the Pkg-bazaar-commits mailing list