From 7255572e21e1e017266da3888648c172a63870f7 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 31 May 2007 07:00:45 +0000 Subject: Create one unified dbapi.move_slot_ent() method to replace the corresponding binarytree and vardbapi methods. svn path=/main/trunk/; revision=6688 --- pym/portage/dbapi/__init__.py | 18 +++++++++++++++++ pym/portage/dbapi/bintree.py | 45 +++++-------------------------------------- pym/portage/dbapi/vartree.py | 28 --------------------------- 3 files changed, 23 insertions(+), 68 deletions(-) (limited to 'pym') diff --git a/pym/portage/dbapi/__init__.py b/pym/portage/dbapi/__init__.py index fce395b00..ef91d4de1 100644 --- a/pym/portage/dbapi/__init__.py +++ b/pym/portage/dbapi/__init__.py @@ -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 diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index 66d89cb0b..b8a24e515 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -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 diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 2283b5a31..23676c91b 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -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] == '*': -- cgit v1.2.3-1-g7c22