Commit 6d9520ed authored by Fabien Lahoudere's avatar Fabien Lahoudere Committed by Enric Balletbo i Serra

Add helper to convert kernel release

Add one function to convert version major and minor
to an integer.
Add a function to get the running kernel version and
convert it using the previous function.
Signed-off-by: default avatarFabien Lahoudere <fabien.lahoudere@collabora.com>
Signed-off-by: default avatarEnric Balletbo i Serra <enric.balletbo@collabora.com>
parent cca9287f
......@@ -131,6 +131,28 @@ def read_file(name):
fd.close()
return contents
# Return an int froom kernel version to allow to compare
def version_to_int(version, major, minor):
pattern = "{0:03d}{1:03d}{2:03d}"
return int(pattern.format(version, major, minor))
# Return the running kernel version
def current_kernel_version():
fd = open("/proc/version", 'r')
current = fd.read().split()[2].split('-')[0].split('.')
fd.close()
return version_to_int(int(current[0]), int(current[1]), int(current[2]))
def kernel_lower_than(version, major, minor):
if version_to_int(version, major, minor) > current_kernel_version():
return True
return False
def kernel_greater_than(version, major, minor):
if version_to_int(version, major, minor) < current_kernel_version():
return True
return False
###############################################################################
# TEST RUNNERS
###############################################################################
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment