[yum-cvs] yum/yum __init__.py, 1.286, 1.287 constants.py, 1.12, 1.13 sqlitesack.py, 1.59, 1.60

Seth Vidal skvidal at linux.duke.edu
Fri Feb 23 05:52:17 UTC 2007


Update of /home/groups/yum/cvs/yum/yum
In directory login1.linux.duke.edu:/tmp/cvs-serv32470/yum

Modified Files:
	__init__.py constants.py sqlitesack.py 
Log Message:

Take a hammer to the search function based on suggestions by Patrick
Reynolds. 


Index: __init__.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.286
retrieving revision 1.287
diff -u -r1.286 -r1.287
--- __init__.py	22 Feb 2007 20:46:47 -0000	1.286
+++ __init__.py	23 Feb 2007 05:52:14 -0000	1.287
@@ -1142,25 +1142,46 @@
         """Generator method to lighten memory load for some searches.
            This is the preferred search function to use."""
 
-        for string in criteria:
-            restring = misc.refineSearchPattern(string)
-            try: crit_re = re.compile(restring, flags=re.I)
-            except sre_constants.error, e:
-                raise Errors.MiscError, \
-                 'Search Expression: %s is an invalid Regular Expression.\n' % string
+        # convert the fields
+        # check the criteria for %
+            # maybe convert globs to sql?
+        # get back results, for each of the results run the old query and 
+        # render results
+        sql_fields = []
+        for f in fields:
+            if RPM_TO_SQLITE.has_key(f):
+                sql_fields.append(RPM_TO_SQLITE[f])
+            else:
+                sql_fields.append(f)
 
-            for sack in self.pkgSack, self.rpmdb:
-                for po in sack:
+        for s in criteria:
+            narrowed_list = []
+            if s.find('%') != -1:
+                continue
+            
+            for sack in self.pkgSack.sacks.values():
+                narrowed_list.extend(sack.searchPrimaryFields(sql_fields, s))
+                
+            for po in narrowed_list:
+                for field in fields:
                     tmpvalues = []
-                    for field in fields:
-                        value = getattr(po, field)
-                        if value and crit_re.search(value):
-                            tmpvalues.append(value)
+                    value = getattr(po, field)
+                    if value and value.find(s) != -1:
+                        tmpvalues.append(value)
 
                     if len(tmpvalues) > 0:
                         yield (po, tmpvalues)
-                    
         
+            for po in self.rpmdb:
+                for field in fields:
+                    tmpvalues = []
+                    value = getattr(po, field)
+                    if value and value.find(s) != -1:
+                        tmpvalues.append(value)
+
+                    if len(tmpvalues) > 0:
+                        yield (po, tmpvalues)
+
     def searchPackages(self, fields, criteria, callback=None):
         """Search specified fields for matches to criteria
            optional callback specified to print out results

Index: constants.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/constants.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- constants.py	19 Feb 2007 22:48:39 -0000	1.12
+++ constants.py	23 Feb 2007 05:52:14 -0000	1.13
@@ -77,3 +77,20 @@
 # boolean dict:
 BOOLEAN_STATES = {'1': True, 'yes': True, 'true': True, 'on': True,
                   '0': False, 'no': False, 'false': False, 'off': False}
+
+RPM_TO_SQLITE = { 'packagesize' : 'size_package',
+                 'archivesize' : 'size_archive',
+                 'installedsize' : 'size_installed',
+                 'buildtime' : 'time_build',
+                 'hdrstart' : 'rpm_header_start',
+                 'hdrend' : 'rpm_header_end',
+                 'basepath' : 'location_base',
+                 'relativepath': 'location_href',
+                 'filetime' : 'time_file',
+                 'packager' : 'rpm_packager',
+                 'group' : 'rpm_group',
+                 'buildhost' : 'rpm_buildhost',
+                 'sourcerpm' : 'rpm_sourcerpm',
+                 'vendor' : 'rpm_vendor',
+                 'license' : 'rpm_license'
+                        }

Index: sqlitesack.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/sqlitesack.py,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- sqlitesack.py	21 Feb 2007 16:36:53 -0000	1.59
+++ sqlitesack.py	23 Feb 2007 05:52:14 -0000	1.60
@@ -263,6 +263,28 @@
             result.append((self.pc(rep,pkg)))
         return result     
     
+    def searchPrimaryFields(self, fields, searchstring):
+        """search arbitrary fields from the primarydb for a string"""
+        result = []
+        if len(fields) < 1:
+            return result
+        
+        basestring="select DISTINCT pkgid from packages where %s like '%%%s%%' " % (fields[0], searchstring)
+        
+        for f in fields[1:]:
+            basestring = "%s or %s like '%%%s%%' " % (basestring, f, searchstring)
+        
+        for (rep,cache) in self.primarydb.items():
+            cur = cache.cursor()
+            executeSQL(cur, basestring)
+            for ob in cur.fetchall():
+                if (self.excludes[rep].has_key(ob['pkgId'])):
+                    continue
+                pkg = self.getPackageDetails(ob['pkgId'])
+                result.append((self.pc(rep,pkg)))
+         
+        return result
+        
     def returnObsoletes(self):
         obsoletes = {}
         for (rep,cache) in self.primarydb.items():




More information about the Yum-cvs-commits mailing list