From 0bf0aa721be9a54d70898c0f00ba9c8d5446710f Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Thu, 12 Sep 2013 10:47:35 +0300 Subject: GitRepository.archive: support getting tar data as return value Return tar data as a generator object, if the 'output' option is not defined. Signed-off-by: Markus Lehtonen --- gbp/git/repository.py | 24 +++++++++++++++++------- tests/test_PristineTar.py | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 64757fe..7d0cd32 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -1808,17 +1808,27 @@ class GitRepository(object): @type format: C{str} @param prefix: prefix to prepend to each filename in the archive @type prefix: C{str} - @param output: the name of the archive to create - @type output: C{str} + @param output: the name of the archive to create, empty string or + C{None} gives data as return value + @type output: C{str} or C{None} @param treeish: the treeish to create the archive from @type treeish: C{str} @param kwargs: additional commandline options passed to git-archive + + @return: archive data as a generator object + @rtype: C{None} or C{generator} of C{str} """ - args = [ '--format=%s' % format, '--prefix=%s' % prefix, - '--output=%s' % output, treeish ] - out, ret = self._git_getoutput('archive', args, **kwargs) - if ret: - raise GitRepositoryError("Unable to archive %s" % treeish) + args = GitArgs('--format=%s' % format, '--prefix=%s' % prefix) + args.add_true(output, '--output=%s' % output) + args.add(treeish) + + if output: + out, err, ret = self._git_inout('archive', args.args, **kwargs) + if ret: + raise GitRepositoryError("Unable to archive %s: %s" % (treeish, + err)) + else: + return self._git_inout2('archive', args.args, **kwargs) def collect_garbage(self, auto=False): """ diff --git a/tests/test_PristineTar.py b/tests/test_PristineTar.py index e837ef8..61fb9a9 100644 --- a/tests/test_PristineTar.py +++ b/tests/test_PristineTar.py @@ -72,7 +72,7 @@ def test_create_tarball(): >>> import gbp.deb.git >>> repo = gbp.deb.git.DebianGitRepository(repo_dir) - >>> repo.archive('tar', 'upstream/', '../upstream_1.0.orig.tar', 'upstream') + >>> repo.archive('tar', 'upstream/', '%s/../upstream_1.0.orig.tar' % repo_dir, 'upstream') >>> gbp.command_wrappers.Command('gzip', [ '-n', '%s/../upstream_1.0.orig.tar' % repo_dir])() """ -- cgit v1.2.3