diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-05-15 16:37:33 +0300 |
---|---|---|
committer | Tzafrir Cohen <tzafrir@debian.org> | 2015-03-26 14:34:39 +0200 |
commit | 1dc7dd948c08f2f9abfbda1c7c3bb24a024f8905 (patch) | |
tree | a113900f60ab5dab269f0302d12496e56c7b5d1d /gbp/scripts/common/buildpackage.py | |
parent | 90bafc753e7810852565f5edc6ba9d73529aec47 (diff) |
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>
Diffstat (limited to 'gbp/scripts/common/buildpackage.py')
-rw-r--r-- | gbp/scripts/common/buildpackage.py | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py index 5de315f..d57baa4 100644 --- a/gbp/scripts/common/buildpackage.py +++ b/gbp/scripts/common/buildpackage.py @@ -24,7 +24,7 @@ import tempfile import shutil import subprocess -from gbp.command_wrappers import (CatenateTarArchive) +from gbp.command_wrappers import (CatenateTarArchive, CatenateZipArchive) from gbp.git.repository import GitRepository, GitRepositoryError from gbp.errors import GbpError import gbp.log @@ -54,51 +54,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)) |