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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Jan 17 10:26:09 CET 2011


Revision: 12969
          http://gar.svn.sourceforge.net/gar/?rev=12969&view=rev
Author:   wahwah
Date:     2011-01-17 09:26:09 +0000 (Mon, 17 Jan 2011)

Log Message:
-----------
pkgdb: Removed 'checkpkg' import

I have a suspicion that slow pkgdb startup is due to large imports.  I'm
removing the checkpkg import and replacing it with a much smaller one.

The IsMd5 function is now in struct_util.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/checkpkg.py
    csw/mgar/gar/v2/lib/python/checkpkg2.py
    csw/mgar/gar/v2/lib/python/pkgdb.py
    csw/mgar/gar/v2/lib/python/struct_util.py

Modified: csw/mgar/gar/v2/lib/python/checkpkg.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg.py	2011-01-17 09:25:47 UTC (rev 12968)
+++ csw/mgar/gar/v2/lib/python/checkpkg.py	2011-01-17 09:26:09 UTC (rev 12969)
@@ -18,6 +18,7 @@
 import models as m
 import common_constants
 import package_stats
+import struct_util
 
 
 DESCRIPTION_RE = r"^([\S]+) - (.*)$"
@@ -38,8 +39,6 @@
     "/lib",
 ]
 
-MD5_RE = re.compile(r"^[0123456789abcdef]{32}$")
-
 class Error(Exception):
   pass
 
@@ -93,15 +92,11 @@
   return m.group("username") if m else None
 
 
-def IsMd5(s):
-  # For optimization, move the compilation elsewhere.
-  return MD5_RE.match(s)
-
 def GetPackageStatsByFilenamesOrMd5s(args, debug=False):
   filenames = []
   md5s = []
   for arg in args:
-    if IsMd5(arg):
+    if struct_util.IsMd5(arg):
       md5s.append(arg)
     else:
       filenames.append(arg)

Modified: csw/mgar/gar/v2/lib/python/checkpkg2.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg2.py	2011-01-17 09:25:47 UTC (rev 12968)
+++ csw/mgar/gar/v2/lib/python/checkpkg2.py	2011-01-17 09:26:09 UTC (rev 12969)
@@ -14,6 +14,7 @@
 import database
 
 import package_stats
+import struct_util
 import checkpkg
 import checkpkg_lib
 import overrides
@@ -102,7 +103,7 @@
   # We need to separate files and md5 sums.
   md5_sums, file_list = [], []
   for arg in args:
-    if checkpkg.MD5_RE.match(arg):
+    if struct_util.IsMd5(arg):
       md5_sums.append(arg)
     else:
       file_list.append(arg)

Modified: csw/mgar/gar/v2/lib/python/pkgdb.py
===================================================================
--- csw/mgar/gar/v2/lib/python/pkgdb.py	2011-01-17 09:25:47 UTC (rev 12968)
+++ csw/mgar/gar/v2/lib/python/pkgdb.py	2011-01-17 09:26:09 UTC (rev 12969)
@@ -4,27 +4,28 @@
 # $Id$
 
 import ConfigParser
-import optparse
-import models as m
-import sqlobject
-from sqlobject import sqlbuilder
 import cPickle
+import catalog
+import checkpkg_lib
+import code
+import common_constants
+import configuration
+import database
+import datetime
 import logging
-import code
+import models as m
+import optparse
 import os
 import os.path
+import package_checks
+import package_stats
 import re
 import socket
+import sqlobject
+import struct_util
 import sys
-import package_checks
-import package_stats
-import database
-import configuration
-import checkpkg_lib
-import common_constants
 import system_pkgmap
-import catalog
-import checkpkg
+from sqlobject import sqlbuilder
 from Cheetah.Template import Template
 
 USAGE = """
@@ -144,7 +145,7 @@
   """Used to normalize identifiers (md5, filename).
 
   Currently, strips paths off given package paths."""
-  if not checkpkg.IsMd5(some_id):
+  if not struct_util.IsMd5(some_id):
     logging.warning(
         "Given Id (%s) is not an md5 sum. Will attempt to retrieve "
         "it from the datbase, but it might fail.",

Modified: csw/mgar/gar/v2/lib/python/struct_util.py
===================================================================
--- csw/mgar/gar/v2/lib/python/struct_util.py	2011-01-17 09:25:47 UTC (rev 12968)
+++ csw/mgar/gar/v2/lib/python/struct_util.py	2011-01-17 09:26:09 UTC (rev 12969)
@@ -2,7 +2,10 @@
 """
 
 import os
+import re
 
+MD5_RE = re.compile(r"^[0123456789abcdef]{32}$")
+
 def IndexDictsBy(list_of_dicts, field_key):
   """Creates an index of list of dictionaries by a field name.
 
@@ -19,3 +22,8 @@
   target = os.path.normpath(
       os.path.join(os.path.dirname(link_from), link_to))
   return target
+
+
+def IsMd5(s):
+  # For optimization, moving the compilation to the top level.
+  return MD5_RE.match(s)


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