From 8fc7b6a4a3c745a376ec3fcd63aa8ca796a0b29f Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 28 May 2007 09:31:26 +0000 Subject: Add new emaint targets called "moveinst" and "movebin" for applying package moves from $PORTDIR/profiles/updates/ on installed packages and binary packages. svn path=/main/trunk/; revision=6652 --- bin/emaint | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/emaint b/bin/emaint index 0152a08e1..d1efc0ab8 100755 --- a/bin/emaint +++ b/bin/emaint @@ -163,6 +163,124 @@ class BinhostHandler(object): locks.unlockfile(pkgindex_lock) return None +class MoveHandler(object): + + def __init__(self, tree): + self._tree = tree + self._portdir = tree.settings["PORTDIR"] + self._update_keys = ["DEPEND", "RDEPEND", "PDEPEND", "PROVIDE"] + + def _grab_global_updates(self, portdir): + from portage.update import grab_updates, parse_updates + updpath = os.path.join(portdir, "profiles", "updates") + try: + rawupdates = grab_updates(updpath) + except portage.exception.DirectoryNotFound: + rawupdates = [] + upd_commands = [] + errors = [] + for mykey, mystat, mycontent in rawupdates: + commands, errors = parse_updates(mycontent) + upd_commands.extend(commands) + errors.extend(errors) + return upd_commands, errors + + def check(self, onProgress=None): + updates, errors = self._grab_global_updates(self._portdir) + # Matching packages and moving them is relatively fast, so the + # progress bar is updated in indeterminate mode. + match = self._tree.dbapi.match + aux_get = self._tree.dbapi.aux_get + if onProgress: + onProgress(0, 0) + for i, update_cmd in enumerate(updates): + if update_cmd[0] == "move": + origcp, newcp = update_cmd[1:] + for cpv in match(origcp): + errors.append("'%s' moved to '%s'" % (cpv, newcp)) + elif update_cmd[0] == "slotmove": + pkg, origslot, newslot = update_cmd[1:] + for cpv in match(pkg): + slot = aux_get(cpv, ["SLOT"])[0] + if slot == origslot: + errors.append("'%s' slot moved from '%s' to '%s'" % \ + (cpv, origslot, newslot)) + if onProgress: + onProgress(0, 0) + + # Searching for updates in all the metadata is relatively slow, so this + # is where the progress bar comes out of indeterminate mode. + cpv_all = self._tree.dbapi.cpv_all() + cpv_all.sort() + maxval = len(cpv_all) + aux_update = self._tree.dbapi.aux_update + update_keys = self._update_keys + from itertools import izip + from portage.update import update_dbentries + if onProgress: + onProgress(maxval, 0) + for i, cpv in enumerate(cpv_all): + metadata = dict(izip(update_keys, aux_get(cpv, update_keys))) + metadata_updates = update_dbentries(updates, metadata) + if metadata_updates: + errors.append("'%s' has outdated metadata" % cpv) + if onProgress: + onProgress(maxval, i+1) + return errors + + def fix(self, onProgress=None): + updates, errors = self._grab_global_updates(self._portdir) + # Matching packages and moving them is relatively fast, so the + # progress bar is updated in indeterminate mode. + move = self._tree.dbapi.move_ent + slotmove = self._tree.dbapi.move_slot_ent + if onProgress: + onProgress(0, 0) + for i, update_cmd in enumerate(updates): + if update_cmd[0] == "move": + move(update_cmd) + elif update_cmd[0] == "slotmove": + slotmove(update_cmd) + if onProgress: + onProgress(0, 0) + + # Searching for updates in all the metadata is relatively slow, so this + # is where the progress bar comes out of indeterminate mode. + cpv_all = self._tree.dbapi.cpv_all() + cpv_all.sort() + maxval = len(cpv_all) + aux_get = self._tree.dbapi.aux_get + aux_update = self._tree.dbapi.aux_update + update_keys = self._update_keys + from itertools import izip + from portage.update import update_dbentries + if onProgress: + onProgress(maxval, 0) + for i, cpv in enumerate(cpv_all): + metadata = dict(izip(update_keys, aux_get(cpv, update_keys))) + metadata_updates = update_dbentries(updates, metadata) + if metadata_updates: + aux_update(cpv, metadata_updates) + if onProgress: + onProgress(maxval, i+1) + return errors + +class MoveInstalled(MoveHandler): + def name(): + return "moveinst" + name = staticmethod(name) + def __init__(self): + myroot = portage.settings["ROOT"] + MoveHandler.__init__(self, portage.db[myroot]["vartree"]) + +class MoveBinary(MoveHandler): + def name(): + return "movebin" + name = staticmethod(name) + def __init__(self): + myroot = portage.settings["ROOT"] + MoveHandler.__init__(self, portage.db[myroot]["bintree"]) + class VdbKeyHandler(object): def name(): return "vdbkeys" @@ -245,7 +363,9 @@ def emaint_main(myargv): # the need for hard coding. modules = { "world" : WorldHandler, - "binhost":BinhostHandler + "binhost":BinhostHandler, + "moveinst":MoveInstalled, + "movebin":MoveBinary } module_names = modules.keys() -- cgit v1.2.3-1-g7c22