Example #1
0
    def create_pristine_tar_commits(self, upstream_tree, sources):
        """
        Create pristine-tar commits for a package with main tarball
        and (optional) component tarballs based on upstream_tree

        @param upstream_tree: the treeish in the git repo to create the commits against
        @param soures: C{list} of tarball as I{UpstreamSource}. First one being the main
                       tarball the other ones additional tarballs.
        """
        components = [t.component for t in sources[1:]]
        main_tree = self.tree_drop_dirs(upstream_tree, components)

        try:
            for source in sources[1:]:
                subtree = self.tree_get_dir(upstream_tree, source.component)
                if not subtree:
                    raise GitRepositoryError(
                        "No tree for '%s' found in '%s' to create "
                        "pristine tar commit from" %
                        (source.component, upstream_tree))
                gbp.log.debug("Creating pristine tar commit '%s' from '%s'" %
                              (source.path, subtree))
                self.pristine_tar.commit(source.path,
                                         subtree,
                                         signaturefile=source.signaturefile,
                                         quiet=True)
            self.pristine_tar.commit(sources[0].path,
                                     main_tree,
                                     signaturefile=sources[0].signaturefile,
                                     quiet=True)
        except CommandExecFailed as e:
            raise GitRepositoryError(str(e))
Example #2
0
 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,
                                    signature=signature)
     except Exception as e:
         raise GitRepositoryError(
             "Error creating %s%s: %s" %
             (output, " with attached signature file" if signature else "",
              e))
     return True
Example #3
0
    def create_pristine_tar_commits(self, upstream_tree, tarball,
                                    component_tarballs):
        """
        Create pristine-tar commits for a package with main tarball
        and (optional) component tarballs based on upstream_tree

        @param tarball: path to main tarball
        @param component_tarballs: C{list} of C{tuple}s of component
            name and path to additional tarball
        @param upstream_tree: the treeish in the git repo to create the commits against
        """
        components = [c for (c, t) in component_tarballs]
        main_tree = self.tree_drop_dirs(upstream_tree, components)

        try:
            for component, name in component_tarballs:
                subtree = self.tree_get_dir(upstream_tree, component)
                if not subtree:
                    raise GitRepositoryError(
                        "No tree for '%s' found in '%s' to create "
                        "pristine tar commit from" %
                        (component, upstream_tree))
                gbp.log.debug("Creating pristine tar commit '%s' from '%s'" %
                              (component, subtree))
                self.pristine_tar.commit(name, subtree, quiet=True)
            self.pristine_tar.commit(tarball, main_tree, quiet=True)
        except CommandExecFailed as e:
            raise GitRepositoryError(str(e))
Example #4
0
    def create_upstream_tarball_via_git_archive(self, source, output_dir, treeish,
                                                comp, with_submodules, component=None):
        """
        Create a compressed orig tarball in output_dir using git archive

        @param source: debian source package
        @type source: L{DebianSource}
        @param output_dir: output directory
        @param type: C{str}
        @param treeish: git treeish
        @type treeish: C{str}
        @param comp: compressor
        @type comp: L{Compressor}
        @param with_submodules: wether to add submodules
        @type with_submodules: C{bool}
        @param component: component to add to tarball name
        @type component: C{str}

        Raises GitRepositoryError in case of an error
        """
        submodules = False
        output = os.path.join(output_dir,
                              source.upstream_tarball_name(comp.type, component=component))
        prefix = "%s-%s" % (source.name, source.upstream_version)

        try:
            if self.has_submodules() and with_submodules:
                submodules = True
                self.update_submodules()
            self.archive_comp(treeish, output, prefix, comp, submodules=submodules)
        except Exception as e:
            raise GitRepositoryError("Error creating %s: %s" % (output, e))
        return True
Example #5
0
 def create_upstream_tarball_via_pristine_tar(self, source, output_dir, comp, component=None):
     output = source.upstream_tarball_name(comp.type, component=component)
     try:
         self.pristine_tar.checkout(source.name, source.upstream_version, comp.type, output_dir,
                                    component=component, quiet=True)
     except Exception as e:
         raise GitRepositoryError("Error creating %s: %s" % (output, e))
     return True
Example #6
0
 def vcs_tag_parent(self, vcs_tag_format, version):
     """If linking to the upstream VCS get the commit id"""
     if not vcs_tag_format:
         return None
     try:
         tag = self.version_to_tag(vcs_tag_format, version)
         return [self.rev_parse("%s^{}" % tag)]
     except GitRepositoryError:
         raise GitRepositoryError("Can't find upstream vcs tag at '%s'" %
                                  tag)
