← Back to team overview

launchpad-reviewers team mailing list archive

Re: [Merge] lp:~cjwatson/launchpad/gina-stronger-checksums into lp:launchpad

 

Review: Approve code



Diff comments:

> 
> === modified file 'lib/lp/soyuz/scripts/gina/archive.py'
> --- lib/lp/soyuz/scripts/gina/archive.py	2013-05-22 09:51:08 +0000
> +++ lib/lp/soyuz/scripts/gina/archive.py	2016-03-18 14:22:06 +0000
> @@ -62,53 +62,49 @@
>              raise MangledArchiveError("No archive directory for %s/%s" %
>                                        (distroseries, component))
>  
> -        # Search and get the files with full path
> -        sources_zipped = os.path.join(root, "dists", distroseries,
> -                                      component, "source", "Sources.gz")
> -        if not os.path.exists(sources_zipped):
> -            raise MangledArchiveError("Archive missing Sources.gz at %s"
> -                                      % sources_zipped)
> -
>          # Extract Sources index.
> -        srcfd, sources_tagfile = tempfile.mkstemp()
> -        call("gzip -dc %s > %s" % (sources_zipped, sources_tagfile))
> -        srcfile = os.fdopen(srcfd)
> -
> -        # Holds the opened files and its names.
> -        self.sources_tagfile = sources_tagfile
> -        self.srcfile = srcfile
> +        sources_prefix = os.path.join(
> +            root, "dists", distroseries, component, "source", "Sources")
> +        self.srcfile, self.sources_tagfile = self.openTagFile(sources_prefix)
>  
>          # Detect source-only mode and skip binary index parsing.
>          if source_only:
>              return
>  
> -        # Extract Binaries indexes.
> +        # Extract binary indexes.
>          dist_bin_dir = os.path.join(dist_dir, "binary-%s" % arch)
>          if not os.path.exists(dist_bin_dir):
>              raise NoBinaryArchive
>  
> -        binaries_zipped = os.path.join(dist_bin_dir, "Packages.gz")
> -        if not os.path.exists(binaries_zipped):
> -            raise MangledArchiveError("Archive mising Packages.gz at %s"
> -                                      % binaries_zipped)
> -        di_zipped = os.path.join(root, "dists", distroseries, component,
> -                                 "debian-installer", "binary-%s" % arch,
> -                                 "Packages.gz")
> -        # Extract Binary indexes.
> -        binfd, binaries_tagfile = tempfile.mkstemp()
> -        call("gzip -dc %s > %s" % (binaries_zipped, binaries_tagfile))
> -        binfile = os.fdopen(binfd)
> -
> -        difd, di_tagfile = tempfile.mkstemp()
> -        if os.path.exists(di_zipped):
> -            call("gzip -dc %s > %s" % (di_zipped, di_tagfile))
> -        difile = os.fdopen(difd)
> -
> -        # Holds the opened files and its names.
> -        self.binaries_tagfile = binaries_tagfile
> -        self.binfile = binfile
> -        self.di_tagfile = di_tagfile
> -        self.difile = difile
> +        self.binfile, self.binaries_tagfile = self.openTagFile(
> +            os.path.join(dist_bin_dir, "Packages"))
> +
> +        try:
> +            self.difile, self.di_tagfile = self.openTagFile(
> +                os.path.join(
> +                    root, "dists", distroseries, component,
> +                    "debian-installer", "binary-%s" % arch, "Packages"))
> +        except MangledArchiveError:
> +            # d-i binary indexes may be missing.  Put something empty in
> +            # place so that PackagesMap doesn't need to care.
> +            difd, self.di_tagfile = tempfile.mkstemp()
> +            self.difile = os.fdopen(difd)
> +
> +    def openTagFile(self, prefix):
> +        for suffix in (".xz", ".gz"):
> +            if os.path.exists(prefix + suffix):
> +                # Extract index.
> +                fd, tagfile = tempfile.mkstemp()
> +                if suffix == ".xz":
> +                    call("xz -dc %s > %s" % (prefix + suffix, tagfile))
> +                elif suffix == ".gz":
> +                    call("gzip -dc %s > %s" % (prefix + suffix, tagfile))
> +                else:
> +                    raise AssertionError("Unknown suffix '%s'" % suffix)
> +                return os.fdopen(fd), tagfile
> +        else:
> +            raise MangledArchiveError(
> +                "Archive missing any variant of %s" % prefix)

Should we fix it properly and support uncompressed and bz2 indices at the same time?

>  
>      def cleanup(self):
>          os.unlink(self.sources_tagfile)


-- 
https://code.launchpad.net/~cjwatson/launchpad/gina-stronger-checksums/+merge/289505
Your team Launchpad code reviewers is subscribed to branch lp:launchpad.


References