summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2012-05-15 16:37:33 +0300
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>2014-11-14 14:22:00 +0200
commite6cea4d84bc9744f2e720c8277165f2168fe987e (patch)
tree8c0b9a9c1dfacfc2b80eb5987d7d8125fe4b3fb9
parente641994dc5ca3cd05fc869f253b084dd1f612058 (diff)
downloadgit-buildpackage-e6cea4d84bc9744f2e720c8277165f2168fe987e.tar.gz
git-buildpackage-e6cea4d84bc9744f2e720c8277165f2168fe987e.tar.bz2
git-buildpackage-e6cea4d84bc9744f2e720c8277165f2168fe987e.zip
common/buildpackage: support for different archive formats
Adds support for defining the archive format of the output of git_archive_single(), e.g. 'zip'. Defaults to 'tar', as before. Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com> Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r--debian/control2
-rw-r--r--gbp/command_wrappers.py10
-rw-r--r--gbp/scripts/common/buildpackage.py48
3 files changed, 39 insertions, 21 deletions
diff --git a/debian/control b/debian/control
index 58d9a35a..45d28a98 100644
--- a/debian/control
+++ b/debian/control
@@ -45,7 +45,7 @@ Depends: ${python:Depends},
python-dateutil,
python-pkg-resources,
Recommends: pristine-tar (>= 0.5), cowbuilder
-Suggests: python-notify, unzip
+Suggests: python-notify, unzip, zipmerge
Description: Suite to help with Debian packages in Git repositories
This package contains the following tools:
* gbp import-{dsc,dscs}: import existing Debian source packages into a git
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py
index b8bd21f7..f1312e4c 100644
--- a/gbp/command_wrappers.py
+++ b/gbp/command_wrappers.py
@@ -233,6 +233,16 @@ class UnpackZipArchive(Command):
self.run_error = 'Couldn\'t unpack "%s"' % self.archive
+class CatenateZipArchive(Command):
+ """Wrap zipmerge tool to catenate a zip file with the next"""
+ def __init__(self, archive, **kwargs):
+ self.archive = archive
+ Command.__init__(self, 'zipmerge', [archive], **kwargs)
+
+ def __call__(self, target):
+ Command.__call__(self, [target])
+
+
class GitCommand(Command):
"Mother/Father of all git commands"
def __init__(self, cmd, args=[], **kwargs):
diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py
index 0522cd6b..e293c333 100644
--- a/gbp/scripts/common/buildpackage.py
+++ b/gbp/scripts/common/buildpackage.py
@@ -22,7 +22,7 @@ import os, os.path
import pipes
import tempfile
import shutil
-from gbp.command_wrappers import (CatenateTarArchive)
+from gbp.command_wrappers import (CatenateTarArchive, CatenateZipArchive)
from gbp.errors import GbpError
import gbp.log
@@ -50,51 +50,59 @@ def sanitize_prefix(prefix):
return '/'
-def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level, comp_opts):
+def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level,
+ comp_opts, format='tar'):
"""
- Create tar.gz of an archive with submodules
+ Create a source tree archive with submodules.
- since git-archive always writes an end of tarfile trailer we concatenate
+ Since git-archive always writes an end of tarfile trailer we concatenate
the generated archives using tar and compress the result.
Exception handling is left to the caller.
"""
prefix = sanitize_prefix(prefix)
- tarfile = output.rsplit('.', 1)[0]
tempdir = tempfile.mkdtemp()
- submodule_tarfile = os.path.join(tempdir, "submodule.tar")
+ main_archive = os.path.join(tempdir, "main.%s" % format)
+ submodule_archive = os.path.join(tempdir, "submodule.%s" % format)
try:
- # generate main tarfile
- repo.archive(format='tar', prefix=prefix,
- output=tarfile, treeish=treeish)
+ # generate main (tmp) archive
+ repo.archive(format=format, prefix=prefix,
+ output=main_archive, treeish=treeish)
- # generate each submodule's tarfile and append it to the main archive
+ # generate each submodule's arhive and append it to the main archive
for (subdir, commit) in repo.get_submodules(treeish):
tarpath = [subdir, subdir[2:]][subdir.startswith("./")]
gbp.log.debug("Processing submodule %s (%s)" % (subdir, commit[0:8]))
- repo.archive(format='tar', prefix='%s%s/' % (prefix, tarpath),
- output=submodule_tarfile, treeish=commit, cwd=subdir)
- CatenateTarArchive(tarfile)(submodule_tarfile)
+ repo.archive(format=format, prefix='%s%s/' % (prefix, tarpath),
+ output=submodule_archive, treeish=commit, cwd=subdir)
+ if format == 'tar':
+ CatenateTarArchive(main_archive)(submodule_archive)
+ elif format == 'zip':
+ CatenateZipArchive(main_archive)(submodule_archive)
# compress the output
- ret = os.system("%s -%s %s %s" % (comp_type, comp_level, comp_opts, tarfile))
- if ret:
- raise GbpError("Error creating %s: %d" % (output, ret))
+ if comp_type:
+ ret = os.system("%s --stdout -%s %s %s > %s" % (comp_type, comp_level, comp_opts, main_archive, output))
+ if ret:
+ raise GbpError("Error creating %s: %d" % (output, ret))
+ else:
+ shutil.move(main_archive, output)
finally:
shutil.rmtree(tempdir)
-def git_archive_single(treeish, output, prefix, comp_type, comp_level, comp_opts):
+def git_archive_single(treeish, output, prefix, comp_type, comp_level, comp_opts, format='tar'):
"""
- Create tar.gz of an archive without submodules
+ Create an archive without submodules
Exception handling is left to the caller.
"""
prefix = sanitize_prefix(prefix)
pipe = pipes.Template()
- pipe.prepend("git archive --format=tar --prefix=%s %s" % (prefix, treeish), '.-')
- pipe.append('%s -c -%s %s' % (comp_type, comp_level, comp_opts), '--')
+ pipe.prepend("git archive --format=%s --prefix=%s %s" % (format, prefix, treeish), '.-')
+ if comp_type:
+ pipe.append('%s -c -%s %s' % (comp_type, comp_level, comp_opts), '--')
ret = pipe.copy('', output)
if ret:
raise GbpError("Error creating %s: %d" % (output, ret))