Make dbapi.update_ents() take a dict of {repo_name: list}, since it's
authorZac Medico <zmedico@gentoo.org>
Wed, 28 Jul 2010 00:45:27 +0000 (17:45 -0700)
committerZac Medico <zmedico@gentoo.org>
Wed, 28 Jul 2010 00:45:27 +0000 (17:45 -0700)
most efficient to process all repos at once.

bin/emaint
pym/portage/_global_updates.py
pym/portage/dbapi/__init__.py

index 2bd17d9fdbe63ef5f37fe9217ba8fd177d461e61..52990f7dfd4d27e146123ecf25877d36837abd60 100755 (executable)
@@ -323,8 +323,7 @@ class MoveHandler(object):
 
                # Searching for updates in all the metadata is relatively slow, so this
                # is where the progress bar comes out of indeterminate mode.
-               for repo, updates in allupdates.items():
-                       self._tree.dbapi.update_ents(updates, onProgress=onProgress, repo=repo)
+               self._tree.dbapi.update_ents(allupdates, onProgress=onProgress)
                return errors
 
 class MoveInstalled(MoveHandler):
index 214052daf1352a0e4146d4ed6f9e0bc839f2cbdc..85c8d8ef4bb550c4d4bae6bfcb1ab6f743199bf2 100644 (file)
@@ -54,6 +54,8 @@ def _global_updates(trees, prev_mtimes):
        world_list = grabfile(world_file)
        world_modified = False
        world_warnings = set()
+       updpath_map = {}
+       repo_map = {}
 
        for repo_name in portdb.getRepositories():
                repo = portdb.getRepositoryPath(repo_name)
@@ -62,6 +64,10 @@ def _global_updates(trees, prev_mtimes):
                        # as a backwards-compatibility measure, fallback to PORTDIR
                        updpath = os.path.join(portdb.porttree_root, "profiles", "updates")
 
+               if updpath in updpath_map:
+                       repo_map[repo_name] = updpath_map[updpath]
+                       continue
+
                try:
                        if mysettings.get("PORTAGE_CALLER") == "fixpackages":
                                update_data = grab_updates(updpath)
@@ -69,10 +75,11 @@ def _global_updates(trees, prev_mtimes):
                                update_data = grab_updates(updpath, prev_mtimes)
                except DirectoryNotFound:
                        continue
-               myupd = None
+               myupd = []
+               updpath_map[updpath] = myupd
+               repo_map[repo_name] = myupd
                if len(update_data) > 0:
                        do_upgrade_packagesmessage = 0
-                       myupd = []
                        timestamps = {}
                        for mykey, mystat, mycontent in update_data:
                                writemsg_stdout("\n\n")
@@ -96,6 +103,7 @@ def _global_updates(trees, prev_mtimes):
                                                writemsg("%s\n" % msg, noiselevel=-1)
                        retupd.extend(myupd)
 
+       for repo_name, myupd in repo_map.items():
                        def _world_repo_match(atoma, atomb):
                                """
                                Check whether to perform a world change from atoma to atomb.
@@ -151,18 +159,19 @@ def _global_updates(trees, prev_mtimes):
                                for mykey, mtime in timestamps.items():
                                        prev_mtimes[mykey] = mtime
 
+       if repo_map:
                        # We gotta do the brute force updates for these now.
                        if mysettings.get("PORTAGE_CALLER") == "fixpackages" or \
                        "fixpackages" in mysettings.features:
                                def onUpdate(maxval, curval):
                                        if curval > 0:
                                                writemsg_stdout("#")
-                               vardb.update_ents(myupd, onUpdate=onUpdate, repo=repo_name)
+                               vardb.update_ents(repo_map, onUpdate=onUpdate)
                                if bindb:
                                        def onUpdate(maxval, curval):
                                                if curval > 0:
                                                        writemsg_stdout("*")
-                                       bindb.update_ents(myupd, onUpdate=onUpdate, repo=repo_name)
+                                       bindb.update_ents(repo_map, onUpdate=onUpdate)
                        else:
                                do_upgrade_packagesmessage = 1
 
index 88af46ba80277fb76865d78e3fcf29fee9b6d8e1..b6b9175c6a06876febb3772c2e570e55573357a5 100644 (file)
@@ -197,36 +197,43 @@ class dbapi(object):
                else:
                        writemsg("!!! Invalid db entry: %s\n" % mypath, noiselevel=-1)
 
-       def update_ents(self, updates, onProgress=None, onUpdate=None, repo=None):
+       def update_ents(self, updates, onProgress=None, onUpdate=None):
                """
                Update metadata of all packages for package moves.
-               @param updates: A list of move commands
-               @type updates: List
+               @param updates: A list of move commands, or dict of {repo_name: list}
+               @type updates: list or dict
                @param onProgress: A progress callback function
                @type onProgress: a callable that takes 2 integer arguments: maxval and curval
                @param onUpdate: A progress callback function called only
                        for packages that are modified by updates.
                @type onUpdate: a callable that takes 2 integer arguments:
                        maxval and curval
-               @param repo: Name of the repository which packages should be updated
-               @type repo: string
                """
                cpv_all = self.cpv_all()
                cpv_all.sort()
                maxval = len(cpv_all)
                aux_get = self.aux_get
                aux_update = self.aux_update
-               update_keys = ["DEPEND", "RDEPEND", "PDEPEND", "PROVIDE"]
+               meta_keys = ["DEPEND", "RDEPEND", "PDEPEND", "PROVIDE", 'repository']
+               repo_dict = None
+               if isinstance(updates, dict):
+                       repo_dict = updates
                from portage.update import update_dbentries
                if onUpdate:
                        onUpdate(maxval, 0)
                if onProgress:
                        onProgress(maxval, 0)
                for i, cpv in enumerate(cpv_all):
-                       if repo and aux_get(cpv, ['repository'])[0] != repo:
-                               continue
-                       metadata = dict(zip(update_keys, aux_get(cpv, update_keys)))
-                       metadata_updates = update_dbentries(updates, metadata)
+                       metadata = dict(zip(meta_keys, aux_get(cpv, meta_keys)))
+                       repo = metadata.pop('repository')
+                       if repo_dict is None:
+                               updates_list = updates
+                       else:
+                               updates_list = repo_dict.get(repo)
+                               if updates_list is None:
+                                       continue
+
+                       metadata_updates = update_dbentries(updates_list, metadata)
                        if metadata_updates:
                                aux_update(cpv, metadata_updates)
                                if onUpdate: