Skip to content

Commit

Permalink
Kernel window: Show installed mainline kernels (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
gm10 authored and clefebvre committed Oct 10, 2018
1 parent 019f903 commit 82baf86
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 38 deletions.
28 changes: 20 additions & 8 deletions usr/lib/linuxmint/mintUpdate/checkKernels.py
@@ -1,28 +1,32 @@
#!/usr/bin/python3

import os
import subprocess
import apt
import sys
import re

from gi.repository import Gio

try:
current_version = subprocess.check_output("uname -r", shell = True).decode("utf-8").replace("-generic", "").strip()

settings = Gio.Settings("com.linuxmint.updates")
kernel_type = "-generic"
if settings.get_boolean("use-lowlatency-kernels"):
kernel_type = "-lowlatency"
else:
kernel_type = "-generic"
current_version = subprocess.check_output("uname -r", shell = True).decode("utf-8").replace(kernel_type, "").strip()
cache = apt.Cache()
signed_kernels = ['']
r = re.compile(r'^(?:linux-image-)(?:unsigned-)?(\d.+?)' + kernel_type + '$')
for pkg in cache:
installed = 0
used = 0
installable = 0
pkg_version = ""
package = pkg.name
if (package.startswith("linux-image-3") or package.startswith("linux-image-4")) and package.endswith(kernel_type):
version = package.replace("linux-image-", "").replace("-generic", "").replace("-lowlatency", "")
if r.match(package):
version = r.sub(r'\1', package)
# filter duplicates (unsigned kernels where signed exists)
if version in signed_kernels:
continue
if pkg.is_installed:
installed = 1
pkg_version = pkg.installed.version
Expand All @@ -32,6 +36,12 @@
pkg_version = pkg.candidate.version
if version == current_version:
used = 1
if not pkg.candidate.origins[0].origin:
origin = 0
elif pkg.candidate.origins[0].origin == 'Ubuntu':
origin = 1
else:
origin = 2

# provide a representation of the version which helps sorting the kernels
version_array = pkg_version.replace("-", ".").split(".")
Expand All @@ -43,7 +53,9 @@
element = "0%s" % element
versions.append(element)

resultString = "KERNEL###%s###%s###%s###%s###%s###%s" % (".".join(versions), version, pkg_version, installed, used, installable)
signed_kernels.append(version)

resultString = "KERNEL###%s###%s###%s###%s###%s###%s###%s" % (".".join(versions), version, pkg_version, installed, used, installable, origin)
print(resultString.encode("utf-8").decode('ascii', 'xmlcharrefreplace'))

except:
Expand Down
62 changes: 32 additions & 30 deletions usr/lib/linuxmint/mintUpdate/kernelwindow.py
Expand Up @@ -2,13 +2,12 @@
import apt
import subprocess
import os
import re
import tempfile
import threading
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('GdkX11', '3.0') # Needed to get xid
from gi.repository import Gtk, Gdk, GdkX11
from gi.repository import Gtk

from Classes import KERNEL_PKG_NAMES

Expand All @@ -31,6 +30,8 @@ def run(self):
"--non-interactive", "--parent-window-id", "%s" % self.application.window.get_window().get_xid(), "-o", "Synaptic::closeZvt=true"]
f = tempfile.NamedTemporaryFile()
cache = apt.Cache()
if self.remove:
KERNEL_PKG_NAMES.append('linux-image-unsigned-VERSION-generic') # mainline, remove only
for name in KERNEL_PKG_NAMES:
name = name.replace("VERSION", self.version)
if name in cache:
Expand All @@ -51,7 +52,7 @@ def run(self):
f.close()

class KernelRow(Gtk.ListBoxRow):
def __init__(self, version, pkg_version, text, installed, used, title, installable, window, application):
def __init__(self, version, pkg_version, text, installed, used, title, installable, origin, window, application):
Gtk.ListBoxRow.__init__(self)

