[yum-cvs] yum/yum __init__.py,1.188,1.189 sqlitesack.py,1.28,1.29

Seth Vidal skvidal at linux.duke.edu
Tue Feb 28 06:53:06 UTC 2006


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

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

fix for yum provides foocommand not working

this, ultimately, means that yum provides *foocommand* will be VERY SLOW for
dumb reasons.

there needs to be a better solution than this but at least this solution is
functionally correct, albeit slow



Index: __init__.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.188
retrieving revision 1.189
diff -u -r1.188 -r1.189
--- __init__.py	22 Feb 2006 22:07:01 -0000	1.188
+++ __init__.py	28 Feb 2006 06:53:03 -0000	1.189
@@ -1185,25 +1185,28 @@
                 self.doSackFilelistPopulate()
 
         for arg in args:
-            self.log(4,'refining the search expression') 
+            # assume we have to search every package, unless we can refine the search set
+            where = self.pkgSack
+            
+            # this is annoying. If the user doesn't use any glob or regex-like
+            # or regexes then we can use the where 'like' search in sqlite
+            # if they do use globs or regexes then we can't b/c the string
+            # will no longer have much meaning to use it for matches
+            
+            if hasattr(self.pkgSack, 'searchAll'):
+                if not re.match('.*[\*,\[,\],\{,\},\?,\+,\%].*', arg):
+                    self.log(4, 'Using the like search')
+                    where = self.pkgSack.searchAll(arg, query_type='like')
+            
+            self.log(4, 'Searching %d packages' % len(where))
+            self.log(4,'refining the search expression of %s' % arg) 
             restring = self._refineSearchPattern(arg)
+            self.log(4, 'refined search: %s' % restring)
             try: 
                 arg_re = re.compile(restring, flags=re.I)
             except sre_constants.error, e:
                 raise Errors.MiscError, \
                   'Search Expression: %s is an invalid Regular Expression.\n' % arg
-            
-            # assume we have to search every package, unless we can refine the search set
-            where = self.pkgSack
-            # if it is a glob and it's a sqlite sack, use the glob query_type
-            if hasattr(self.pkgSack, 'searchAll'):
-                if arg.find('*') != -1 or arg.find('?') != -1:
-                    self.log(4, 'Using the glob search')
-                    where = self.pkgSack.searchAll(arg, query_type='glob')
-                else:
-                    if arg.find('%') == -1:
-                        self.log(4, 'Using the like search')
-                        where = self.pkgSack.searchAll(arg, query_type='like')
 
             for po in where:
                 self.log(5, 'searching package %s' % po)

Index: sqlitesack.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/sqlitesack.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- sqlitesack.py	12 Jan 2006 06:03:20 -0000	1.28
+++ sqlitesack.py	28 Feb 2006 06:53:03 -0000	1.29
@@ -187,81 +187,51 @@
     # or provide a file containing name 
     def searchAll(self,name, query_type='like'):
     
