diff options
author | Christian Göttsche <cgzones@googlemail.com> | 2019-12-17 00:10:01 +0100 |
---|---|---|
committer | Christian Göttsche <cgzones@googlemail.com> | 2020-01-21 17:36:53 +0100 |
commit | 2f1c1577e74c36d17aa9f8956e95c42018c71925 (patch) | |
tree | b864c8b9ebe646515d1451a8d360e81a88fd394b /gbp | |
parent | bddd221ee61f8fca61f5a7e17ee47019862c1da7 (diff) |
add option to export tarballs with upstream signature
Add option `--upstream-signatures=[on|auto|off]` to export-orig.
Add option `--git-upstream-signatures=[on|auto|off]` to buildpackage.
Closes: 872864
Diffstat (limited to 'gbp')
-rw-r--r-- | gbp/deb/git.py | 15 | ||||
-rw-r--r-- | gbp/pkg/pristinetar.py | 21 | ||||
-rwxr-xr-x | gbp/scripts/buildpackage.py | 2 | ||||
-rwxr-xr-x | gbp/scripts/export_orig.py | 6 | ||||
-rwxr-xr-x | gbp/scripts/push.py | 2 |
5 files changed, 37 insertions, 9 deletions
diff --git a/gbp/deb/git.py b/gbp/deb/git.py index 3584f6ff..ee939a85 100644 --- a/gbp/deb/git.py +++ b/gbp/deb/git.py @@ -316,13 +316,22 @@ class DebianGitRepository(PkgGitRepository): source.upstream_version, comp)) - def create_upstream_tarball_via_pristine_tar(self, source, output_dir, comp, component=None): + def create_upstream_tarball_via_pristine_tar(self, source, output_dir, comp, upstream_signatures, component=None): output = source.upstream_tarball_name(comp.type, component=component) + gbp.log.debug("upstream signature state: %s" % upstream_signatures) + commit, found_signature = self.get_pristine_tar_commit(source, component) + if not commit and self.has_pristine_tar_branch(): + raise GitRepositoryError("Can not find pristine tar commit for archive '%s'" % output) + if not found_signature and upstream_signatures.is_on(): + raise GitRepositoryError("Can not find requested upstream signature for archive '%s' in pristine tar commit." % output) try: + signature = False if upstream_signatures.is_off() else found_signature self.pristine_tar.checkout(source.name, source.upstream_version, comp.type, output_dir, - component=component, quiet=True) + component=component, quiet=True, signature=signature) except Exception as e: - raise GitRepositoryError("Error creating %s: %s" % (output, e)) + raise GitRepositoryError("Error creating %s%s: %s" % (output, + " with attached signature file" if signature else "", + e)) return True def create_upstream_tarball_via_git_archive(self, source, output_dir, treeish, diff --git a/gbp/pkg/pristinetar.py b/gbp/pkg/pristinetar.py index 5c0892b7..e8534076 100644 --- a/gbp/pkg/pristinetar.py +++ b/gbp/pkg/pristinetar.py @@ -63,25 +63,38 @@ class PristineTar(Command): @param archive_regexp: archive name to look for (regexp wildcards allowed) @type archive_regexp: C{str} """ - return True if self.get_commit(archive_regexp) else False + return True if self.get_commit(archive_regexp)[0] else False + + def _commit_contains_file(self, commit, regexp): + """Does the given commit contain a file with the given regex""" + files = self.repo.get_commit_info(commit)['files'] + cregex = re.compile(regexp) + for _, v in files.items(): + for f in v: + if cregex.match(f.decode()): + return True + return False def get_commit(self, archive_regexp): """ Get the pristine-tar commit of a package matching I{archive_regexp}. + Checks also whether the commit contains a signature file. @param archive_regexp: archive name to look for (regexp wildcards allowed) @type archive_regexp: C{str} + @return: Commit, True if commit contains a signature file + @rtype: C{tuple} of C{str} and C{bool} """ if not self.repo.has_pristine_tar_branch(): - return None + return None, False regex = ('pristine-tar .* %s' % archive_regexp) commits = self.repo.grep_log(regex, self.branch, merges=False) if commits: commit = commits[-1] gbp.log.debug("Found pristine-tar commit at '%s'" % commit) - return commit - return None + return commit, self._commit_contains_file(commit, '%s.asc' % archive_regexp) + return None, False def checkout(self, archive, quiet=False, signaturefile=None): """ diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py index 2aca53df..9b3d67fa 100755 --- a/gbp/scripts/buildpackage.py +++ b/gbp/scripts/buildpackage.py @@ -395,6 +395,8 @@ def build_parser(name, prefix=None): help="Compression type, default is '%(compression)s'") orig_group.add_config_file_option(option_name="compression-level", dest="comp_level", help="Compression level, default is '%(compression-level)s'") + orig_group.add_config_file_option(option_name="upstream-signatures", dest="upstream_signatures", + help="use upstream signatures, default is auto", type='tristate') orig_group.add_config_file_option("component", action="append", metavar='COMPONENT', dest="components") branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch") diff --git a/gbp/scripts/export_orig.py b/gbp/scripts/export_orig.py index 13be4f91..cad8297b 100755 --- a/gbp/scripts/export_orig.py +++ b/gbp/scripts/export_orig.py @@ -113,7 +113,8 @@ def pristine_tar_build_origs(repo, source, output_dir, options): source.upstream_tarball_name(comp.type)))) repo.create_upstream_tarball_via_pristine_tar(source, output_dir, - comp) + comp, + options.upstream_signatures) for component in options.components: gbp.log.info("Creating %s" % os.path.abspath(os.path.join(output_dir, @@ -121,6 +122,7 @@ def pristine_tar_build_origs(repo, source, output_dir, options): repo.create_upstream_tarball_via_pristine_tar(source, output_dir, comp, + options.upstream_signatures, component=component) return True except GitRepositoryError: @@ -303,6 +305,8 @@ def build_parser(name): help="Compression type, default is '%(compression)s'") orig_group.add_config_file_option(option_name="compression-level", dest="comp_level", help="Compression level, default is '%(compression-level)s'") + orig_group.add_config_file_option(option_name="upstream-signatures", dest="upstream_signatures", + help="use upstream signature, default is auto", type='tristate') orig_group.add_config_file_option("component", action="append", metavar='COMPONENT', dest="components") branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch") diff --git a/gbp/scripts/push.py b/gbp/scripts/push.py index c897396e..8233ace8 100755 --- a/gbp/scripts/push.py +++ b/gbp/scripts/push.py @@ -164,7 +164,7 @@ def main(argv): to_push['refs'].append((ref, get_push_src(repo, ref, utag))) if options.pristine_tar: - commit = repo.get_pristine_tar_commit(source) + commit, _ = repo.get_pristine_tar_commit(source) if commit: ref = 'refs/heads/pristine-tar' to_push['refs'].append((ref, get_push_src(repo, ref, commit))) |