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
This commit is contained in:
		
							parent
							
								
									1dadca8ed8
								
							
						
					
					
						commit
						31e3f72ae0
					
				@ -19,7 +19,7 @@
 | 
				
			|||||||
# You should have received a copy of the GNU General Public License
 | 
					# You should have received a copy of the GNU General Public License
 | 
				
			||||||
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
					# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
 | 
					import itertools
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import re
 | 
					import re
 | 
				
			||||||
import qubesadmin
 | 
					import qubesadmin
 | 
				
			||||||
@ -118,17 +118,17 @@ class KernelVersion:  # pylint: disable=too-few-public-methods
 | 
				
			|||||||
    # versions that have no numbers in them
 | 
					    # versions that have no numbers in them
 | 
				
			||||||
    def __init__(self, string):
 | 
					    def __init__(self, string):
 | 
				
			||||||
        self.string = string
 | 
					        self.string = string
 | 
				
			||||||
        self.contents = []
 | 
					        self.groups = re.compile(r'(\d+)').split(self.string)
 | 
				
			||||||
        if re.compile(r'\d+.*').match(string):
 | 
					 | 
				
			||||||
            # the version begins with a number
 | 
					 | 
				
			||||||
            self.contents = [int(x) for x in re.compile(r'\D+').split(string)]
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __lt__(self, other):
 | 
					    def __lt__(self, other):
 | 
				
			||||||
        if not self.contents and not other.contents:
 | 
					        for (self_content, other_content) in itertools.zip_longest(
 | 
				
			||||||
            return self.string < other.string
 | 
					                self.groups, other.groups):
 | 
				
			||||||
        if not self.contents or not other.contents:
 | 
					            if self_content == other_content:
 | 
				
			||||||
            return len(self.contents) < len(other.contents)
 | 
					                continue
 | 
				
			||||||
        return self.contents < other.contents
 | 
					            if self_content.isdigit() and other_content.isdigit():
 | 
				
			||||||
 | 
					                return int(self_content) < int(other_content)
 | 
				
			||||||
 | 
					            return self_content < other_content
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def prepare_kernel_choice(widget, holder, propname, default, *args, **kwargs):
 | 
					def prepare_kernel_choice(widget, holder, propname, default, *args, **kwargs):
 | 
				
			||||||
    # TODO get from storage API (pool 'linux-kernel') (suggested by @marmarta)
 | 
					    # TODO get from storage API (pool 'linux-kernel') (suggested by @marmarta)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user