Add factory method to create Version from version string
authorAntoine Busque <abusque@efficios.com>
Tue, 26 Apr 2016 22:43:36 +0000 (18:43 -0400)
committerAntoine Busque <abusque@efficios.com>
Tue, 26 Apr 2016 22:43:36 +0000 (18:43 -0400)
Signed-off-by: Antoine Busque <abusque@efficios.com>
lttnganalyses/common/version_utils.py

index 88ef3c059f99f6bbd5c5e97ba4e240cf2055939d..26771d381c4785f40523dc9f1b9eff6036210e9f 100644 (file)
@@ -20,6 +20,7 @@
 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
+import re
 from functools import total_ordering
 
 
@@ -57,3 +58,18 @@ class Version:
             version_str += self.extra
 
         return version_str
+
+    @classmethod
+    def new_from_string(cls, string):
+        version_match = re.match(r'(\d+)\.(\d+)\.(\d+)(.*)', string)
+
+        if version_match is None:
+            major = minor = patch = 0
+            extra = '+unknown'
+        else:
+            major = int(version_match.group(1))
+            minor = int(version_match.group(2))
+            patch = int(version_match.group(3))
+            extra = version_match.group(4)
+
+        return cls(major, minor, patch, extra)
This page took 0.024136 seconds and 5 git commands to generate.