[yum-git] 2 commits - yum/__init__.py yum/rpmsack.py
James Antill
james at linux.duke.edu
Tue Mar 25 23:49:18 UTC 2008
yum/__init__.py | 58 +++++++++++++++++++++-----------------------------------
yum/rpmsack.py | 26 ++++++++++++++++++++++++-
2 files changed, 47 insertions(+), 37 deletions(-)
New commits:
commit f3c97ab817b19dfd98625fa6255d973b4c24b49e
Author: James Antill <james at and.org>
Date: Tue Mar 25 19:46:52 2008 -0400
Push search data down to rpm too, again roughly 0.3 and 15MB ... plus nicer
diff --git a/yum/__init__.py b/yum/__init__.py
index b6433d7..bf1791a 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -1473,47 +1473,33 @@ class YumBase(depsolve.Depsolve):
for sack in self.pkgSack.sacks.values():
tmpres.extend(sack.searchPrimaryFieldsMultipleStrings(sql_fields, real_crit))
- for (po, count) in tmpres:
- # check the pkg for sanity
- # pop it into the sorted lists
- tmpkeys = set()
- tmpvalues = []
- if count not in sorted_lists: sorted_lists[count] = []
- for s in real_crit_lower:
- for field in fields:
- value = getattr(po, field)
- if value and value.lower().find(s) != -1:
- tmpvalues.append(value)
- tmpkeys.add(rcl2c[s])
-
- if len(tmpvalues) > 0:
- sorted_lists[count].append((po, tmpkeys, tmpvalues))
-
- for po in self.rpmdb:
- tmpkeys = set()
- tmpvalues = []
- criteria_matched = 0
- for s in real_crit_lower:
- matched_s = False
- for field in fields:
- value = getattr(po, field)
- # make sure that string are in unicode
- value = to_unicode(value)
- if value and value.lower().find(s) != -1:
- if not matched_s:
- criteria_matched += 1
- matched_s = True
-
- tmpvalues.append(value)
- tmpkeys.add(rcl2c[s])
+ def results2sorted_lists(tmpres, sorted_lists):
+ for (po, count) in tmpres:
+ # check the pkg for sanity
+ # pop it into the sorted lists
+ tmpkeys = set()
+ tmpvalues = []
+ if count not in sorted_lists: sorted_lists[count] = []
+ for s in real_crit_lower:
+ for field in fields:
+ value = to_unicode(getattr(po, field))
+ if value and value.lower().find(s) != -1:
+ tmpvalues.append(value)
+ tmpkeys.add(rcl2c[s])
- if len(tmpvalues) > 0:
- if criteria_matched not in sorted_lists: sorted_lists[criteria_matched] = []
- sorted_lists[criteria_matched].append((po, tmpkeys, tmpvalues))
+ if len(tmpvalues) > 0:
+ sorted_lists[count].append((po, tmpkeys, tmpvalues))
+ results2sorted_lists(tmpres, sorted_lists)
+ tmpres = self.rpmdb.searchPrimaryFieldsMultipleStrings(fields,
+ real_crit_lower,
+ lowered=True)
# close our rpmdb connection so we can ctrl-c, kthxbai
self.closeRpmDB()
+ results2sorted_lists(tmpres, sorted_lists)
+ del tmpres
+
# By default just sort using package sorting
sort_func = operator.itemgetter(0)
if keys:
diff --git a/yum/rpmsack.py b/yum/rpmsack.py
index d591d16..3a24f2f 100644
--- a/yum/rpmsack.py
+++ b/yum/rpmsack.py
@@ -28,6 +28,8 @@ from packageSack import PackageSackBase
import fnmatch
import re
+from misc import to_unicode
+
class RPMInstalledPackage(YumInstalledPackage):
def __init__(self, rpmhdr, index, rpmdb):
@@ -279,6 +281,28 @@ class RPMDBPackageSack(PackageSackBase):
self._completely_loaded = patterns is None
return self._idx2pkg.values()
+ @staticmethod
+ def _find_search_fields(fields, searchstrings, hdr):
+ count = 0
+ for s in searchstrings:
+ for field in fields:
+ value = to_unicode(hdr[field])
+ if value and value.lower().find(s) != -1:
+ count += 1
+ break
+ return count
+
+ def searchPrimaryFieldsMultipleStrings(self, fields, searchstrings,
+ lowered=False):
+ if not lowered:
+ searchstrings = map(lambda x: x.lower(), searchstrings)
+ ret = []
+ for hdr, idx in self._all_packages():
+ n = self._find_search_fields(fields, searchstrings, hdr)
+ if n > 0:
+ ret.append((self._makePackageObject(hdr, idx), n))
+ return ret
+
def searchNevra(self, name=None, epoch=None, ver=None, rel=None, arch=None):
return self._search(name, epoch, ver, rel, arch)
commit 7ae0b20c166a67b4cfe31975b8a94a4e6f2ed78c
Author: James Antill <james at and.org>
Date: Tue Mar 25 19:47:57 2008 -0400
If we are filtering don't mark everything as loaded
diff --git a/yum/rpmsack.py b/yum/rpmsack.py
index 07b62f5..d591d16 100644
--- a/yum/rpmsack.py
+++ b/yum/rpmsack.py
@@ -276,7 +276,7 @@ class RPMDBPackageSack(PackageSackBase):
for hdr, idx in self._all_packages():
if self._match_repattern(rpats, hdr):
self._makePackageObject(hdr, idx)
- self._completely_loaded = True
+ self._completely_loaded = patterns is None
return self._idx2pkg.values()
def searchNevra(self, name=None, epoch=None, ver=None, rel=None, arch=None):
More information about the Yum-cvs-commits
mailing list