[yum-cvs] yum/yum __init__.py, 1.173, 1.174 depsolve.py, 1.76, 1.77 sqlitesack.py, 1.27, 1.28

Seth Vidal skvidal at linux.duke.edu
Thu Jan 12 06:03:22 UTC 2006


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

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

- remove some code duplication
- add sqlitesack searchALL parameter to do glob queries
- massively speed up the searchPackageProvides() method.


Index: __init__.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.173
retrieving revision 1.174
diff -u -r1.173 -r1.174
--- __init__.py	8 Jan 2006 23:57:25 -0000	1.173
+++ __init__.py	12 Jan 2006 06:03:20 -0000	1.174
@@ -369,6 +369,22 @@
         self.comps.compile(pkglist)
         
 
+    def doSackFilelistPopulate(self):
+        """convenience function to populate the repos with the filelist metadata
+           it also is simply to only emit a log if anything actually gets populated"""
+        
+        necessary = False
+        for repo in self.repos.listEnabled():
+            if 'filelists' in self.pkgSack.added[repo.id]:
+                continue
+            else:
+                necessary = True
+        
+        if necessary:
+            msg = 'Importing additional filelist information'
+            self.log(2, msg)
+            self.repos.populateSack(with='filelists')
+           
     def buildTransaction(self):
         """go through the packages in the transaction set, find them in the
            packageSack or rpmdb, and pack up the ts accordingly"""
@@ -1119,11 +1135,11 @@
     def searchPackageProvides(self, args, callback=None):
         
         self.doRepoSetup()
-        self.doRpmDBSetup()
         matches = {}
         
         # search deps the simple way first
         for arg in args:
+            self.log(4, 'searching the simple way')
             pkgs = self.returnPackagesByDep(arg)
             for po in pkgs:
                 if callback:
@@ -1132,6 +1148,7 @@
 
         # search pkgSack - fully populate the worthwhile metadata to search
         # if it even vaguely matches
+        self.log(4, 'fully populating the necessary data')
         for arg in args:
             matched = 0
             globs = ['.*bin\/.*', '.*\/etc\/.*', '^\/usr\/lib\/sendmail$']
@@ -1140,10 +1157,10 @@
                 if globc.match(arg):
                     matched = 1
             if not matched:
-                self.log(2, 'Importing Additional filelist information for packages')
-                self.repos.populateSack(with='filelists')
+                self.doSackFilelistPopulate()
 
         for arg in args:
+            self.log(4,'refining the search expression') 
             restring = self._refineSearchPattern(arg)
             try: 
                 arg_re = re.compile(restring, flags=re.I)
@@ -1151,21 +1168,29 @@
                 raise Errors.MiscError, \
                   'Search Expression: %s is an invalid Regular Expression.\n' % arg
             
-            # If this is not a regular expression, only search in packages
-            # returned by pkgSack.searchAll
-            if arg.find('*') == arg.find('?')  == arg.find('%') == -1 and \
-              hasattr(self.pkgSack,'searchAll'):
-                where = self.pkgSack.searchAll(arg)
-            else:
-                where = self.pkgSack
+            # 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)
                 tmpvalues = []
+                
+                self.log(5, 'searching in file entries')
                 for filetype in po.returnFileTypes():
                     for fn in po.returnFileEntries(ftype=filetype):
                         if arg_re.search(fn):
                             tmpvalues.append(fn)
-
+                
+                self.log(5, 'searching in provides entries')
                 for (p_name, p_flag, (p_e, p_v, p_r)) in po.returnPrco('provides'):
                     if arg_re.search(p_name):
                         prov = po.prcoPrintable((p_name, p_flag, (p_e, p_v, p_r)))
@@ -1176,6 +1201,7 @@
                         callback(po, tmpvalues)
                     matches[po] = tmpvalues
         
+        self.doRpmDBSetup()
         # installed rpms, too
         taglist = ['filenames', 'dirnames', 'provides']
         arg_re = []

Index: depsolve.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/depsolve.py,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -r1.76 -r1.77
--- depsolve.py	11 Jan 2006 07:14:40 -0000	1.76
+++ depsolve.py	12 Jan 2006 06:03:20 -0000	1.77
@@ -70,12 +70,8 @@
                 if globc.match(name):
                     matched = 1
             if not matched:
-                for repo in self.repos.listEnabled():
-                    if 'filelists' in self.pkgSack.added[repo.id]:
-                        continue
-                    self.log(2, 'Importing Additional filelist information for dependency resolution')
-                    self.repos.populateSack(with='filelists', which=repo.id)
-                
+                self.doSackFilelistPopulate()
+            
         pkgs = self.pkgSack.searchProvides(name)
         if flags == 0:
             flags = None

Index: sqlitesack.py
===================================================================
RCS file: /home/groups/yum/cvs/yum/yum/sqlitesack.py,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- sqlitesack.py	8 Dec 2005 21:50:14 -0000	1.27
+++ sqlitesack.py	12 Jan 2006 06:03:20 -0000	1.28
@@ -185,36 +185,69 @@
             
     # Search packages that either provide something containing name
     # or provide a file containing name 
-    def searchAll(self,name):
-        # 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))
+    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))
+        
+            
             for ob in cur.fetchall():
                 # Check if it is an actual match
                 # The query above can give false positives, when




More information about the Yum-cvs-commits mailing list