pristine-tar: support checking in/out upstream signatures
authorGuido Günther <agx@sigxcpu.org>
Sat, 24 Nov 2018 16:17:10 +0000 (17:17 +0100)
committerGuido Günther <agx@sigxcpu.org>
Sat, 24 Nov 2018 16:17:10 +0000 (17:17 +0100)
gbp/deb/policy.py
gbp/deb/pristinetar.py
gbp/pkg/pristinetar.py
tests/doctests/test_PristineTar.py

index 6664f4ff288ec871febb0ed5fa64b0a0a0482ea5..d05d05cbaa8c0c8223b1517c45ba18ec2645692d 100644 (file)
@@ -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'
index 843e52e96fe166f8c41abe33c645e499fb120121..1b9317d56b29abf32c5c1724b920ab0b1cd1bead 100644 (file)
@@ -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)
index 40d7dd30fd033e39d890a9a7f7855a50eb84489b..76f1d3c854cc254b9da6d8e0f1e92e1c484e1566 100644 (file)
@@ -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"""
index 3616319bbd49175345d10902b29e110d1d111c0f..825ef04289582dade667249d092723e828a7155f 100644 (file)
@@ -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