[Yum-devel] [PATCH] make sure when we return items we sort the counts of things matched from the tagsdb into the rest of the matches. FIXME added to get rid of the silly sorting list as it appears to only want to make me cry
James Antill
james at fedoraproject.org
Thu Mar 11 23:00:19 UTC 2010
On Thu, 2010-03-11 at 17:47 -0500, Seth Vidal wrote:
> ---
> yum/__init__.py | 37 ++++++++++++++++++++++++++++++++-----
> 1 files changed, 32 insertions(+), 5 deletions(-)
>
> diff --git a/yum/__init__.py b/yum/__init__.py
> index 7de65b1..e43844b 100644
> --- a/yum/__init__.py
> +++ b/yum/__init__.py
> @@ -2144,6 +2144,9 @@ class YumBase(depsolve.Depsolve):
> del tmpres
>
> tmpres = self.searchPackageTags(real_crit_lower)
> +
> + results_by_pkg = {} # pkg=[list_of_tuples_of_values]
> +
> for pkg in tmpres:
> count = 0
> matchkeys = []
> @@ -2152,13 +2155,37 @@ class YumBase(depsolve.Depsolve):
> count += len(taglist)
> matchkeys.append(rcl2c[match])
> tagresults.extend(taglist)
> + if pkg not in results_by_pkg:
> + results_by_pkg[pkg] = []
> + results_by_pkg[pkg].append((matchkeys, tagresults))
Use:
results_by_pkg.setdefault(pkg, []).append((matchkeys, tagresults))
> +
> + # do the ones we already have
> + for item in sorted_lists.values():
> + for pkg, keys, values in item:
> + if pkg not in results_by_pkg:
> + results_by_pkg[pkg] = []
> + results_by_pkg[pkg].append((keys,values))
Dito.
> + # take our existing dict-by-pkg and make the dict-by-count for
> + # this bizarro sorted_lists format
> + # FIXME - stab sorted_lists in the chest at some later date
> + sorted_lists = {}
> + for pkg in results_by_pkg:
I think you want to sort this, no?
> + totkeys = []
> + totvals = []
> + for (keys, values) in results_by_pkg[pkg]:
> + totkeys.extend(keys)
> + totvals.extend(values)
> +
> + totkeys = misc.unique(totkeys)
> + totvals = misc.unique(totvals)
Just use sets
> + count = len(totkeys)
> + if count not in sorted_lists:
> + sorted_lists[count] = []
> + sorted_lists[count].append((pkg, totkeys, totvals))
Dito .setdefault().
...I kind of understand what it does, and it seems right, so err. ACK
after minor fixes :).
More information about the Yum-devel
mailing list