aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2018-11-24 17:17:10 +0100
committerGuido Günther <agx@sigxcpu.org>2018-11-24 17:17:10 +0100
commitdacca59e1a968f79253dca901e212e868954fcff (patch)
tree6f7fa2a659f47dcb86d5079519d2187b0cddd12d
parenta55d19f20a301b727874649b2519f9596bc3e084 (diff)
pristine-tar: support checking in/out upstream signatures
-rw-r--r--gbp/deb/policy.py8
-rw-r--r--gbp/deb/pristinetar.py13
-rw-r--r--gbp/pkg/pristinetar.py14
-rw-r--r--tests/doctests/test_PristineTar.py39
4 files changed, 67 insertions, 7 deletions
diff --git a/gbp/deb/policy.py b/gbp/deb/policy.py
index 6664f4f..d05d05c 100644
--- a/gbp/deb/policy.py
+++ b/gbp/deb/policy.py
@@ -96,3 +96,11 @@ class DebianPkgPolicy(PkgPolicy):
if dir:
tarball = os.path.join(dir, tarball)
return tarball
+
+ @staticmethod
+ def build_signature_name(*args, **kwargs):
+ """
+ Given a source package's I{name}, I{version} and I{compression}
+ return the name of the corresponding upstream tarball signature file.
+ """
+ return DebianPkgPolicy.build_tarball_name(*args, **kwargs) + '.asc'
diff --git a/gbp/deb/pristinetar.py b/gbp/deb/pristinetar.py
index 843e52e..1b9317d 100644
--- a/gbp/deb/pristinetar.py
+++ b/gbp/deb/pristinetar.py
@@ -45,7 +45,7 @@ class DebianPristineTar(PristineTar):
return super(DebianPristineTar, self).has_commit(name_regexp)
def checkout(self, package, version, comp_type, output_dir, component=None,
- quiet=False):
+ quiet=False, signature=False):
"""
Checkout the orig tarball for package I{package} of I{version} and
compression type I{comp_type} to I{output_dir}
@@ -59,9 +59,18 @@ class DebianPristineTar(PristineTar):
@param output_dir: the directory to put the tarball into
@type output_dir: C{str}
"""
+ signaturefile = None
name = DebianPkgPolicy.build_tarball_name(package,
version,
comp_type,
output_dir,
component=component)
- super(DebianPristineTar, self).checkout(name, quiet=quiet)
+ if signature:
+ signaturefile = DebianPkgPolicy.build_signature_name(package,
+ version,
+ comp_type,
+ output_dir,
+ component=component)
+ super(DebianPristineTar, self).checkout(name,
+ quiet=quiet,
+ signaturefile=signaturefile)
diff --git a/gbp/pkg/pristinetar.py b/gbp/pkg/pristinetar.py
index 40d7dd3..76f1d3c 100644
--- a/gbp/pkg/pristinetar.py
+++ b/gbp/pkg/pristinetar.py
@@ -83,17 +83,20 @@ class PristineTar(Command):
return commit
return None
- def checkout(self, archive, quiet=False):
+ def checkout(self, archive, quiet=False, signaturefile=None):
"""
Checkout an orig archive from pristine-tar branch
@param archive: the name of the orig archive
@type archive: C{str}
"""
+ args = ['checkout', archive]
self.run_error = 'Pristine-tar couldn\'t checkout "%s": {stderr_or_reason}' % os.path.basename(archive)
- self.__call__(['checkout', archive], quiet=quiet)
+ if signaturefile:
+ args += ['-s', signaturefile]
+ self.__call__(args, quiet=quiet)
- def commit(self, archive, upstream, quiet=False):
+ def commit(self, archive, upstream, quiet=False, signaturefile=None):
"""
Commit an archive I{archive} to the pristine tar branch using upstream
branch ${upstream}.
@@ -103,9 +106,12 @@ class PristineTar(Command):
@param upstream: the upstream branch to diff against
@type upstream: C{str}
"""
+ args = ['commit', archive, upstream]
self.run_error = ("Couldn't commit to '%s' with upstream '%s': {stderr_or_reason}" %
(self.branch, upstream))
- self.__call__(['commit', archive, upstream], quiet=quiet)
+ if signaturefile:
+ args += ['-s', signaturefile]
+ self.__call__(args, quiet=quiet)
def verify(self, archive, quiet=False):
"""Verify an archive's I{archive} checksum using to the pristine tar branch"""
diff --git a/tests/doctests/test_PristineTar.py b/tests/doctests/test_PristineTar.py
index 3616319..825ef04 100644
--- a/tests/doctests/test_PristineTar.py
+++ b/tests/doctests/test_PristineTar.py
@@ -76,7 +76,7 @@ def test_commit_dir():
def test_create_tarball():
"""
- Create a tarball from a git tree
+ Create a tarball from a git tree and add a stub signature
Methods tested:
- L{gbp.deb.git.DebianGitRepository.archive}
@@ -85,6 +85,8 @@ def test_create_tarball():
>>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
>>> repo.archive('tar', 'upstream/', '../upstream_1.0.orig.tar', 'upstream')
>>> gbp.command_wrappers.Command('gzip', [ '-n', '%s/../upstream_1.0.orig.tar' % dirs['repo']])()
+ >>> with open('%s/../upstream_1.0.orig.tar.gz.asc' % dirs['repo'], 'w') as f: f.write("sig")
+ 3
"""
@@ -101,6 +103,20 @@ def test_pristine_tar_commit():
"""
+def test_pristine_tar_commit_with_sig():
+ """
+ Commit the delta to the pristine-tar branch including a signature
+
+ Methods tested:
+ - L{gbp.deb.pristinetar.DebianPristineTar.commit}
+
+ >>> import gbp.deb.git
+ >>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
+ >>> repo.pristine_tar.commit('../upstream_1.0.orig.tar.gz', 'upstream',
+ ... signaturefile='../upstream_1.0.orig.tar.gz.asc')
+ """
+
+
def test_pristine_has_commit():
"""
Find delta on the pristine tar branch
@@ -137,6 +153,27 @@ def test_pristine_tar_checkout():
"""
+def test_pristine_tar_checkout_with_sig():
+ """
+ Checkout a tarball using pristine-tar
+
+ Methods tested:
+ - L{gbp.deb.pristinetar.DebianPristineTar.checkout}
+
+ >>> import gbp.deb.git
+ >>> from gbp.deb.policy import DebianPkgPolicy
+
+ >>> repo = gbp.deb.git.DebianGitRepository(dirs['repo'])
+ >>> sf = os.path.join(repo.path,
+ ... DebianPkgPolicy.build_signature_name('upstream', '1.0', 'gzip', '..'))
+ >>> os.unlink(sf)
+ >>> repo.pristine_tar.checkout('upstream', '1.0', 'gzip', '..',
+ ... signature=True)
+ >>> os.path.exists(sf)
+ True
+ """
+
+
def test_pristine_tar_verify():
"""
Verify a tarball using pristine-tar