-        if query_type == 'like':
-            # This should never be called with a name containing a %
-            assert(name.find('%') == -1)
-            result = []
-            quotename = name.replace("'","''")
-            for (rep,cache) in self.primarydb.items():
-                cur = cache.cursor()
-                cur.execute("select DISTINCT packages.pkgId as pkgId from provides,packages where provides.name LIKE '%%%s%%' AND provides.pkgKey = packages.pkgKey" % quotename)
-                for ob in cur.fetchall():
-                    if (self.excludes[rep].has_key(ob['pkgId'])):
-                        continue
-                    pkg = self.getPackageDetails(ob['pkgId'])
-                    result.append((self.pc(pkg,rep)))
-    
-            for (rep,cache) in self.filelistsdb.items():
-                cur = cache.cursor()
-                (dir,filename) = os.path.split(quotename)
-                # This query means:
-                # Either name is a substring of dirname or the directory part
-                # in name is a substring of dirname and the file part is part
-                # of filelist
-                cur.execute("select packages.pkgId as pkgId,\
-                    filelist.dirname as dirname,\
-                    filelist.filetypes as filetypes,\
-                    filelist.filenames as filenames \
-                    from packages,filelist where \
-                    (filelist.dirname LIKE '%%%s%%' \
-                    OR (filelist.dirname LIKE '%%%s%%' AND\
-                    filelist.filenames LIKE '%%%s%%'))\
-                    AND (filelist.pkgKey = packages.pkgKey)" % (quotename,dir,filename))
-                    
-        elif query_type == 'glob':
-            result = []
-            quotename = name.replace("'","''")
-            for (rep,cache) in self.primarydb.items():
-                cur = cache.cursor()
-                cur.execute("select DISTINCT packages.pkgId as pkgId from provides,packages where provides.name GLOB '*%s*' AND provides.pkgKey = packages.pkgKey" % quotename)
-                for ob in cur.fetchall():
-                    if (self.excludes[rep].has_key(ob['pkgId'])):
-                        continue
-                    pkg = self.getPackageDetails(ob['pkgId'])
-                    result.append((self.pc(pkg,rep)))
-    
-            for (rep,cache) in self.filelistsdb.items():
-                cur = cache.cursor()
-                (dir,filename) = os.path.split(quotename)
-                # This query means:
-                # Either name is a substring of dirname or the directory part
-                # in name is a substring of dirname and the file part is part
-                # of filelist
-                cur.execute("select packages.pkgId as pkgId,\
-                    filelist.dirname as dirname,\
-                    filelist.filetypes as filetypes,\
-                    filelist.filenames as filenames \
-                    from packages,filelist where \
-                    (filelist.dirname GLOB '*%s*' \
-                    OR (filelist.dirname GLOB '*%s*' AND\
-                    filelist.filenames GLOB '*%s*'))\
-                    AND (filelist.pkgKey = packages.pkgKey)" % (quotename,dir,filename))
-        
-            
+        # This should never be called with a name containing a %
+        assert(name.find('%') == -1)
+        result = []
+        quotename = name.replace("'","''")
+        for (rep,cache) in self.primarydb.items():
+            cur = cache.cursor()
+            cur.execute("select DISTINCT packages.pkgId as pkgId from provides,packages where provides.name LIKE '%%%s%%' AND provides.pkgKey = packages.pkgKey" % quotename)
             for ob in cur.fetchall():
-                # Check if it is an actual match
-                # The query above can give false positives, when
-                # a package provides /foo/aaabar it will also match /foo/bar
                 if (self.excludes[rep].has_key(ob['pkgId'])):
                     continue
-                real = False
-                for filename in decodefilenamelist(ob['filenames']):
-                    if (ob['dirname']+'/'+filename).find(name) != -1:
-                        real = True
-                if (not real):
-                    continue
                 pkg = self.getPackageDetails(ob['pkgId'])
                 result.append((self.pc(pkg,rep)))
+
+        for (rep,cache) in self.filelistsdb.items():
+            cur = cache.cursor()
+            (dir,filename) = os.path.split(quotename)
+            # This query means:
+            # Either name is a substring of dirname or the directory part
+            # in name is a substring of dirname and the file part is part
+            # of filelist
+            cur.execute("select packages.pkgId as pkgId,\
+                filelist.dirname as dirname,\
+                filelist.filetypes as filetypes,\
+                filelist.filenames as filenames \
+                from packages,filelist where \
+                (filelist.dirname LIKE '%%%s%%' \
+                OR (filelist.dirname LIKE '%%%s%%' AND\
+                filelist.filenames LIKE '%%%s%%'))\
+                AND (filelist.pkgKey = packages.pkgKey)" % (quotename,dir,filename))
+                    
+        # cull the results for false positives
+        for ob in cur.fetchall():
+            # Check if it is an actual match
+            # The query above can give false positives, when
+            # a package provides /foo/aaabar it will also match /foo/bar
+            if (self.excludes[rep].has_key(ob['pkgId'])):
+                continue
+            real = False
+            for filename in decodefilenamelist(ob['filenames']):
+                if (ob['dirname']+'/'+filename).find(name) != -1:
+                    real = True
+            if (not real):
+                continue
+            pkg = self.getPackageDetails(ob['pkgId'])
+            result.append((self.pc(pkg,rep)))
         return result     
     
     def returnObsoletes(self):




More information about the Yum-cvs-commits mailing list