Skip to content

Commit 31e3f72

Browse files
committed
Kernel sorting fix
Fixed bug with kernel versions ending with a letter, hopefully now the sorting is even more robust and sensible. fixes QubesOS/qubes-issues#5208
1 parent 1dadca8 commit 31e3f72

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

qubesmanager/utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# You should have received a copy of the GNU General Public License
2020
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2121
#
22-
22+
import itertools
2323
import os
2424
import re
2525
import qubesadmin
@@ -118,17 +118,17 @@ class KernelVersion: # pylint: disable=too-few-public-methods
118118
# versions that have no numbers in them
119119
def __init__(self, string):
120120
self.string = string
121-
self.contents = []
122-
if re.compile(r'\d+.*').match(string):
123-
# the version begins with a number
124-
self.contents = [int(x) for x in re.compile(r'\D+').split(string)]
121+
self.groups = re.compile(r'(\d+)').split(self.string)
125122

126123
def __lt__(self, other):
127-
if not self.contents and not other.contents:
128-
return self.string < other.string
129-
if not self.contents or not other.contents:
130-
return len(self.contents) < len(other.contents)
131-
return self.contents < other.contents
124+
for (self_content, other_content) in itertools.zip_longest(
125+
self.groups, other.groups):
126+
if self_content == other_content:
127+
continue
128+
if self_content.isdigit() and other_content.isdigit():
129+
return int(self_content) < int(other_content)
130+
return self_content < other_content
131+
132132

133133
def prepare_kernel_choice(widget, holder, propname, default, *args, **kwargs):
134134
# TODO get from storage API (pool 'linux-kernel') (suggested by @marmarta)

0 commit comments

Comments
 (0)