Salome HOME
accept range 'version_1_0_0_to_2_0_0' as '_from_1_0_0_to_2_0_0'
authorChristian Van Wambeke <christian.van-wambeke@cea.fr>
Thu, 29 Nov 2018 09:03:43 +0000 (10:03 +0100)
committerChristian Van Wambeke <christian.van-wambeke@cea.fr>
Thu, 29 Nov 2018 09:03:43 +0000 (10:03 +0100)
src/versionMinorMajorPatch.py
test/test_021_versionMinorMajorPatch.py

index 94b8921efc00d35d96edee29df33842d30a9b1d5..ef916ce2fa275050101ed427d3f75a29e0a384ea 100755 (executable)
@@ -144,10 +144,13 @@ def toCompactStr_majorMinorPatch(version):
 #############################################
 def getRange_majorMinorPatch(aStr, verbose=False):
   """
-  extract from aStr a version range, defined as "*_from_aMinVersionTag_to_aMaxVersionTag.
+  extract from aStr a version range, defined as
+  '*_from_aMinVersionTag_to_aMaxVersionTag' or
+  '*version_aMinVersionTag_to_aMaxVersionTag'.
+
   where aMinVersionTag and aMaxVersionTag are compatible with MinorMajorPatch class syntaxes
   '1.2.3' or '1_2_3' etc.
-  if not found '_from_' then aMinVersionTag is '0.0.0'
+  if not found '_from_' or 'version_' first then aMinVersionTag is '0.0.0'
 
   :param aStr: string to work
   :return: list [min, max], where min, max are MinorMajorPatch instances.
@@ -162,7 +165,16 @@ def getRange_majorMinorPatch(aStr, verbose=False):
     raise Exception(msg)
   aMax = tmp1[1]
 
-  tmp0 = aStr.lower().split("_from_")
+  # accept older syntax as 'version_1_0_0_to_2_0_0', (as '_from_1_0_0_to_2_0_0')
+  if "version_" in tmp1[0] and "_from_" not in tmp1[0]:
+    aStr_with_from = aStr.lower().replace("version_", "_from_", 1)
+  else:
+    aStr_with_from = aStr.lower()
+
+  # print("aStr_with_from '%s' -> '%s'" % (aStr, aStr_with_from))
+
+  tmp0 = aStr_with_from.split("_from_")
+  tmp1 = aStr_with_from.split("_to_")
 
   if len(tmp0) > 2:
     msg = "more than one '_from_' is incorrect for version range: '%s'" % aStr
index 6fbb0612713a8866690a4babf8d6c7a0c53261e6..2cecf03642ee4b5efbccabc454c0c264bac860eb 100755 (executable)
@@ -173,7 +173,9 @@ toto_from_1_to_2
    _from_1.0.0_to_2.0.0
 _from_1_0.  0_to_  2.0_0   
 _from_V1.0.0_to_2.0.0
-_from_version_1.0.0_to_2.0.0""".split("\n")
+_from_version_1.0.0_to_2.0.0
+version_1.0.0_to_2.0.0
+VERSION_1.0.0_to_2.0.0""".split("\n")
 
     for a in tests:
       # print("test '%s'" % a)
@@ -221,6 +223,8 @@ toto_from_2""".split("\n")
     with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("_from__to_")
     with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("toto_from__to_")
     with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("toto_from_123_to_")
+    with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("version_123_to_")
+    with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("version_to_")
 
     # min > max does matter
     with self.assertRaises(Exception): VMMP.getRange_majorMinorPatch("_from_3_to_2")