From: Christian Van Wambeke Date: Thu, 29 Nov 2018 09:03:43 +0000 (+0100) Subject: accept range 'version_1_0_0_to_2_0_0' as '_from_1_0_0_to_2_0_0' X-Git-Tag: 5.2.0~8 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c6d84d3916d436550743817edff79a7e3f1233ea;p=tools%2Fsat.git accept range 'version_1_0_0_to_2_0_0' as '_from_1_0_0_to_2_0_0' --- diff --git a/src/versionMinorMajorPatch.py b/src/versionMinorMajorPatch.py index 94b8921..ef916ce 100755 --- a/src/versionMinorMajorPatch.py +++ b/src/versionMinorMajorPatch.py @@ -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 diff --git a/test/test_021_versionMinorMajorPatch.py b/test/test_021_versionMinorMajorPatch.py index 6fbb061..2cecf03 100755 --- a/test/test_021_versionMinorMajorPatch.py +++ b/test/test_021_versionMinorMajorPatch.py @@ -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")