self.application = application
Expand Down Expand Up @@ -92,24 +93,25 @@ def __init__(self, version, pkg_version, text, installed, used, title, installab
hidden_box.set_margin_bottom(6)
self.revealer.add(hidden_box)

box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box.set_margin_bottom(6)
hidden_box.pack_start(box, True, True, 0)
link = Gtk.Label()
link.set_markup("<a href='https://launchpad.net/ubuntu/+source/linux/+bugs?field.searchtext=%s'>Bug reports</a>" % version)
link.set_line_wrap(True)
box.pack_start(link, False, False, 2)
link = Gtk.Label()
changelog_version = pkg_version
if "~" in pkg_version:
changelog_version = pkg_version.split("~")[0]
link.set_markup("<a href='http://changelogs.ubuntu.com/changelogs/pool/main/l/linux/linux_%s/changelog'>Changelog</a>" % changelog_version)
link.set_line_wrap(True)
box.pack_start(link, False, False, 2)
link = Gtk.Label()
link.set_markup("<a href='https://people.canonical.com/~ubuntu-security/cve/pkg/linux.html'>CVE Tracker</a>")
link.set_line_wrap(True)
box.pack_start(link, False, False, 2)
if origin == "1":
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
box.set_margin_bottom(6)
hidden_box.pack_start(box, True, True, 0)
link = Gtk.Label()
link.set_markup("<a href='https://launchpad.net/ubuntu/+source/linux/+bugs?field.searchtext=%s'>Bug reports</a>" % version)
link.set_line_wrap(True)
box.pack_start(link, False, False, 2)
link = Gtk.Label()
changelog_version = pkg_version
if "~" in pkg_version:
changelog_version = pkg_version.split("~")[0]
link.set_markup("<a href='http://changelogs.ubuntu.com/changelogs/pool/main/l/linux/linux_%s/changelog'>Changelog</a>" % changelog_version)
link.set_line_wrap(True)
box.pack_start(link, False, False, 2)
link = Gtk.Label()
link.set_markup("<a href='https://people.canonical.com/~ubuntu-security/cve/pkg/linux.html'>CVE Tracker</a>")
link.set_line_wrap(True)
box.pack_start(link, False, False, 2)

button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
button = Gtk.Button.new_with_label("")
Expand Down Expand Up @@ -191,30 +193,30 @@ def __init__(self, application):

builder.get_object("button_close").connect("clicked", self.hide_window)

kernels = subprocess.check_output("/usr/lib/linuxmint/mintUpdate/checkKernels.py | sort -r | grep \"###\"", shell = True).decode("utf-8")
kernels = subprocess.check_output("/usr/lib/linuxmint/mintUpdate/checkKernels.py", shell = True).decode("utf-8")
kernels = kernels.split("\n")
kernels.sort(reverse = True)
kernel_list = []
pages_needed = []
for kernel in kernels:
values = kernel.split('###')
if len(values) == 7:
status = values[0]
if status != "KERNEL":
continue
(status, version_id, version, pkg_version, installed, used, installable) = values
if len(values) == 8:
(status, version_id, version, pkg_version, installed, used, installable, origin) = values
installed = (installed == "1")
used = (used == "1")
title = ""
if used:
title = _("Active")
elif installed:
title = _("Installed")
if origin == "0":
title += " (local)"

installable = (installable == "1")
label = version

page_label = label.split(".")[0] + "." + label.split(".")[1]
kernel_list.append([version, pkg_version, page_label, label, installed, used, title, installable])
kernel_list.append([version, pkg_version, page_label, label, installed, used, title, installable, origin])
if page_label not in pages_needed:
pages_needed.append(page_label)

Expand All @@ -230,11 +232,11 @@ def __init__(self, application):
# stack_switcher.add_titled(page, page)

for kernel in kernel_list:
(version, pkg_version, page_label, label, installed, used, title, installable) = kernel
(version, pkg_version, page_label, label, installed, used, title, installable, origin) = kernel
if used:
current_label.set_markup("<b>%s %s</b>" % (_("You are currently using the following kernel:"), kernel[3]))
if page_label == page:
row = KernelRow(version, pkg_version, label, installed, used, title, installable, self.window, self.application)
row = KernelRow(version, pkg_version, label, installed, used, title, installable, origin, self.window, self.application)
list_box.add(row)

list_box.connect("row_activated", self.on_row_activated)
Expand Down

0 comments on commit 82baf86

Please sign in to comment.