summaryrefslogtreecommitdiff
path: root/build-aux
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2020-05-18 13:32:50 +0200
committerAleksander Morgado <aleksander@aleksander.es>2020-05-18 13:35:32 +0200
commit891ff842fdb84a2f8628a19af89794a9c4287623 (patch)
treed9add68ffe4f9015ef592f5a703f6d11a08dfd25 /build-aux
parentfc550c38e88f6228a492546f1d75edb98846a194 (diff)
mbim-codegen: avoid needing python packaging.version.parse
Diffstat (limited to 'build-aux')
-rw-r--r--build-aux/mbim-codegen/Struct.py4
-rw-r--r--build-aux/mbim-codegen/utils.py21
2 files changed, 22 insertions, 3 deletions
diff --git a/build-aux/mbim-codegen/Struct.py b/build-aux/mbim-codegen/Struct.py
index 9a55b61..93e3134 100644
--- a/build-aux/mbim-codegen/Struct.py
+++ b/build-aux/mbim-codegen/Struct.py
@@ -20,8 +20,6 @@
import string
import utils
-from packaging.version import parse as parse_version
-
"""
The Struct class takes care of emitting the struct type
"""
@@ -253,7 +251,7 @@ class Struct:
if self.array_member:
# TypeArray was introduced in 1.24
- translations['array_since'] = self.since if parse_version(self.since) > parse_version('1.24') else '1.24'
+ translations['array_since'] = self.since if utils.version_compare('1.24', self.since) > 0 else '1.24'
template = (
'\n'
'/**\n'
diff --git a/build-aux/mbim-codegen/utils.py b/build-aux/mbim-codegen/utils.py
index ca0231e..118979a 100644
--- a/build-aux/mbim-codegen/utils.py
+++ b/build-aux/mbim-codegen/utils.py
@@ -189,3 +189,24 @@ def read_json_file(path):
else:
out += line
return out
+
+"""
+Compare two version strings given in MAJOR.MINOR format.
+Just to avoid needing to include e.g. packaging.version.parse just for this
+"""
+def version_compare(v1,v2):
+ major_v1 = int(v1.partition(".")[0])
+ major_v2 = int(v2.partition(".")[0])
+ if major_v2 > major_v1:
+ return 1
+ if major_v2 < major_v1:
+ return -1
+ # major_v2 == major_v1
+ minor_v1 = int(v1.partition(".")[2])
+ minor_v2 = int(v2.partition(".")[2])
+ if minor_v2 > minor_v1:
+ return 1
+ if minor_v2 < minor_v1:
+ return -1
+ # minor_v2 == minor_v1
+ return 0