Create one unified dbapi.move_slot_ent() method to replace the corresponding binarytr...
authorZac Medico <zmedico@gentoo.org>
Thu, 31 May 2007 07:00:45 +0000 (07:00 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 31 May 2007 07:00:45 +0000 (07:00 -0000)
svn path=/main/trunk/; revision=6688

pym/portage/dbapi/__init__.py
pym/portage/dbapi/bintree.py
pym/portage/dbapi/vartree.py

index fce395b00321a530bb55fd8e48243931811c1c19..ef91d4de1cd553399a2f90b8a99782e4e34fa5d2 100644 (file)
@@ -78,3 +78,21 @@ class dbapi(object):
                                aux_update(cpv, metadata_updates)
                        if onProgress:
                                onProgress(maxval, i+1)
+
+       def move_slot_ent(self, mylist):
+               pkg = mylist[1]
+               origslot = mylist[2]
+               newslot = mylist[3]
+               origmatches = self.match(pkg)
+               moves = 0
+               if not origmatches:
+                       return moves
+               from portage.versions import catsplit
+               for mycpv in origmatches:
+                       slot = self.aux_get(mycpv, ["SLOT"])[0]
+                       if slot != origslot:
+                               continue
+                       moves += 1
+                       mydata = {"SLOT": newslot+"\n"}
+                       self.aux_update(mycpv, mydata)
+               return moves
index 66d89cb0ba764d750cab92b7ed87bbcaca6ea7f5..b8a24e515b6e1121ebc3f581688a398472743145 100644 (file)
@@ -16,7 +16,6 @@ class bindbapi(fakedbapi):
        def __init__(self, mybintree=None, settings=None):
                self.bintree = mybintree
                self.move_ent = mybintree.move_ent
-               self.move_slot_ent = mybintree.move_slot_ent
                self.cpvdict={}
                self.cpdict={}
                if settings is None:
@@ -90,6 +89,10 @@ class bindbapi(fakedbapi):
                        self.bintree.populate()
                return fakedbapi.cpv_all(self)
 
+       def move_slot_ent(self, mylist):
+               if not self.bintree.populated:
+                       self.bintree.populate()
+               return fakedbapi.move_slot_ent(self, mylist)
 
 class binarytree(object):
        "this tree scans for a list of all packages available in PKGDIR"
@@ -112,6 +115,7 @@ class binarytree(object):
                        self.pkgdir = normalize_path(pkgdir)
                        self.dbapi = bindbapi(self, settings=settings)
                        self.update_ents = self.dbapi.update_ents
+                       self.move_slot_ent = self.dbapi.move_slot_ent
                        self.populated = 0
                        self.tree = {}
                        self.remotepkgs = {}
@@ -229,45 +233,6 @@ class binarytree(object):
                        del e
                os.symlink(os.path.join("..", "All", mypkg + ".tbz2"), full_path)
 
-       def move_slot_ent(self, mylist):
-               if not self.populated:
-                       self.populate()
-               pkg = mylist[1]
-               origslot = mylist[2]
-               newslot = mylist[3]
-               
-               if not isvalidatom(pkg):
-                       raise InvalidAtom(pkg)
-               
-               origmatches = self.dbapi.match(pkg)
-               moves = 0
-               if not origmatches:
-                       return moves
-               for mycpv in origmatches:
-                       mycpsplit = catpkgsplit(mycpv)
-                       myoldpkg = mycpv.split("/")[1]
-                       tbz2path = self.getname(mycpv)
-                       if os.path.exists(tbz2path) and not os.access(tbz2path,os.W_OK):
-                               writemsg("!!! Cannot update readonly binary: "+mycpv+"\n",
-                                       noiselevel=-1)
-                               continue
-
-                       #print ">>> Updating data in:",mycpv
-                       mytbz2 = portage.xpak.tbz2(tbz2path)
-                       mydata = mytbz2.get_data()
-
-                       slot = mydata["SLOT"]
-                       if (not slot):
-                               continue
-
-                       if (slot[0] != origslot):
-                               continue
-
-                       moves += 1
-                       mydata["SLOT"] = newslot+"\n"
-                       mytbz2.recompose_mem(portage.xpak.xpak_mem(mydata))
-               return moves
-
        def prevent_collision(self, cpv):
                """Make sure that the file location ${PKGDIR}/All/${PF}.tbz2 is safe to
                use for a given cpv.  If a collision will occur with an existing
index 2283b5a31ff9bd22fe0f4aead9bc64c2664111a7..23676c91b7d945688010a3f595bda49959fad26c 100644 (file)
@@ -316,34 +316,6 @@ class vardbapi(dbapi):
                        fixdbentries([mylist], newpath)
                return moves
 
-       def move_slot_ent(self, mylist):
-               pkg = mylist[1]
-               origslot = mylist[2]
-               newslot = mylist[3]
-
-               if not isvalidatom(pkg):
-                       raise InvalidAtom(pkg)
-
-               origmatches = self.match(pkg, use_cache=0)
-               moves = 0
-               if not origmatches:
-                       return moves
-               for mycpv in origmatches:
-                       origpath = self.getpath(mycpv)
-                       if not os.path.exists(origpath):
-                               continue
-
-                       slot = grabfile(os.path.join(origpath, "SLOT"));
-                       if (not slot):
-                               continue
-
-                       if (slot[0] != origslot):
-                               continue
-
-                       moves += 1
-                       write_atomic(os.path.join(origpath, "SLOT"), newslot+"\n")
-               return moves
-
        def cp_list(self, mycp, use_cache=1):
                mysplit=catsplit(mycp)
                if mysplit[0] == '*':