From 03561ee72c9e082573b8d12efb56c5d4c37fc949 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Mon, 20 Feb 2017 17:51:17 +0000 Subject: [PATCH 1/4] target: Make KernelVersion fields numerical --- devlib/target.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/devlib/target.py b/devlib/target.py index d3b1086..5fd6bb9 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -1209,11 +1209,15 @@ class KernelVersion(object): self.rc = None match = KVERSION_REGEX.match(version_string) if match: - self.version_number = match.group('version') - self.major = match.group('major') - self.minor = match.group('minor') - self.sha1 = match.group('sha1') - self.rc = match.group('rc') + groups = match.groupdict() + self.version_number = int(groups['version']) + self.major = int(groups['major']) + if groups['minor'] is not None: + self.minor = int(groups['minor']) + if groups['rc'] is not None: + self.rc = int(groups['rc']) + if groups['sha1'] is not None: + self.sha1 = match.group('sha1') def __str__(self): return '{} {}'.format(self.release, self.version) From 54adf80eab2cd1660539b09c72af85c12abc53d7 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Mon, 20 Feb 2017 17:57:51 +0000 Subject: [PATCH 2/4] target: Add KernelVersion docstring --- devlib/target.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/devlib/target.py b/devlib/target.py index 5fd6bb9..4229362 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -1189,7 +1189,29 @@ class Cpuinfo(object): class KernelVersion(object): + """ + Class representing the version of a target kernel + Not expected to work for very old (pre-3.0) kernel version numbers. + + :ivar release: Version number/revision string. Typical output of + ``uname -r`` + :type release: str + :ivar version: Extra version info (aside from ``release``) reported by + ``uname`` + :type version: str + :ivar version_number: Main version number (e.g. 3 for Linux 3.18) + :type version_number: int + :ivar major: Major version number (e.g. 18 for Linux 3.18) + :type major: int + :ivar minor: Minor version number for stable kernels (e.g. 9 for 4.9.9). May + be None + :type minor: int + :ivar rc: Release candidate number (e.g. 3 for Linux 4.9-rc3). May be None. + :type rc: int + :ivar sha1: Kernel git revision hash, if available (otherwise None) + :type sha1: str + """ def __init__(self, version_string): if ' #' in version_string: release, version = version_string.split(' #') From 18b77b8808e4772d676d02a600ea1b3931de9c3a Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Mon, 20 Feb 2017 17:52:56 +0000 Subject: [PATCH 3/4] target: Add `parts` field to KernelVersion --- devlib/target.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/devlib/target.py b/devlib/target.py index 4229362..1450d71 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -1211,6 +1211,10 @@ class KernelVersion(object): :type rc: int :ivar sha1: Kernel git revision hash, if available (otherwise None) :type sha1: str + + :ivar parts: Tuple of version number components. Can be used for + lexicographically comparing kernel versions. + :type parts: tuple(int) """ def __init__(self, version_string): if ' #' in version_string: @@ -1241,6 +1245,8 @@ class KernelVersion(object): if groups['sha1'] is not None: self.sha1 = match.group('sha1') + self.parts = (self.version_number, self.major, self.minor) + def __str__(self): return '{} {}'.format(self.release, self.version) From 6665693e8f4cca154e3546d0ffdac9c3333dafa7 Mon Sep 17 00:00:00 2001 From: Brendan Jackman Date: Mon, 20 Feb 2017 18:29:49 +0000 Subject: [PATCH 4/4] target: Fix kernel version regex for -rc field This regex currently matches the `rc` group against the added-patches-count, e.g. "00005" in "4.4.41-00005-g17b74bafccbe-dirty" and "59" in "4.4.0-59-generic". Fix this by requiring "rc" in the match. --- devlib/target.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devlib/target.py b/devlib/target.py index 1450d71..c93d475 100644 --- a/devlib/target.py +++ b/devlib/target.py @@ -27,7 +27,7 @@ ANDROID_SCREEN_RESOLUTION_REGEX = re.compile(r'mUnrestrictedScreen=\(\d+,\d+\)' DEFAULT_SHELL_PROMPT = re.compile(r'^.*(shell|root)@.*:/\S* [#$] ', re.MULTILINE) KVERSION_REGEX =re.compile( - r'(?P\d+)(\.(?P\d+)(\.(?P\d+)(-(rc)?(?P\d+))?)?)?(.*-g(?P[0-9a-fA-F]{7,}))?' + r'(?P\d+)(\.(?P\d+)(\.(?P\d+)(-rc(?P\d+))?)?)?(.*-g(?P[0-9a-fA-F]{7,}))?' )