From 27732ff17ad3a88075787b634ebcc0e591f6c677 Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Tue, 15 May 2012 18:13:43 +0300 Subject: buildpackage/git_archive_single: use GitRepository.archive() Use GitRepository.archive() method like git_archive_submodules() does. This makes it possible to call git_archive_single() independent of the callers current working directory. Signed-off-by: Markus Lehtonen With some adjustments (e.g.: comp_opts) Signed-off-by: Tzafrir Cohen --- gbp/scripts/buildpackage.py | 2 +- gbp/scripts/common/buildpackage.py | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index 3b15e1c..3024bf0 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -58,7 +58,7 @@ def git_archive(repo, cp, output_dir, treeish, comp_type, comp_level, with_submo comp_type, comp_level, comp_opts) else: - git_archive_single(treeish, output, prefix, + git_archive_single(repo, treeish, output, prefix, comp_type, comp_level, comp_opts) except (GitRepositoryError, CommandExecFailed): gbp.log.err("Error generating submodules' archives") diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py index d57baa4..be7b346 100644 --- a/gbp/scripts/common/buildpackage.py +++ b/gbp/scripts/common/buildpackage.py @@ -96,20 +96,29 @@ def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level, shutil.rmtree(tempdir) -def git_archive_single(treeish, output, prefix, comp_type, comp_level, comp_opts, format='tar'): +def git_archive_single(repo, treeish, output, prefix, comp_type, comp_level, + comp_opts, format='tar'): """ Create an archive without submodules Exception handling is left to the caller. """ prefix = sanitize_prefix(prefix) - pipe = pipes.Template() - 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)) + with open(output, 'w') as archive_fd: + if comp_type: + # FIXME: assumes comp_opts has a single component + cmd = [comp_type, '--stdout', '-%s' % comp_level] + if comp_opts != '': + cmd.append(comp_opts) + else: + cmd = ['cat'] + + popen = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=archive_fd) + for chunk in repo.archive(format, prefix, None, treeish): + popen.stdin.write(chunk) + popen.stdin.close() + if popen.wait(): + raise GbpError("Error creating %s: compressor cmd failed" % output) def untar_data(outdir, data): -- cgit v1.2.3