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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Mon Feb 14 21:30:17 CET 2011


Revision: 13310
          http://gar.svn.sourceforge.net/gar/?rev=13310&view=rev
Author:   wahwah
Date:     2011-02-14 20:30:17 +0000 (Mon, 14 Feb 2011)

Log Message:
-----------
checkpkg: Adding MakeCatalognameByPkgname

A function to transform pkgnames to a catalognames.  One of its uses will be
verifying that catalognames match pkgnames.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/struct_util.py
    csw/mgar/gar/v2/lib/python/struct_util_test.py

Modified: csw/mgar/gar/v2/lib/python/struct_util.py
===================================================================
--- csw/mgar/gar/v2/lib/python/struct_util.py	2011-02-14 20:29:41 UTC (rev 13309)
+++ csw/mgar/gar/v2/lib/python/struct_util.py	2011-02-14 20:30:17 UTC (rev 13310)
@@ -5,7 +5,10 @@
 import re
 
 MD5_RE = re.compile(r"^[0123456789abcdef]{32}$")
+PKGNAME_TICKER_RE = re.compile(r'^CSW')
+PKGNAME_CHARS_RE = re.compile(r'[A-Za-z0-9\+]+')
 
+
 def IndexDictsBy(list_of_dicts, field_key):
   """Creates an index of list of dictionaries by a field name.
 
@@ -34,3 +37,9 @@
 def IsMd5(s):
   # For optimization, moving the compilation to the top level.
   return MD5_RE.match(s)
+
+
+def MakeCatalognameByPkgname(pkgname):
+  catalogname = re.sub(PKGNAME_TICKER_RE, '', pkgname)
+  catalogname = "_".join(re.findall(PKGNAME_CHARS_RE, catalogname))
+  return catalogname

Modified: csw/mgar/gar/v2/lib/python/struct_util_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/struct_util_test.py	2011-02-14 20:29:41 UTC (rev 13309)
+++ csw/mgar/gar/v2/lib/python/struct_util_test.py	2011-02-14 20:30:17 UTC (rev 13310)
@@ -46,6 +46,7 @@
         "/libexec/foo-exec",
         struct_util.ResolveSymlink("/opt/csw/bin/foo", "/libexec/foo-exec"))
 
+
 class OsReleaseToLongTest(unittest.TestCase):
 
   def testLong(self):
@@ -55,5 +56,25 @@
     self.assertEqual("SunOS5.9", struct_util.OsReleaseToLong("5.9"))
 
 
+class MakeCatalognameByPkgnameTest(unittest.TestCase):
+
+  def testSimple(self):
+    self.assertEqual("foo", struct_util.MakeCatalognameByPkgname("CSWfoo"))
+
+  def testWithDash(self):
+    self.assertEqual("foo_bar", struct_util.MakeCatalognameByPkgname("CSWfoo-bar"))
+
+  def testCollapseSeparators(self):
+    self.assertEqual("foo_bar", struct_util.MakeCatalognameByPkgname("CSWfoo--bar"))
+
+  def testWithDigits(self):
+    # This shouldn't be a typical case.
+    self.assertEqual("libfoo1_1", struct_util.MakeCatalognameByPkgname("CSWlibfoo1-1"))
+
+  def testPluses(self):
+    # Pluses?  Plusen?  Plusi?
+    self.assertEqual("libnetcdf_c++5", struct_util.MakeCatalognameByPkgname("CSWlibnetcdf-c++5"))
+
+
 if __name__ == '__main__':
 	unittest.main()


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