[yum-git] yum/depsolve.py yum/__init__.py yum/misc.py yum/sqlitesack.py

James Antill james at linux.duke.edu
Tue Mar 18 20:37:28 UTC 2008


 yum/__init__.py   |    4 ++--
 yum/depsolve.py   |    9 ++-------
 yum/misc.py       |   26 ++++++++++++++++++++++++--
 yum/sqlitesack.py |   29 ++++++++---------------------
 4 files changed, 36 insertions(+), 32 deletions(-)

New commits:
commit e760b5123c64f78232a7d4e06a807c8d81c5e969
Author: James Antill <james at and.org>
Date:   Tue Mar 18 16:37:21 2008 -0400

    Cleanup RE matching for globs and primary.xml filename matching

diff --git a/yum/__init__.py b/yum/__init__.py
index 1ddb4c0..8144d16 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -1564,7 +1564,7 @@ class YumBase(depsolve.Depsolve):
         
         matches = {}
         for arg in args:
-            if not re.match('.*[\*\?\[\]].*', arg):
+            if not misc.re_glob(arg):
                 isglob = False
                 if arg[0] != '/':
                     canBeFile = False
@@ -1619,7 +1619,7 @@ class YumBase(depsolve.Depsolve):
         # installed rpms, too
         taglist = ['filelist', 'dirnames', 'provides_names']
         for arg in args:
-            if not re.match('.*[\*\?\[\]].*', arg):
+            if not misc.re_glob(arg):
                 isglob = False
                 if arg[0] != '/':
                     canBeFile = False
diff --git a/yum/depsolve.py b/yum/depsolve.py
index 21f3571..15b9277 100644
--- a/yum/depsolve.py
+++ b/yum/depsolve.py
@@ -27,6 +27,7 @@ import rpmUtils.transaction
 import rpmUtils.miscutils
 import rpmUtils.arch
 from rpmUtils.arch import archDifference, isMultiLibArch
+import misc
 from misc import unique, version_tuple_to_string
 import rpm
 
@@ -150,13 +151,7 @@ class Depsolve(object):
         # /etc/* bin/* or /usr/lib/sendmail then we should fetch the 
         # filelists.xml for all repos to make the searchProvides more complete.
         if name[0] == '/':
-            matched = 0
-            globs = ['.*bin\/.*', '^\/etc\/.*', '^\/usr\/lib\/sendmail$']
-            for glob in globs:
-                globc = re.compile(glob)
-                if globc.match(name):
-                    matched = 1
-            if not matched:
+            if not misc.re_primary_filename(name):
                 self.doSackFilelistPopulate()
             
         pkgs = self.pkgSack.searchProvides(name)
diff --git a/yum/misc.py b/yum/misc.py
index 336d621..2172af9 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -20,11 +20,33 @@ import gpgme
 
 from Errors import MiscError
 
+
+_re_compiled_glob_match = None
+def re_glob(s):
+    """ Tests if a string is a shell wildcard. """
+    # re.match('.*[\*\?\[\]].*', name)
+    global _re_compiled_glob_match
+    if _re_compiled_glob_match is None:
+        _re_compiled_glob_match = re.compile('.*[\*\?\[\]].*')
+    return _re_compiled_glob_match.match(s)
+
+_re_compiled_pri_fnames_match = None
+def re_primary_filename(filename):
+    global _re_compiled_pri_fnames_match
+    if _re_compiled_pri_fnames_match is None:
+        one   = re.compile('.*bin\/.*')
+        two   = re.compile('^\/etc\/.*')
+        three = re.compile('^\/usr\/lib\/sendmail$')
+        _re_compiled_pri_fnames_match = (one, two, three)
+    for rec in _re_compiled_pri_fnames_match:
+        if rec.match(filename):
+            return True
+    return False
+
 ###########
 # Title: Remove duplicates from a sequence
 # Submitter: Tim Peters 
-# From: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560                      
-    
+# From: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52560
 def unique(s):
     """Return a list of the elements in s, but without duplicates.
 
diff --git a/yum/sqlitesack.py b/yum/sqlitesack.py
index 26c1f68..80f916a 100644
--- a/yum/sqlitesack.py
+++ b/yum/sqlitesack.py
@@ -21,7 +21,6 @@
 
 import os
 import os.path
-import re
 import fnmatch
 
 import yumRepo
@@ -415,7 +414,7 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
         
         glob = True
         querytype = 'glob'
-        if strict or not re.match('.*[\*\?\[\]].*', name):
+        if strict or not misc.re_glob(name):
             glob = False
             querytype = '='
 
@@ -686,14 +685,8 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
             self._search_cache[prcotype][req] = result
             return result
 
-        matched = 0
-        globs = ['.*bin\/.*', '^\/etc\/.*', '^\/usr\/lib\/sendmail$']
-        for thisglob in globs:
-            globc = re.compile(thisglob)
-            if globc.match(name):
-                matched = 1
-
-        if not matched: # if its not in the primary.xml files
+        if not misc.re_primary_filename(name):
+            # if its not in the primary.xml files
             # search the files.xml file info
             for pkg in self.searchFiles(name, strict=True):
                 result[pkg] = [(name, None, None)]
@@ -726,7 +719,7 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
         """return list of packages having prcotype name (any evr and flag)"""
         glob = True
         querytype = 'glob'
-        if not re.match('.*[\*\?\[\]].*', name):
+        if not misc.re_glob(name):
             glob = False
             querytype = '='
 
@@ -746,15 +739,9 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
             cur = cache.cursor()
             executeSQL(cur, "select DISTINCT pkgKey from files where name %s ?" % querytype, (name,))
             self._sql_pkgKey2po(rep, cur, results)
-        
-        matched = 0
-        globs = ['.*bin\/.*', '^\/etc\/.*', '^\/usr\/lib\/sendmail$']
-        for thisglob in globs:
-            globc = re.compile(thisglob)
-            if globc.match(name):
-                matched = 1
-
-        if matched and not glob: # if its in the primary.xml files then skip the other check
+
+        # if its in the primary.xml files then skip the other check
+        if misc.re_primary_filename(name) and not glob:
             return misc.unique(results)
 
         # If it is a filename, search the files.xml file info
@@ -898,7 +885,7 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
         unmatched = list(pkgspecs)
 
         for p in pkgspecs:
-            if re.match('.*[\*\?\[\]].*', p):
+            if misc.re_glob(p):
                 query = PARSE_QUERY % ({ "op": "glob", "q": p })
                 matchres = matched
             else:



More information about the Yum-cvs-commits mailing list