Add repository-wide updates support to emaint.
authorMichał Górny <gentoo@mgorny.alt.pl>
Thu, 8 Jul 2010 10:40:45 +0000 (12:40 +0200)
committerZac Medico <zmedico@gentoo.org>
Tue, 27 Jul 2010 23:13:16 +0000 (16:13 -0700)
bin/emaint

index 89373a13fe8e3d53a1183d0dcda2db8abe77b6a4..fb712db8b8e1b5294ac06d5330fb212a5a78b339 100755 (executable)
@@ -226,48 +226,56 @@ class BinhostHandler(object):
 
 class MoveHandler(object):
 
-       def __init__(self, tree):
+       def __init__(self, tree, porttree):
                self._tree = tree
-               self._portdir = tree.settings["PORTDIR"]
+               self._portdb = porttree.dbapi
                self._update_keys = ["DEPEND", "RDEPEND", "PDEPEND", "PROVIDE"]
 
-       def _grab_global_updates(self, portdir):
+       def _grab_global_updates(self):
                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 = []
+               retupdates = {}
                errors = []
-               for mykey, mystat, mycontent in rawupdates:
-                       commands, errors = parse_updates(mycontent)
-                       upd_commands.extend(commands)
-                       errors.extend(errors)
-               return upd_commands, errors
+
+               for repo_name in self._portdb.getRepositories():
+                       repo = self._portdb.getRepositoryPath(repo_name)
+                       updpath = os.path.join(repo, "profiles", "updates")
+                       try:
+                               rawupdates = grab_updates(updpath)
+                       except portage.exception.DirectoryNotFound:
+                               rawupdates = []
+                       upd_commands = []
+                       for mykey, mystat, mycontent in rawupdates:
+                               commands, errors = parse_updates(mycontent)
+                               upd_commands.extend(commands)
+                               errors.extend(errors)
+                       retupdates[repo_name] = upd_commands
+
+               return retupdates, errors
 
        def check(self, onProgress=None):
-               updates, errors = self._grab_global_updates(self._portdir)
+               allupdates, errors = self._grab_global_updates()
                # 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)
+               for repo, updates in allupdates.items():
+                       for i, update_cmd in enumerate(updates):
+                               if update_cmd[0] == "move":
+                                       origcp, newcp = update_cmd[1:]
+                                       for cpv in match(origcp):
+                                               if aux_get(cpv, ["repository"])[0] == repo:
+                                                       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, prepo = aux_get(cpv, ["SLOT", "repository"])
+                                               if slot == origslot and prepo == repo:
+                                                       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.
@@ -280,6 +288,11 @@ class MoveHandler(object):
                if onProgress:
                        onProgress(maxval, 0)
                for i, cpv in enumerate(cpv_all):
+                       try:
+                               updates = allupdates[aux_get(cpv, ['repository'])[0]]
+                       except KeyError:
+                               continue
+
                        metadata = dict(zip(update_keys, aux_get(cpv, update_keys)))
                        metadata_updates = update_dbentries(updates, metadata)
                        if metadata_updates:
@@ -289,24 +302,26 @@ class MoveHandler(object):
                return errors
 
        def fix(self, onProgress=None):
-               updates, errors = self._grab_global_updates(self._portdir)
+               allupdates, errors = self._grab_global_updates()
                # 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)
+               for repo, updates in allupdates.items():
+                       for i, update_cmd in enumerate(updates):
+                               if update_cmd[0] == "move":
+                                       move(update_cmd, repo_name=repo)
+                               elif update_cmd[0] == "slotmove":
+                                       slotmove(update_cmd, repo_name=repo)
+                               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.
-               self._tree.dbapi.update_ents(updates, onProgress=onProgress)
+               for repo, updates in allupdates.items():
+                       self._tree.dbapi.update_ents(updates, onProgress=onProgress, repo=repo)
                return errors
 
 class MoveInstalled(MoveHandler):
@@ -318,7 +333,7 @@ class MoveInstalled(MoveHandler):
        name = staticmethod(name)
        def __init__(self):
                myroot = portage.settings["ROOT"]
-               MoveHandler.__init__(self, portage.db[myroot]["vartree"])
+               MoveHandler.__init__(self, portage.db[myroot]["vartree"], portage.db[myroot]["porttree"])
 
 class MoveBinary(MoveHandler):
 
@@ -329,7 +344,7 @@ class MoveBinary(MoveHandler):
        name = staticmethod(name)
        def __init__(self):
                myroot = portage.settings["ROOT"]
-               MoveHandler.__init__(self, portage.db[myroot]["bintree"])
+               MoveHandler.__init__(self, portage.db[myroot]["bintree"], portage.db[myroot]["porttree"])
 
 class VdbKeyHandler(object):
        def name():