add thin manifest support to the Manifest class
authorBrian Harring <ferringb@gmail.com>
Thu, 1 Sep 2011 21:36:45 +0000 (14:36 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 12 Sep 2011 21:23:10 +0000 (14:23 -0700)
'thin' is just distfiles.  This is primarily useful when the ebuild
lives in a vcs- git for example, which already has it's own checksums
to rely on.

pym/portage/manifest.py
pym/portage/package/ebuild/digestcheck.py

index 13efab791c3d7d24b00a6a7b13eb7659e3455d48..ef1a552e8c57b9bacdca0a2ab695a3e616211f46 100644 (file)
@@ -49,6 +49,12 @@ def guessManifestFileType(filename):
        else:
                return "DIST"
 
+def guessThinManifestFileType(filename):
+       type = guessManifestFileType(filename)
+       if type != "DIST":
+               return None
+       return "DIST"
+
 def parseManifest2(mysplit):
        myentry = None
        if len(mysplit) > 4 and mysplit[0] in portage.const.MANIFEST2_IDENTIFIERS:
@@ -93,12 +99,14 @@ class Manifest2Entry(ManifestEntry):
 class Manifest(object):
        parsers = (parseManifest2,)
        def __init__(self, pkgdir, distdir, fetchlist_dict=None,
-               manifest1_compat=False, from_scratch=False):
+               manifest1_compat=False, from_scratch=False, thin=False):
                """ create new Manifest instance for package in pkgdir
                    and add compability entries for old portage versions if manifest1_compat == True.
                    Do not parse Manifest file if from_scratch == True (only for internal use)
                        The fetchlist_dict parameter is required only for generation of
-                       a Manifest (not needed for parsing and checking sums)."""
+                       a Manifest (not needed for parsing and checking sums).
+                       If thin is specified, then the manifest carries only info for
+                       distfiles."""
                self.pkgdir = _unicode_decode(pkgdir).rstrip(os.sep) + os.sep
                self.fhashdict = {}
                self.hashes = set()
@@ -120,7 +128,11 @@ class Manifest(object):
                else:
                        self.fetchlist_dict = {}
                self.distdir = distdir
-               self.guessType = guessManifestFileType
+               self.thin = thin
+               if thin:
+                       self.guessType = guessThinManifestFileType
+               else:
+                       self.guessType = guessManifestFileType
 
        def getFullname(self):
                """ Returns the absolute path to the Manifest file for this instance """
@@ -313,64 +325,20 @@ class Manifest(object):
                        distfilehashes = {}
                self.__init__(self.pkgdir, self.distdir,
                        fetchlist_dict=self.fetchlist_dict, from_scratch=True,
-                       manifest1_compat=False)
-               cpvlist = []
+                       manifest1_compat=False, thin=self.thin)
                pn = os.path.basename(self.pkgdir.rstrip(os.path.sep))
                cat = self._pkgdir_category()
 
                pkgdir = self.pkgdir
+               if self.thin:
+                       cpvlist = self._update_thin_pkgdir(cat, pn, pkgdir)
+               else:
+                       cpvlist = self._update_thick_pkgdir(cat, pn, pkgdir)
 
-               for pkgdir, pkgdir_dirs, pkgdir_files in os.walk(pkgdir):
-                       break
-               for f in pkgdir_files:
-                       try:
-                               f = _unicode_decode(f,
-                                       encoding=_encodings['fs'], errors='strict')
-                       except UnicodeDecodeError:
-                               continue
-                       if f[:1] == ".":
-                               continue
-                       pf = None
-                       if f[-7:] == '.ebuild':
-                               pf = f[:-7]
-                       if pf is not None:
-                               mytype = "EBUILD"
-                               ps = portage.versions._pkgsplit(pf)
-                               cpv = "%s/%s" % (cat, pf)
-                               if not ps:
-                                       raise PortagePackageException(
-                                               _("Invalid package name: '%s'") % cpv)
-                               if ps[0] != pn:
-                                       raise PortagePackageException(
-                                               _("Package name does not "
-                                               "match directory name: '%s'") % cpv)
-                               cpvlist.append(cpv)
-                       elif manifest2MiscfileFilter(f):
-                               mytype = "MISC"
-                       else:
-                               continue
-                       self.fhashdict[mytype][f] = perform_multiple_checksums(self.pkgdir+f, self.hashes)
-               recursive_files = []
-
-               pkgdir = self.pkgdir
-               cut_len = len(os.path.join(pkgdir, "files") + os.sep)
-               for parentdir, dirs, files in os.walk(os.path.join(pkgdir, "files")):
-                       for f in files:
-                               try:
-                                       f = _unicode_decode(f,
-                                               encoding=_encodings['fs'], errors='strict')
-                               except UnicodeDecodeError:
-                                       continue
-                               full_path = os.path.join(parentdir, f)
-                               recursive_files.append(full_path[cut_len:])
-               for f in recursive_files:
-                       if not manifest2AuxfileFilter(f):
-                               continue
-                       self.fhashdict["AUX"][f] = perform_multiple_checksums(
-                               os.path.join(self.pkgdir, "files", f.lstrip(os.sep)), self.hashes)
                distlist = set()
                for cpv in cpvlist:
                        distlist.update(self._getCpvDistfiles(cpv))
+
                if requiredDistfiles is None:
                        # This allows us to force removal of stale digests for the
                        # ebuild --force digest option (no distfiles are required).
@@ -404,6 +372,81 @@ class Manifest(object):
                                        if f in requiredDistfiles:
                                                raise
 
+       def _is_cpv(self, cat, pn, filename):
+               if not filename.endswith(".ebuild"):
+                       return None
+               pf = filename[:-7]
+               if pf is None:
+                       return None
+               ps = portage.versions._pkgsplit(pf)
+               cpv = "%s/%s" % (cat, pf)
+               if not ps:
+                       raise PortagePackageException(
+                               _("Invalid package name: '%s'") % cpv)
+               if ps[0] != pn:
+                       raise PortagePackageException(
+                               _("Package name does not "
+                               "match directory name: '%s'") % cpv)
+               return cpv
+
+       def _update_thin_pkgdir(self, cat, pn, pkgdir):
+               for pkgdir, pkgdir_dirs, pkgdir_files in os.walk(pkgdir):
+                       break
+               cpvlist = []
+               for f in pkgdir_files:
+                       try:
+                               f = _unicode_decode(f,
+                                       encoding=_encodings['fs'], errors='strict')
+                       except UnicodeDecodeError:
+                               continue
+                       if f[:1] == '.':
+                               continue
+                       pf = self._is_cpv(cat, pn, f)
+                       if pf is not None:
+                               cpvlist.append(pf)
+               return cpvlist
+
+       def _update_thick_pkgdir(self, cat, pn, pkgdir):
+               cpvlist = []
+               for pkgdir, pkgdir_dirs, pkgdir_files in os.walk(pkgdir):
+                       break
+               for f in pkgdir_files:
+                       try:
+                               f = _unicode_decode(f,
+                                       encoding=_encodings['fs'], errors='strict')
+                       except UnicodeDecodeError:
+                               continue
+                       if f[:1] == ".":
+                               continue
+                       pf = self._is_cpv(cat, pn, f)
+                       if pf is not None:
+                               mytype = "EBUILD"
+                               cpvlist.append(pf)
+                       elif manifest2MiscfileFilter(f):
+                               mytype = "MISC"
+                       else:
+                               continue
+                       self.fhashdict[mytype][f] = perform_multiple_checksums(self.pkgdir+f, self.hashes)
+               recursive_files = []
+
+               pkgdir = self.pkgdir
+               cut_len = len(os.path.join(pkgdir, "files") + os.sep)
+               for parentdir, dirs, files in os.walk(os.path.join(pkgdir, "files")):
+                       for f in files:
+                               try:
+                                       f = _unicode_decode(f,
+                                               encoding=_encodings['fs'], errors='strict')
+                               except UnicodeDecodeError:
+                                       continue
+                               full_path = os.path.join(parentdir, f)
+                               recursive_files.append(full_path[cut_len:])
+               for f in recursive_files:
+                       if not manifest2AuxfileFilter(f):
+                               continue
+                       self.fhashdict["AUX"][f] = perform_multiple_checksums(
+                               os.path.join(self.pkgdir, "files", f.lstrip(os.sep)), self.hashes)
+               return cpvlist
+
        def _pkgdir_category(self):
                return self.pkgdir.rstrip(os.sep).split(os.sep)[-2]
 
index d18430160176c2f60258487e78cea9219c5bc2d7..466fd059ef3c43c85f97cbb0f1e1ac8f08f144a4 100644 (file)
@@ -92,7 +92,7 @@ def digestcheck(myfiles, mysettings, strict=False, justmanifest=None, mf=None):
                writemsg(_("!!! Got: %s\n") % e.value[2], noiselevel=-1)
                writemsg(_("!!! Expected: %s\n") % e.value[3], noiselevel=-1)
                return 0
-       if allow_missing:
+       if allow_missing or mf.thin:
                # In this case we ignore any missing digests that
                # would otherwise be detected below.
                return 1