|
19 | 19 | # You should have received a copy of the GNU General Public License
|
20 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
21 | 21 | #
|
22 |
| - |
| 22 | +import itertools |
23 | 23 | import os
|
24 | 24 | import re
|
25 | 25 | import qubesadmin
|
@@ -118,17 +118,17 @@ class KernelVersion: # pylint: disable=too-few-public-methods
|
118 | 118 | # versions that have no numbers in them
|
119 | 119 | def __init__(self, string):
|
120 | 120 | 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) |
125 | 122 |
|
126 | 123 | 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 | + |
132 | 132 |
|
133 | 133 | def prepare_kernel_choice(widget, holder, propname, default, *args, **kwargs):
|
134 | 134 | # TODO get from storage API (pool 'linux-kernel') (suggested by @marmarta)
|
|
0 commit comments