[csw-devel] SF.net SVN: gar:[9276] csw/mgar/gar/v2/lib/python

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Sat Mar 20 09:15:31 CET 2010


Revision: 9276
          http://gar.svn.sourceforge.net/gar/?rev=9276&view=rev
Author:   wahwah
Date:     2010-03-20 08:15:31 +0000 (Sat, 20 Mar 2010)

Log Message:
-----------
mGAR v2: checkpkg, performance fix for the dependency guesser.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/checkpkg.py
    csw/mgar/gar/v2/lib/python/checkpkg_test.py

Modified: csw/mgar/gar/v2/lib/python/checkpkg.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg.py	2010-03-20 08:12:41 UTC (rev 9275)
+++ csw/mgar/gar/v2/lib/python/checkpkg.py	2010-03-20 08:15:31 UTC (rev 9276)
@@ -479,16 +479,16 @@
 def GuessDepsByFilename(pkgname, pkg_by_any_filename):
   """Guesses dependencies based on filename regexes."""
   guessed_deps = set()
-  for pattern, dep_pkgname in DEPENDENCY_FILENAME_REGEXES:
-    # If any file name matches, add the dep, go to the next pattern/pkg
-    # combination.
-    pattern_re = re.compile("^%s$" % pattern)
-    for filename in pkg_by_any_filename:
-      if (re.match(pattern_re, filename)
-            and
-          pkgname == pkg_by_any_filename[filename]):
+  patterns = [(re.compile(x), y) for x, y in DEPENDENCY_FILENAME_REGEXES]
+  filenames = []
+  # First, find the filenames of interest.
+  for filename, file_pkgname in pkg_by_any_filename.iteritems():
+    if file_pkgname == pkgname:
+      filenames.append(filename)
+  for regex, dep_pkgname in patterns:
+    for filename in filenames:
+      if regex.match(filename):
         guessed_deps.add(dep_pkgname)
-        break
   return guessed_deps
 
 

Modified: csw/mgar/gar/v2/lib/python/checkpkg_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg_test.py	2010-03-20 08:12:41 UTC (rev 9275)
+++ csw/mgar/gar/v2/lib/python/checkpkg_test.py	2010-03-20 08:15:31 UTC (rev 9276)
@@ -249,6 +249,16 @@
     self.assertEqual(expected,
                      checkpkg.GuessDepsByFilename(pkgname, pkg_by_filename))
 
+  def testGuessDepsByFilename3(self):
+    expected = set([])
+    pkgname = u"CSWfoo"
+    pkg_by_filename = {
+        "/opt/csw/bin/bar": u"CSWfoo",
+        "/opt/csw/lib/foo.so.1": u"CSWfoo",
+    }
+    self.assertEqual(expected,
+                     checkpkg.GuessDepsByFilename(pkgname, pkg_by_filename))
+
   def testGuessDepsByPkgname1(self):
     expected = set([u"CSWfoo"])
     pkgname = u"CSWfoo-devel"


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.


More information about the devel mailing list