Remove db and mysettings from Manifest and replace them with a mapping object that...
authorZac Medico <zmedico@gentoo.org>
Mon, 10 Apr 2006 03:37:11 +0000 (03:37 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 10 Apr 2006 03:37:11 +0000 (03:37 -0000)
svn path=/main/trunk/; revision=3111

bin/repoman
pym/portage.py
pym/portage_manifest.py

index ac51660273c1dbfe60fc70672addd54d49d29a5e..d502d858948ed6bf640a98cdde68a82287a05eb2 100755 (executable)
@@ -795,8 +795,9 @@ for x in scanlist:
                                fails["CVS/Entries.IO_error"].append(checkdir+"/files/CVS/Entries")
                        continue
 
-       mf = Manifest(checkdir, db=portage.db["/"]["porttree"].dbapi,
-               mysettings=repoman_settings, repoman_settings["DISTDIR"])
+       mf = Manifest(checkdir,
+               portage.FetchlistDict(checkdir, repoman_settings),
+               repoman_settings["DISTDIR"])
        mydigests=mf.getTypeDigests("DIST")
        myfiles_all = []
 
index 727b99ae5d6710fef8d009f1d46ef09fed10cb88..b4cbf607f2ed62969558b3c48e0663abb9150bb7 100644 (file)
@@ -30,6 +30,7 @@ try:
        import commands
        from time import sleep
        from random import shuffle
+       import UserDict
 except ImportError, e:
        sys.stderr.write("\n\n")
        sys.stderr.write("!!! Failed to complete python imports. These are internal modules for\n")
@@ -2073,7 +2074,7 @@ def digestgen(myarchives,mysettings,db=None,overwrite=1,manifestonly=0):
                db = portagetree().dbapi
 
        global settings
-       mf = Manifest(mysettings["O"], db, mysettings, mysettings["DISTDIR"])
+       mf = Manifest(mysettings["O"], FetchlistDict(mysettings["O"], mysettings), mysettings["DISTDIR"])
        mf.create(assumeDistfileHashes=True)
        for f in myarchives:
                # the whole type evaluation is only for the case that myarchives isn't a 
@@ -2111,7 +2112,7 @@ def digestParseFile(myfilename,mysettings=None,db=None):
        if mysettings is None:
                mysettings = config(clone=settings)
 
-       mf = Manifest(pkgdir, db, mysettings, mysettings["DISTDIR"])
+       mf = Manifest(pkgdir, FetchlistDict(pkgdir, mysettings), mysettings["DISTDIR"])
 
        return mf.getDigests()
 
@@ -2165,7 +2166,7 @@ def digestcheck(myfiles, mysettings, strict=0, justmanifest=0, db=None):
        pkgdir = mysettings["O"]
        if db is None:
                db = portagetree().dbapi
-       mf = Manifest(pkgdir, db, mysettings, mysettings["DISTDIR"])
+       mf = Manifest(pkgdir, FetchlistDict(pkgdir, mysettings), mysettings["DISTDIR"])
        try:
                if strict:
                        print ">>> checking ebuild checksums",
@@ -6342,6 +6343,25 @@ class dblink:
                "Is this a regular package (does it have a CATEGORY file?  A dblink can be virtual *and* regular)"
                return os.path.exists(self.dbdir+"/CATEGORY")
 
+class FetchlistDict(UserDict.DictMixin):
+       def __init__(self, pkgdir, settings):
+               self.pkgdir = pkgdir
+               self.cp = os.sep.join(pkgdir.split(os.sep)[-2:])
+               self.settings = settings
+               self.db = portagetree().dbapi
+               porttree = os.path.dirname(os.path.dirname(pkgdir))
+               porttree_key = os.path.normpath(os.path.realpath(porttree)).strip(os.sep)
+               # This ensures that the fetchlist comes from the correct portage tree.
+               for t in self.db.porttrees:
+                       if os.path.normpath(os.path.realpath(t)).strip(os.sep) != porttree_key:
+                               self.db.porttrees.remove(t)
+       def __getitem__(self, pkg_key):
+               return self.db.getfetchlist(pkg_key, mysettings=self.settings, all=True)[1]
+       def has_key(self, pkg_key):
+               return self.db.cpv_exists(pkg_key)
+       def keys(self):
+               return self.db.cp_list(self.cp)
+
 def cleanup_pkgmerge(mypkg,origdir):
        shutil.rmtree(settings["PORTAGE_TMPDIR"]+"/binpkgs/"+mypkg)
        if os.path.exists(settings["PORTAGE_TMPDIR"]+"/portage/"+mypkg+"/temp/environment"):
index fff9983aabeedd5951ecf787421e046df2561344..df9c3d4a4f934152d04f295d4579a51c38382157 100644 (file)
@@ -26,8 +26,8 @@ def manifest2MiscfileFilter(filename):
        return not (filename in ["CVS", ".svn", "files", "Manifest"] or filename.endswith(".ebuild"))
 
 class Manifest(object):
-       def __init__(self, pkgdir, db, mysettings, distdir, manifest1_compat=True, from_scratch=False):
-               """ create new Manifest instance for package in pkgdir, using db and mysettings for metadata lookups,
+       def __init__(self, pkgdir, fetchlist_dict, distdir, manifest1_compat=True, from_scratch=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) """
                self.pkgdir = pkgdir.rstrip(os.sep) + os.sep
@@ -42,8 +42,7 @@ class Manifest(object):
                if not from_scratch:
                        self._read()
                self.compat = manifest1_compat
-               self.db = db
-               self.mysettings = mysettings
+               self.fetchlist_dict = fetchlist_dict
                self.distdir = distdir
                
        def guessType(self, filename):
@@ -286,7 +285,7 @@ class Manifest(object):
                        distfilehashes = self.fhashdict["DIST"]
                else:
                        distfilehashes = {}
-               self.__init__(self.pkgdir, self.db, self.mysettings, self.distdir, from_scratch=True)
+               self.__init__(self.pkgdir, self.fetchlist_dict, self.distdir, from_scratch=True)
                for pkgdir, pkgdir_dirs, pkgdir_files in os.walk(self.pkgdir):
                        break
                for f in pkgdir_files:
@@ -364,7 +363,7 @@ class Manifest(object):
        
        def _getCpvDistfiles(self, cpv):
                """ Get a list of all DIST files associated to the given cpv """
-               return self.db.getfetchlist(cpv, mysettings=self.mysettings, all=True)[1]
+               return self.fetchlist_dict[cpv]
        
        def updateFileHashes(self, ftype, fname, checkExisting=True, ignoreMissing=True, reuseExisting=False):
                """ Regenerate hashes for the given file """