From: Maciej Bliziński <[email protected]>

This function transforms pkgname to a catalogname.
---
 gar/v2/lib/python/struct_util.py      |    6 ++++++
 gar/v2/lib/python/struct_util_test.py |   12 ++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/gar/v2/lib/python/struct_util.py b/gar/v2/lib/python/struct_util.py
index 389c4f8..cc02828 100644
--- a/gar/v2/lib/python/struct_util.py
+++ b/gar/v2/lib/python/struct_util.py
@@ -27,3 +27,9 @@ def ResolveSymlink(link_from, link_to):
 def IsMd5(s):
   # For optimization, moving the compilation to the top level.
   return MD5_RE.match(s)
+
+
+def MakeCatalognameByPkgname(pkgname):
+  catalogname = re.sub(r'^CSW', '', pkgname)
+  catalogname = re.sub('[^A-Za-z0-9]', '_', catalogname)
+  return catalogname
diff --git a/gar/v2/lib/python/struct_util_test.py 
b/gar/v2/lib/python/struct_util_test.py
index 98d9dbd..6046ed6 100755
--- a/gar/v2/lib/python/struct_util_test.py
+++ b/gar/v2/lib/python/struct_util_test.py
@@ -47,5 +47,17 @@ class IndexByUnitTest(unittest.TestCase):
         struct_util.ResolveSymlink("/opt/csw/bin/foo", "/libexec/foo-exec"))
 
 
+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 testWithDigits(self):
+    self.assertEqual("libfoo1_1", 
struct_util.MakeCatalognameByPkgname("CSWlibfoo1-1"))
+
+
 if __name__ == '__main__':
        unittest.main()
-- 
1.7.1

_______________________________________________
maintainers mailing list
[email protected]
https://lists.opencsw.org/mailman/listinfo/maintainers
.:: This mailing list's archive is public. ::.

Reply via email to