Example #7
0
    def _archive_comp_submodules(self,
                                 treeish,
                                 output,
                                 prefix,
                                 comp,
                                 format='tar'):
        """
        Create a compressed source tree archive with submodules.

        Concatenates the archives generated by git-archive into one and compresses
        the end result.

        Exception handling is left to the caller.
        """
        prefix = self.sanitize_prefix(prefix)
        tempdir = tempfile.mkdtemp()
        main_archive = os.path.join(tempdir, "main.%s" % format)
        submodule_archive = os.path.join(tempdir, "submodule.%s" % format)
        try:
            # generate main (tmp) archive
            self.archive(format=format,
                         prefix=prefix,
                         output=main_archive,
                         treeish=treeish)

            # generate each submodule's archive and append it to the main archive
            for (subdir, commit) in self.get_submodules(treeish):
                tarpath = [subdir, subdir[2:]][subdir.startswith("./")]

                gbp.log.debug("Processing submodule %s (%s)" %
                              (subdir, commit[0:8]))
                self.archive(format=format,
                             prefix='%s%s/' % (prefix, tarpath),
                             output=submodule_archive,
                             treeish=commit,
                             cwd=subdir)
                if format == 'tar':
                    CatenateTarArchive(main_archive)(submodule_archive)
                elif format == 'zip':
                    CatenateZipArchive(main_archive)(submodule_archive)

            # compress the output
            if comp and comp.type:
                # Redirect through stdout directly to the correct output file in
                # order to avoid determining the output filename of the compressor
                ret = os.system("%s %s > %s" %
                                (comp.cmdline(), main_archive, output))
                if ret:
                    raise GitRepositoryError("Error creating %s: %d" %
                                             (output, ret))
            else:
                shutil.move(main_archive, output)
        finally:
            shutil.rmtree(tempdir)
Example #8
0
    def archive_comp(self,
                     treeish,
                     output,
                     prefix,
                     comp,
                     format='tar',
                     submodules=False):
        """Create a compressed source tree archive with the given options"""
        if comp and not comp.is_known():
            raise GitRepositoryError("Unsupported compression type '%s'" %
                                     comp.type)

        if submodules:
            return self._archive_comp_submodules(treeish, output, prefix, comp,
                                                 format)
        else:
            return self._archive_comp_single(treeish, output, prefix, comp,
                                             format)
Example #9
0
    def get_head_author_subject(self):
        out, err, ret = self._git_inout(
            'format-patch', ['-1', '--stdout', '--subject-prefix='],
            capture_stderr=True)
        if ret:
            raise GitRepositoryError("Cannot get head author/subject: %s" %
                                     err.strip())

        output = out.decode('utf-8')
        for line in output.split('\n'):
            line = line.strip()
            if not line:
                # end of headers
                break
            if line.startswith('From:'):
                author = line.replace('From:', '').strip()
            elif line.startswith('Subject:'):
                subject = line.replace('Subject:', '').strip()
        return author, subject
Example #10
0
 def submodule_status(self):
     """
     Determine submodules and their status
     """
     out, err, ret = self._git_inout('submodule', ['status'],
                                     capture_stderr=True)
     if ret:
         raise GitRepositoryError("Cannot get submodule status: %s" %
                                  err.strip())
     submodules = {}
     for line in out.decode().splitlines():
         module = line.strip()
         # Uninitialized
         status = module[0]
         if status == '-':
             sha1, path = module[1:].rsplit(' ', 1)
         else:
             commitpath = module[1:].rsplit(' ', 1)[0]
             sha1, path = commitpath.split(' ', 1)
         submodules[path] = (status, sha1)
     return submodules
Example #11
0
    def _archive_comp_single(self,
                             treeish,
                             output,
                             prefix,
                             comp,
                             format='tar'):
        """
        Create a compressed source tree archive without submodules

        We have this as a special case since it avoids a temporary file
        """
        prefix = self.sanitize_prefix(prefix)
        pipe = pipes.Template()
        pipe.prepend(
            "git archive --format=%s --prefix=%s %s" %
            (format, prefix, treeish), '.-')
        if comp and comp.type:
            pipe.append(comp.cmdline(), '--')
        ret = pipe.copy('', output)
        if ret:
            raise GitRepositoryError("Error creating %s: %d" % (output, ret))