From 73604962a177d654c4196d6ff7d9dd74f71aea37 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Guido=20G=C3=BCnther?= Date: Sun, 24 Jul 2011 14:52:12 +0200 Subject: [PATCH] Support importing zip archives This can now be easily extended to support other formats --- debian/control | 2 +- gbp/command_wrappers.py | 10 ++++++++++ gbp/deb.py | 24 ++++++++++++++++++++++-- git-import-orig | 20 ++++++++++++++------ 4 files changed, 47 insertions(+), 9 deletions(-) diff --git a/debian/control b/debian/control index 848ff5e..fcf0377 100644 --- a/debian/control +++ b/debian/control @@ -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 diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py index 64300cf..2f77a7b 100644 --- a/gbp/command_wrappers.py +++ b/gbp/command_wrappers.py @@ -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): diff --git a/gbp/deb.py b/gbp/deb.py index 846bbbd..bffb62d 100644 --- a/gbp/deb.py +++ b/gbp/deb.py @@ -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 diff --git a/git-import-orig b/git-import-orig index 9433f4b..9798e2b 100755 --- a/git-import-orig +++ b/git-import-orig @@ -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' 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)" -- 2.7.4