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

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Thu Sep 2 11:56:40 CEST 2010


Revision: 10899
          http://gar.svn.sourceforge.net/gar/?rev=10899&view=rev
Author:   wahwah
Date:     2010-09-02 09:56:40 +0000 (Thu, 02 Sep 2010)

Log Message:
-----------
mGAR v2: checkpkg, improvements for the file name parsing function, to handle file names that don't conform to the standard.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/opencsw.py
    csw/mgar/gar/v2/lib/python/opencsw_test.py

Modified: csw/mgar/gar/v2/lib/python/opencsw.py
===================================================================
--- csw/mgar/gar/v2/lib/python/opencsw.py	2010-09-02 08:42:19 UTC (rev 10898)
+++ csw/mgar/gar/v2/lib/python/opencsw.py	2010-09-02 09:56:40 UTC (rev 10899)
@@ -119,15 +119,28 @@
     p = p[:-4]
   bits = p.split("-")
   catalogname = bits[0]
-  version, version_info, revision_info = ParseVersionString(bits[1])
+  if len(bits) < 2:
+    version, version_info, revision_info = None, None, None
+    full_version_string = None
+  else:
+    version, version_info, revision_info = ParseVersionString(bits[1])
+    full_version_string = bits[1]
   if len(bits) == 5:
     osrel, arch, vendortag = bits[2:5]
-  else:
+  elif len(bits) == 4:
     arch, vendortag = bits[2:4]
     osrel = "unspecified"
+  elif len(bits) == 3:
+    arch = bits[2]
+    vendortag = "UNKN"
+    osrel = "unspecified"
+  else:
+    arch = "unknown"
+    vendortag = "UNKN"
+    osrel = "unspecified"
   data = {
       'catalogname': catalogname,
-      'full_version_string': bits[1],
+      'full_version_string': full_version_string,
       'version': version,
       'version_info': version_info,
       'revision_info': revision_info,

Modified: csw/mgar/gar/v2/lib/python/opencsw_test.py
===================================================================
--- csw/mgar/gar/v2/lib/python/opencsw_test.py	2010-09-02 08:42:19 UTC (rev 10898)
+++ csw/mgar/gar/v2/lib/python/opencsw_test.py	2010-09-02 09:56:40 UTC (rev 10899)
@@ -117,7 +117,21 @@
       self.assertEqual(catalogname, compiled["catalogname"])
       self.assertEqual(pkg_version, compiled["full_version_string"])
 
+  def testParsePackageFileName_RichpSe(self):
+    file_name = "RICHPse-3.5.1.pkg.gz"
+    parsed = opencsw.ParsePackageFileName(file_name)
+    self.assertEqual(parsed["version"], "3.5.1")
+    self.assertEqual(parsed["vendortag"], "UNKN")
+    self.assertEqual(parsed["arch"], "unknown")
+    self.assertEqual(parsed["osrel"], "unspecified")
+    self.assertEqual(parsed["catalogname"], "RICHPse")
 
+  def testParsePackageFileName_Nonsense(self):
+    """Checks if the function can sustain a non-conformant string."""
+    file_name = "What if I wrote a letter to my grandma here?"
+    parsed = opencsw.ParsePackageFileName(file_name)
+
+
 class ParsePackageFileNameTest_2(unittest.TestCase):
 
   def setUp(self):
@@ -143,6 +157,28 @@
     self.assertEqual("unspecified", parsed["osrel"])
 
 
+class ParseVersionStringTest(unittest.TestCase):
+
+  def test_NoRev(self):
+    data = "1.2.3"
+    expected = ('1.2.3', {
+      'minor version': '2',
+      'patchlevel': '3',
+      'major version': '1'},
+      {})
+    self.assertEqual(expected, opencsw.ParseVersionString(data))
+
+  def test_Text(self):
+    data = "That, sir, is a frab-rication! It's wabbit season!"
+    opencsw.ParseVersionString(data)
+
+  def test_Empty(self):
+    data = ""
+    opencsw.ParseVersionString(data)
+    expected = ('', {'major version': ''}, {})
+    self.assertEqual(expected, opencsw.ParseVersionString(data))
+
+
 class UpgradeTypeTest(unittest.TestCase):
 
   def testUpgradeType_1(self):


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