diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2015-10-05 13:59:26 +0300 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2015-12-02 18:50:32 +0100 |
commit | f7cd0f94a8734bc2716f97e6590fd63b2fa60c4d (patch) | |
tree | 0fd2e177279c61d53a1ef993e89ca0ce94086149 /gbp/scripts/common | |
parent | 0f2f346678aaea585ca4f58367f581239712db16 (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')
-rw-r--r-- | gbp/scripts/common/buildpackage.py | 54 |
1 files changed, 33 insertions, 21 deletions
diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py index 71e4daa9..b58f0877 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,63 @@ 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 - the generated archives using tar and compress the result. + Concatenates the archives generated by git-archive into one and compresses + the end 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: + # Redirect through stdout directly to the correct output file in + # order to avoid determining the output filename of the compressor + 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)) |