Support importing zip archives
authorGuido Günther <agx@sigxcpu.org>
Sun, 24 Jul 2011 12:52:12 +0000 (14:52 +0200)
committerGuido Günther <agx@sigxcpu.org>
Mon, 25 Jul 2011 15:12:35 +0000 (17:12 +0200)
This can now be easily extended to support other formats

debian/control
gbp/command_wrappers.py
gbp/deb.py
git-import-orig

index 848ff5e..fcf0377 100644 (file)
@@ -18,7 +18,7 @@ Architecture: all
 Depends: ${python:Depends}, ${shlibs:Depends}, ${misc:Depends}, devscripts (>= 2.10.66~),
  git (>= 1:1.7.0.4-2) | git-core (>= 1:1.5.0.1-1), python-dateutil
 Recommends: pristine-tar (>= 0.5), cowbuilder
-Suggests: python-notify
+Suggests: python-notify, unzip
 Description: Suite to help with Debian packages in Git repositories
  This package contains the following tools:
   * git-import-{dsc,dscs}: import existing Debian source packages into a git
index 64300cf..2f77a7b 100644 (file)
@@ -200,6 +200,16 @@ class DpkgSourceExtract(Command):
         Command.__call__(self, [dsc, output_dir])
 
 
+class UnpackZipArchive(Command):
+    """Wrap zip to Unpack a zip file"""
+    def __init__(self, archive, dir):
+        self.archive = archive
+        self.dir = dir
+
+        Command.__init__(self, 'unzip', [ "-q", archive, '-d', dir ])
+        self.run_error = 'Couldn\'t unpack "%s"' % self.archive
+
+
 class GitCommand(Command):
     "Mother/Father of all git commands"
     def __init__(self, cmd, args=[], **kwargs):
index 846bbbd..bffb62d 100644 (file)
@@ -407,11 +407,31 @@ def unpack_orig(archive, tmpdir, filters):
         unpackArchive = gbpc.UnpackTarArchive(archive, tmpdir, filters)
         unpackArchive()
     except gbpc.CommandExecFailed:
-        print >>sys.stderr, "Unpacking of %s failed" % archive
+        # unpackArchive already printed an error message
         raise GbpError
     return unpackArchive.dir
 
 
+def unpack_upstream_source(archive, tmpdir, filters):
+    """
+    Unpack upstream sources into tmpdir
+
+    @return: Return true if the importet archive is suitable as an upstream
+             tarball
+    @rtype:  boolean
+    """
+    ext = os.path.splitext(archive)[1]
+    if ext in [ ".zip", ".xpi" ]:
+        try:
+            gbpc.UnpackZipArchive(archive, tmpdir)()
+        except gbpc.CommandExecFailed:
+            raise GbpError, "Unpacking of %s failed" % archive
+        return False
+    else:
+        unpack_orig(archive, tmpdir, filters)
+        return True
+
+
 def repack_orig(archive, tmpdir, dest):
     """
     recreate a new .orig.tar.gz from tmpdir (useful when using filter option)
@@ -420,7 +440,7 @@ def repack_orig(archive, tmpdir, dest):
         repackArchive = gbpc.RepackTarArchive(archive, tmpdir, dest)
         repackArchive()
     except gbpc.CommandExecFailed:
-        print >>sys.stderr, "Failed to create %s" % archive
+        # repackArchive already printed an error
         raise GbpError
     return repackArchive.dir
 
index 9433f4b..9798e2b 100755 (executable)
@@ -28,7 +28,7 @@ import tarfile
 import time
 import tempfile
 import gbp.command_wrappers as gbpc
-from gbp.deb import (parse_changelog, unpack_orig, repack_orig,
+from gbp.deb import (parse_changelog, unpack_upstream_source, repack_orig,
                      NoChangelogError, has_epoch, tar_toplevel,
                      guess_upstream_version, do_uscan,
                      parse_changelog_repo, is_valid_packagename,
@@ -327,7 +327,10 @@ def main(argv):
             if options.interactive:
                 version = ask_package_version(guessed_version)
             else:
-                version = guessed_version
+                if guessed_version:
+                    version = guessed_version
+                else:
+                    raise GbpError, "Couldn't determine upstream version. Use '-u<version>' or --interactive"
 
         (clean, out) = repo.is_clean()
         if not clean and not is_empty:
@@ -340,11 +343,16 @@ def main(argv):
         else:
             if not options.fast_import:
                 tmpdir = tempfile.mkdtemp(dir='../')
-                unpack_orig(archive, tmpdir, options.filters)
+                is_orig = unpack_upstream_source(archive, tmpdir, options.filters)
                 gbp.log.debug("Unpacked %s to '%s'" % (archive , tmpdir))
                 orig_dir = tar_toplevel(tmpdir)
 
-                # Don't mess up or repo with git metadata from an upstream tarball
+                # If the upstream archive is not suitable as an upstream
+                # tarball we turn of pristine-tar for now
+                if not is_orig:
+                    options.pristine_tar = False
+
+                # Don't mess up our repo with git metadata from an upstream tarball
                 try:
                     if os.path.isdir(os.path.join(orig_dir, '.git/')):
                         raise GbpError, "The orig tarball contains .git metadata - giving up."
@@ -358,8 +366,8 @@ def main(argv):
                         os.path.basename(archive).replace(".tar", ".gbp.tar")
                         )
                     repack_orig(archive, tmpdir, os.path.basename(orig_dir))
-            pristine_orig = symlink_orig(archive, sourcepackage, version)
-
+            if is_orig:
+                pristine_orig = symlink_orig(archive, sourcepackage, version)
         try:
             upstream_branch = [ options.upstream_branch, 'master' ][is_empty]
             filter_msg = ["", " (filtering out %s)"