summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2013-09-12 10:47:35 +0300
committerTzafrir Cohen <tzafrir@debian.org>2015-03-26 14:21:52 +0200
commit0bf0aa721be9a54d70898c0f00ba9c8d5446710f (patch)
treef93b4723b5f8fca4830311bccb6f300487b3b8c6
parent4df52a5e989c28d81cf69e3ad8b27ff35d492046 (diff)
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 <markus.lehtonen@linux.intel.com>
-rw-r--r--gbp/git/repository.py24
-rw-r--r--tests/test_PristineTar.py2
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])()
"""