Пример #1
0
 def _is_cpv(self, cat, pn, filename):
     if not filename.endswith(".ebuild"):
         return None
     pf = filename[:-7]
     ps = portage.versions._pkgsplit(pf)
     cpv = f"{cat}/{pf}"
     if not ps:
         raise PortagePackageException(_(f"Invalid package name: '{cpv}'"))
     if ps[0] != pn:
         raise PortagePackageException(
             _(f"Package name does not match directory name: '{cpv}'"))
     return cpv
Пример #2
0
 def _is_cpv(self, cat, pn, filename):
     if not filename.endswith(".ebuild"):
         return None
     pf = filename[:-7]
     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
Пример #3
0
    def create(self,
               checkExisting=False,
               assumeDistHashesSometimes=False,
               assumeDistHashesAlways=False,
               requiredDistfiles=[]):
        """ Recreate this Manifest from scratch.  This will not use any
		existing checksums unless assumeDistHashesSometimes or
		assumeDistHashesAlways is true (assumeDistHashesSometimes will only
		cause DIST checksums to be reused if the file doesn't exist in
		DISTDIR).  The requiredDistfiles parameter specifies a list of
		distfiles to raise a FileNotFound exception for (if no file or existing
		checksums are available), and defaults to all distfiles when not
		specified."""
        if checkExisting:
            self.checkAllHashes()
        if assumeDistHashesSometimes or assumeDistHashesAlways:
            distfilehashes = self.fhashdict["DIST"]
        else:
            distfilehashes = {}
        self.__init__(self.pkgdir,
                      self.distdir,
                      fetchlist_dict=self.fetchlist_dict,
                      from_scratch=True,
                      manifest1_compat=False)
        cpvlist = []
        pn = os.path.basename(self.pkgdir.rstrip(os.path.sep))
        cat = self._pkgdir_category()

        pkgdir = self.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).
            requiredDistfiles = set()
        elif len(requiredDistfiles) == 0:
            # repoman passes in an empty list, which implies that all distfiles
            # are required.
            requiredDistfiles = distlist.copy()
        required_hash_types = set()
        required_hash_types.add("size")
        required_hash_types.add(portage.const.MANIFEST2_REQUIRED_HASH)
        for f in distlist:
            fname = os.path.join(self.distdir, f)
            mystat = None
            try:
                mystat = os.stat(fname)
            except OSError:
                pass
            if f in distfilehashes and \
             not required_hash_types.difference(distfilehashes[f]) and \
             ((assumeDistHashesSometimes and mystat is None) or \
             (assumeDistHashesAlways and mystat is None) or \
             (assumeDistHashesAlways and mystat is not None and \
             len(distfilehashes[f]) == len(self.hashes) and \
             distfilehashes[f]["size"] == mystat.st_size)):
                self.fhashdict["DIST"][f] = distfilehashes[f]
            else:
                try:
                    self.fhashdict["DIST"][f] = perform_multiple_checksums(
                        fname, self.hashes)
                except FileNotFound:
                    if f in requiredDistfiles:
                        raise