Esempio n. 1
0
    def test_maintenance_time(self):
        months_of_support = 18
        # test historic releases, jaunty
        release_date = datetime.datetime(2009, 4, 23)
        (end_year,
         end_month) = get_maintenance_end_date(release_date, months_of_support)
        self.assertEqual(end_year, 2010)
        self.assertEqual(end_month, 10)
        # test historic releases, karmic
        release_date = datetime.datetime(2009, 10, 29)
        (end_year,
         end_month) = get_maintenance_end_date(release_date, months_of_support)
        self.assertEqual(end_year, 2011)
        self.assertEqual(end_month, 4)
        # test maverick
        release_date = datetime.datetime(2010, 10, 10)
        (end_year,
         end_month) = get_maintenance_end_date(release_date, months_of_support)
        self.assertEqual(end_year, 2012)
        self.assertEqual(end_month, 4)

        # test with modulo zero
        release_date = datetime.datetime(2010, 6, 10)
        (end_year,
         end_month) = get_maintenance_end_date(release_date, months_of_support)
        self.assertEqual(end_year, 2011)
        self.assertEqual(end_month, 12)

        # test dapper
        months_of_support = 60
        release_date = datetime.datetime(2008, 4, 24)
        (end_year,
         end_month) = get_maintenance_end_date(release_date, months_of_support)
        self.assertEqual(end_year, 2013)
        self.assertEqual(end_month, 4)
Esempio n. 2
0
    def test_maintenance_time(self):
        months_of_support = 18
        # test historic releases, jaunty
        release_date = datetime.datetime(2009, 4, 23)
        (end_year, end_month) = get_maintenance_end_date(release_date, months_of_support)
        self.assertEqual(end_year, 2010)
        self.assertEqual(end_month, 10)
        # test historic releases, karmic
        release_date = datetime.datetime(2009, 10, 29)
        (end_year, end_month) = get_maintenance_end_date(release_date, months_of_support)
        self.assertEqual(end_year, 2011)
        self.assertEqual(end_month, 4)
        # test maverick
        release_date = datetime.datetime(2010, 10, 10)
        (end_year, end_month) = get_maintenance_end_date(release_date, months_of_support)
        self.assertEqual(end_year, 2012)
        self.assertEqual(end_month, 4)

        # test with modulo zero
        release_date = datetime.datetime(2010, 6, 10)
        (end_year, end_month) = get_maintenance_end_date(release_date, months_of_support)
        self.assertEqual(end_year, 2011)
        self.assertEqual(end_month, 12)

        # test dapper
        months_of_support = 60
        release_date = datetime.datetime(2008, 4, 24)
        (end_year, end_month) = get_maintenance_end_date(release_date, months_of_support)
        self.assertEqual(end_year, 2013)
        self.assertEqual(end_month, 4)
    def get_maintenance_status(self, cache, appname, pkgname, component,
                               channelname):
        # try to figure out the support dates of the release and make
        # sure to look only for stuff in "Ubuntu" and "distro_codename"
        # (to exclude stuff in ubuntu-updates for the support time
        # calculation because the "Release" file time for that gets
        # updated regularly)
        if not hasattr(cache, '_cache') or not pkgname:
            return
        releasef = get_release_filename_for_pkg(cache._cache, pkgname,
                                                "Ubuntu", self.get_codename())
        time_t = get_release_date_from_release_file(releasef)
        # check the release date and show support information
        # based on this
        if time_t:
            release_date = datetime.datetime.fromtimestamp(time_t)
            #print "release_date: ", release_date
            now = datetime.datetime.now()
            #release_age = (now - release_date).days
            #print "release age: ", release_age

            # init with the default time
            support_month = 18

            # see if we have a "Supported" entry in the pkg record
            if (pkgname in cache and cache[pkgname].candidate):
                support_time = cache._cache[pkgname].candidate.record.get(
                    "Supported")
                if support_time:
                    if support_time.endswith("y"):
                        support_month = 12 * int(support_time.strip("y"))
                    elif support_time.endswith("m"):
                        support_month = int(support_time.strip("m"))
                    else:
                        LOG.warning("unsupported 'Supported' string '%s'" %
                                    support_time)

            # mvo: we do not define the end date very precisely
            #      currently this is why it will just display a end
            #      range
            # print release_date, support_month
            (support_end_year, support_end_month) = get_maintenance_end_date(
                release_date, support_month)
            support_end_month_str = locale.nl_langinfo(
                getattr(locale, "MON_%d" % support_end_month))
            # check if the support has ended
            support_ended = (now.year >= support_end_year
                             and now.month > support_end_month)
            if component == "main":
                if support_ended:
                    return _("Canonical does no longer provide "
                             "updates for %s in Ubuntu %s. "
                             "Updates may be available in a newer version of "
                             "elementary OS.") % (appname,
                                                  self.get_distro_release())
                else:
                    return _("Canonical provides critical updates for "
                             "%(appname)s until %(support_end_month_str)s "
                             "%(support_end_year)s.") % {
                                 'appname': appname,
                                 'support_end_month_str':
                                 support_end_month_str,
                                 'support_end_year': support_end_year
                             }
            elif component == "restricted":
                if support_ended:
                    return _("Canonical does no longer provide "
                             "updates for %s in Ubuntu %s. "
                             "Updates may be available in a newer version of "
                             "elementary OS.") % (appname,
                                                  self.get_distro_release())
                else:
                    return _("Canonical provides critical updates supplied "
                             "by the developers of %(appname)s until "
                             "%(support_end_month_str)s "
                             "%(support_end_year)s.") % {
                                 'appname': appname,
                                 'support_end_month_str':
                                 support_end_month_str,
                                 'support_end_year': support_end_year,
                             }

        # if we couldn't determine a support date, use a generic maintenance
        # string without the date
        if (channelname
                or component in ("partner", "independent", "commercial")):
            return _("Provided by the vendor.")
        elif component == "main":
            return _("Canonical provides critical updates for %s.") % appname
        elif component == "restricted":
            return _("Canonical provides critical updates supplied by the "
                     "developers of %s.") % appname
        elif component == "universe" or component == "multiverse":
            return _("Canonical does not provide updates for %s. "
                     "Some updates may be provided by the "
                     "elementary OS community.") % appname
Esempio n. 4
0
    def get_maintenance_status(self, cache, appname, pkgname, component,
        channelname):
        # try to figure out the support dates of the release and make
        # sure to look only for stuff in "Ubuntu" and "distro_codename"
        # (to exclude stuff in ubuntu-updates for the support time
        # calculation because the "Release" file time for that gets
        # updated regularly)
        if not hasattr(cache, '_cache') or not pkgname:
            return
        releasef = get_release_filename_for_pkg(cache._cache, pkgname,
                                                "Ubuntu",
                                                self.get_codename())
        time_t = get_release_date_from_release_file(releasef)
        # check the release date and show support information
        # based on this
        if time_t:
            release_date = datetime.datetime.fromtimestamp(time_t)
            #print "release_date: ", release_date
            now = datetime.datetime.now()
            #release_age = (now - release_date).days
            #print "release age: ", release_age

            # init with the default time
            support_month = 18

            # see if we have a "Supported" entry in the pkg record
            if (pkgname in cache and
                cache[pkgname].candidate):
                support_time = cache._cache[pkgname].candidate.record.get(
                    "Supported")
                if support_time:
                    if support_time.endswith("y"):
                        support_month = 12 * int(support_time.strip("y"))
                    elif support_time.endswith("m"):
                        support_month = int(support_time.strip("m"))
                    else:
                        LOG.warning("unsupported 'Supported' string '%s'" %
                            support_time)

            # mvo: we do not define the end date very precisely
            #      currently this is why it will just display a end
            #      range
            # print release_date, support_month
            (support_end_year, support_end_month) = get_maintenance_end_date(
                release_date, support_month)
            support_end_month_str = locale.nl_langinfo(
                getattr(locale, "MON_%d" % support_end_month))
             # check if the support has ended
            support_ended = (now.year >= support_end_year and
                             now.month > support_end_month)
            if component == "main":
                if support_ended:
                    return _("Canonical does no longer provide "
                             "updates for %s in Ubuntu %s. "
                             "Updates may be available in a newer version of "
                             "Ubuntu.") % (appname, self.get_distro_release())
                else:
                    return _("Canonical provides critical updates for "
                             "%(appname)s until %(support_end_month_str)s "
                             "%(support_end_year)s.") % {
                                'appname': appname,
                                'support_end_month_str': support_end_month_str,
                                'support_end_year': support_end_year}
            elif component == "restricted":
                if support_ended:
                    return _("Canonical does no longer provide "
                             "updates for %s in Ubuntu %s. "
                             "Updates may be available in a newer version of "
                             "Ubuntu.") % (appname, self.get_distro_release())
                else:
                    return _("Canonical provides critical updates supplied "
                             "by the developers of %(appname)s until "
                             "%(support_end_month_str)s "
                             "%(support_end_year)s.") % {
                                'appname': appname,
                                'support_end_month_str': support_end_month_str,
                                'support_end_year': support_end_year,
                            }

        # if we couldn't determine a support date, use a generic maintenance
        # string without the date
        if (channelname or
            component in ("partner", "independent", "commercial")):
            return _("Provided by the vendor.")
        elif component == "main":
            return _("Canonical provides critical updates for %s.") % appname
        elif component == "restricted":
            return _("Canonical provides critical updates supplied by the "
                     "developers of %s.") % appname
        elif component == "universe" or component == "multiverse":
            return _("Canonical does not provide updates for %s. "
                     "Some updates may be provided by the "
                     "Ubuntu community.") % appname
Esempio n. 5
0
    def build_kernels_list(self, kernels):
        now = datetime.now()
        hwe_support_duration = {}
        kernels = kernels.split("\n")
        kernels.sort()
        kernel_list_prelim = []
        pages_needed = []
        pages_needed_sort = []
        self.marked_kernels = []
        # ACTIVE_KERNEL_VERSION is used by the MarkKernelRow class
        global ACTIVE_KERNEL_VERSION
        ACTIVE_KERNEL_VERSION = "0"
        for kernel in kernels:
            values = kernel.split('###')
            if len(values) == 11:
                (version_id, version, pkg_version, installed, used,
                 installable, origin, archive, support_duration,
                 kernel_type) = values[1:]
                installed = (installed == "1")
                used = (used == "1")
                title = ""
                if used:
                    title = _("Active")
                    ACTIVE_KERNEL_VERSION = version_id
                elif installed:
                    title = _("Installed")

                installable = (installable == "1")
                if kernel_type == CONFIGURED_KERNEL_TYPE:
                    label = version
                else:
                    label = version + kernel_type
                    self.allow_kernel_type_selection = True
                page_label = ".".join(label.replace("-", ".").split(".")[:2])

                support_duration = int(support_duration)

                release = archive.split("-", 1)[0]
                if support_duration and origin == "1":
                    if not release in hwe_support_duration:
                        hwe_support_duration[release] = []
                    if not [
                            x for x in hwe_support_duration[release]
                            if x[0] == page_label
                    ]:
                        hwe_support_duration[release].append(
                            [page_label, support_duration])

                kernel_list_prelim.append([
                    version_id, version, pkg_version, kernel_type, page_label,
                    label, installed, used, title, installable, origin,
                    release, support_duration
                ])
                if page_label not in pages_needed:
                    pages_needed.append(page_label)
                    pages_needed_sort.append([version_id, page_label])

        # get kernel support duration
        kernel_support_info = {}
        for release in hwe_support_duration:
            if release not in self.release_dates.keys():
                continue
            kernel_support_info[release] = []
            kernel_count = len(hwe_support_duration[release])
            time_since_release = (
                now.year - self.release_dates[release][0].year) * 12 + (
                    now.month - self.release_dates[release][0].month)
            for point_release, kernel in enumerate(
                    hwe_support_duration[release]):
                (page_label, support_duration) = kernel
                if support_duration == -1:
                    # here's some magic to determine hwe support duration based on the release cycle
                    # described here: https://wiki.ubuntu.com/Kernel/Support#A18.04.x_Ubuntu_Kernel_Support
                    if point_release >= 4:
                        # Regularly the 4th point release is the next LTS kernel. However, this sequence breaks when
                        # out-of-turn HWE kernels like 4.11 are introduced, so we have to work around that:
                        if kernel_count > 5 and point_release < kernel_count - 1:
                            support_duration = kernel_support_info[release][3][
                                1]
                        # the 4th point release is LTS and scheduled 28 months after original release:
                        elif time_since_release >= 28:
                            support_duration = (self.release_dates[release][1].year - self.release_dates[release][0].year) * 12 + \
                                (self.release_dates[release][1].month - self.release_dates[release][0].month)
                    if point_release >= 1 and support_duration == -1:
                        # out of turn HWE kernels can be detected quite well at the time of release,
                        # but later on there's no way to know which one was the one that was out of turn
                        max_expected_point_release = (time_since_release -
                                                      3) // 6 + 1
                        if point_release > max_expected_point_release:
                            # out of turn HWE kernel
                            support_duration = 10 + max_expected_point_release * 6
                        else:
                            # treat as regular HWE kernel
                            support_duration = 10 + point_release * 6

                support_end_str = ""
                is_end_of_life = False
                (support_end_year,
                 support_end_month) = get_maintenance_end_date(
                     self.release_dates[release][0], support_duration)
                is_end_of_life = (now.year > support_end_year
                                  or (now.year == support_end_year
                                      and now.month > support_end_month))
                if not is_end_of_life:
                    support_end_str = "%s %s" % (locale.nl_langinfo(
                        getattr(locale, "MON_%d" % support_end_month)),
                                                 support_end_year)

                kernel_support_info[release].append([
                    page_label, support_duration, support_end_str,
                    is_end_of_life
                ])

        kernel_list_prelim.sort(reverse=True)
        kernel_list = []
        supported_kernels = {}

        self.installed_kernels = []
        for kernel in kernel_list_prelim:
            (version_id, version, pkg_version, kernel_type, page_label, label,
             installed, used, title, installable, origin, release,
             support_duration) = kernel
            support_status = ""
            newest_supported_in_series = False
            if support_duration and origin == "1":
                if release in kernel_support_info.keys():
                    support_info = [
                        x for x in kernel_support_info[release]
                        if x[0] == page_label
                    ]
                else:
                    support_info = None
                if support_info:
                    (page_label, support_duration, support_end_str,
                     is_end_of_life) = support_info[0]
                    if support_end_str:
                        if not kernel_type in supported_kernels.keys():
                            supported_kernels[kernel_type] = []
                        if not page_label in supported_kernels[kernel_type]:
                            supported_kernels[kernel_type].append(page_label)
                            support_status = '%s %s' % (_("Supported until"),
                                                        support_end_str)
                            newest_supported_in_series = True
                        else:
                            support_status = _("Superseded")
                    elif is_end_of_life:
                        support_status = _("End of Life")
            else:
                support_status = _("Unsupported")
            if installed:
                self.installed_kernels.append((kernel_type, version))
                if not used:
                    Gdk.threads_enter()
                    self.button_massremove.set_sensitive(True)
                    Gdk.threads_leave()
                    self.remove_kernels_listbox.append(
                        MarkKernelRow(
                            Kernel(version, kernel_type, origin,
                                   installed), self.marked_kernels, version_id,
                            newest_supported_in_series))

            kernel_list.append([
                version_id, version, pkg_version, kernel_type, page_label,
                label, installed, used, title, installable, origin,
                support_status
            ])
        del (kernel_list_prelim)

        # add kernels to UI
        Gdk.threads_enter()
        pages_needed_sort.sort(reverse=True)
        for page in pages_needed_sort:
            page = page[1]
            scw = Gtk.ScrolledWindow()
            scw.set_shadow_type(Gtk.ShadowType.IN)
            list_box = Gtk.ListBox()
            list_box.set_header_func(list_header_func, None)
            list_box.set_selection_mode(Gtk.SelectionMode.NONE)
            list_box.set_activate_on_single_click(True)
            scw.add(list_box)
            self.stack.add_titled(scw, page, page)

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

            list_box.connect("row_activated", self.on_row_activated)
        Gdk.threads_leave()
Esempio n. 6
0
    def __init__(self, application):
        self.application = application
        self.application.window.set_sensitive(False)
        gladefile = "/usr/share/linuxmint/mintupdate/kernels.ui"
        builder = Gtk.Builder()
        builder.set_translation_domain("mintupdate")
        builder.add_from_file(gladefile)
        self.window = builder.get_object("window1")
        self.window.set_title(_("Kernels"))
        listbox_series = builder.get_object("listbox_series")
        scrolled_series = builder.get_object("box7")
        kernel_stack_box = builder.get_object("box1")
        main_box = builder.get_object("main_vbox")
        info_box = builder.get_object("intro_box")
        current_label = builder.get_object("label6")
        self.remove_kernels_window = builder.get_object("confirmation_window")

        self.main_stack = Gtk.Stack()
        self.main_stack.set_transition_type(Gtk.StackTransitionType.CROSSFADE)
        self.window.add(self.main_stack)

        # Setup the kernel warning page
        self.main_stack.add_named(info_box, "info_box")
        builder.get_object("button_continue").connect("clicked",
                                                      self.on_continue_clicked,
                                                      main_box)
        builder.get_object("button_help").connect("clicked", self.show_help)
        hide_info_checkbox = builder.get_object("checkbutton1").connect(
            "toggled", self.on_info_checkbox_toggled)

        # Setup the main kernel page
        stack = Gtk.Stack()
        stack.set_transition_type(Gtk.StackTransitionType.SLIDE_UP_DOWN)

        stack_switcher = Gtk.StackSidebar()
        stack_switcher.set_stack(stack)
        scrolled_series.pack_start(stack_switcher, True, True, 0)
        kernel_stack_box.pack_start(stack, True, True, 0)

        builder.get_object("button_close").connect("clicked", self.hide_window)
        self.window.connect("destroy", self.hide_window)
        builder.get_object("button_massremove").connect(
            "clicked", self.show_remove_kernels_window,
            self.remove_kernels_window)

        # Set up the kernel mass removal confirmation window
        builder.get_object("b_cancel").connect("clicked",
                                               self.on_cancel_clicked,
                                               self.remove_kernels_window)
        builder.get_object("b_remove").connect("clicked",
                                               self.on_remove_clicked,
                                               self.remove_kernels_window)
        remove_kernels_listbox = builder.get_object("box_list")

        # Get distro release dates for support duration calculation
        release_dates = {}
        if os.path.isfile("/usr/share/distro-info/ubuntu.csv"):
            distro_info = open("/usr/share/distro-info/ubuntu.csv",
                               "r").readlines()
            for distro in distro_info[1:]:
                distro = distro.split(",")
                release_date = time.mktime(time.strptime(
                    distro[4], '%Y-%m-%d'))
                release_date = datetime.datetime.fromtimestamp(release_date)
                support_end = time.mktime(
                    time.strptime(distro[5].rstrip(), '%Y-%m-%d'))
                support_end = datetime.datetime.fromtimestamp(support_end)
                release_dates[distro[2]] = [release_date, support_end]
        now = datetime.datetime.now()
        hwe_support_duration = {}

        try:
            kernels = subprocess.check_output(
                "/usr/lib/linuxmint/mintUpdate/checkKernels.py").decode(
                    "utf-8")
        except subprocess.CalledProcessError as e:
            print("Update Manager: Error in checkKernels.py output")
            kernels = e.output.decode("utf-8")
        kernels = kernels.split("\n")
        kernels.sort()
        kernel_list_prelim = []
        pages_needed = []
        pages_needed_sort = []
        self.marked_kernels = []
        for kernel in kernels:
            values = kernel.split('###')
            if len(values) == 11:
                (version_id, version, pkg_version, installed, used,
                 installable, origin, archive, support_duration,
                 kernel_type) = values[1:]
                installed = (installed == "1")
                used = (used == "1")
                title = ""
                if used:
                    title = _("Active")
                elif installed:
                    title = _("Installed")
                if origin == "0":
                    title += " (local)"

                installable = (installable == "1")
                if kernel_type == CONFIGURED_KERNEL_TYPE:
                    label = version
                else:
                    label = version + kernel_type
                page_label = ".".join(label.replace("-", ".").split(".")[:2])

                support_duration = int(support_duration)

                release = archive.split("-", 1)[0]
                if support_duration and origin == "1":
                    if not release in hwe_support_duration:
                        hwe_support_duration[release] = []
                    if not [
                            x for x in hwe_support_duration[release]
                            if x[0] == page_label
                    ]:
                        hwe_support_duration[release].append(
                            [page_label, support_duration])

                kernel_list_prelim.append([version_id, version, pkg_version, kernel_type, page_label, label, installed, used, title, \
                    installable, origin, release, support_duration])
                if page_label not in pages_needed:
                    pages_needed.append(page_label)
                    pages_needed_sort.append([version_id, page_label])

        kernel_support_info = {}
        for release in hwe_support_duration:
            if release not in release_dates.keys():
                continue
            kernel_support_info[release] = []
            kernel_count = len(hwe_support_duration[release])
            time_since_release = (now.year - release_dates[release][0].year
                                  ) * 12 + (now.month -
                                            release_dates[release][0].month)
            for point_release, kernel in enumerate(
                    hwe_support_duration[release]):
                (page_label, support_duration) = kernel
                if support_duration == -1:
                    # here's some magic to determine hwe support duration based on the release cycle
                    # described here: https://wiki.ubuntu.com/Kernel/Support#A18.04.x_Ubuntu_Kernel_Support
                    if point_release >= 4:
                        # Regularly the 4th point release is the next LTS kernel. However, this sequence breaks when
                        # out-of-turn HWE kernels like 4.11 are introduced, so we have to work around that:
                        if kernel_count > 5 and point_release < kernel_count - 1:
                            support_duration = kernel_support_info[release][3][
                                1]
                        # the 4th point release is LTS and scheduled 28 months after original release:
                        elif time_since_release >= 28:
                            support_duration = (release_dates[release][1].year - release_dates[release][0].year) * 12 + \
                                (release_dates[release][1].month - release_dates[release][0].month)
                    if point_release >= 1 and support_duration == -1:
                        # out of turn HWE kernels can be detected quite well at the time of release,
                        # but later on there's no way to know which one was the one that was out of turn
                        max_expected_point_release = (time_since_release -
                                                      3) // 6 + 1
                        if point_release > max_expected_point_release:
                            # out of turn HWE kernel
                            support_duration = 10 + max_expected_point_release * 6
                        else:
                            # treat as regular HWE kernel
                            support_duration = 10 + point_release * 6

                support_end_str = ""
                is_end_of_life = False
                (support_end_year,
                 support_end_month) = get_maintenance_end_date(
                     release_dates[release][0], support_duration)
                is_end_of_life = (now.year > support_end_year
                                  or (now.year == support_end_year
                                      and now.month > support_end_month))
                if not is_end_of_life:
                    support_end_str = "%s %s" % (locale.nl_langinfo(
                        getattr(locale, "MON_%d" % support_end_month)),
                                                 support_end_year)

                kernel_support_info[release].append([
                    page_label, support_duration, support_end_str,
                    is_end_of_life
                ])

        kernel_list_prelim.sort(reverse=True)
        kernel_list = []
        supported_kernels = {}
        for kernel in kernel_list_prelim:
            (version_id, version, pkg_version, kernel_type, page_label, label,
             installed, used, title, installable, origin, release,
             support_duration) = kernel
            if installed and not used:
                remove_kernels_listbox.add(
                    MarkKernelRow(version, kernel_type, self))
            support_status = ""
            if support_duration and origin == "1":
                if release in kernel_support_info.keys():
                    support_info = [
                        x for x in kernel_support_info[release]
                        if x[0] == page_label
                    ]
                else:
                    support_info = None
                if support_info:
                    (page_label, support_duration, support_end_str,
                     is_end_of_life) = support_info[0]
                    if support_end_str:
                        if not kernel_type in supported_kernels.keys():
                            supported_kernels[kernel_type] = []
                        if not page_label in supported_kernels[kernel_type]:
                            supported_kernels[kernel_type].append(page_label)
                            support_status = '%s %s' % (_("Supported until"),
                                                        support_end_str)
                        else:
                            support_status = _("Superseded")
                    elif is_end_of_life:
                        support_status = _("End of Life")
            else:
                support_status = _("Unsupported")
            kernel_list.append([
                version_id, version, pkg_version, kernel_type, page_label,
                label, installed, used, title, installable, origin,
                support_status
            ])
        del (kernel_list_prelim)
        pages_needed_sort.sort(reverse=True)

        pages_needed_sort.sort(reverse=True)
        for page in pages_needed_sort:
            page = page[1]
            scw = Gtk.ScrolledWindow()
            scw.set_shadow_type(Gtk.ShadowType.IN)
            list_box = Gtk.ListBox()
            list_box.set_header_func(list_header_func, None)
            list_box.set_selection_mode(Gtk.SelectionMode.NONE)
            list_box.set_activate_on_single_click(True)
            scw.add(list_box)
            stack.add_titled(scw, page, page)
            # stack_switcher.add_titled(page, page)

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

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

        self.main_stack.add_named(main_box, "main_box")

        if self.application.settings.get_boolean("hide-kernel-update-warning"):
            self.main_stack.set_visible_child(main_box)
        else:
            self.main_stack.set_visible_child(info_box)

        # Center on main window
        window_size = self.window.get_size()
        parent_size = self.application.window.get_size()
        parent_position = self.application.window.get_position()
        parent_center_x = parent_position.root_x + parent_size.width / 2
        parent_center_y = parent_position.root_y + parent_size.height / 2
        self.window.move(parent_center_x - window_size.width / 2,
                         parent_center_y - window_size.height / 2)

        self.window.show_all()
Esempio n. 7
0
    def build_kernels_list(self):
        # get list of installed and available kernels from apt
        now = datetime.now()
        hwe_support_duration = {}

        kernels = subprocess.run(["/usr/lib/linuxmint/mintUpdate/checkKernels.py", CONFIGURED_KERNEL_TYPE],
            stdout=subprocess.PIPE).stdout.decode()
        kernels = kernels.split("\n")
        kernels.sort()
        kernel_list_prelim = []
        pages_needed = []
        pages_needed_sort = []
        self.marked_kernels = []
        for kernel in kernels:
            values = kernel.split('###')
            if len(values) == 11:
                (version_id, version, pkg_version, installed, used, installable, origin, archive, support_duration, kernel_type) = values[1:]
                installed = (installed == "1")
                used = (used == "1")
                title = ""
                if used:
                    title = _("Active")
                    # ACTIVE_KERNEL_VERSION is used by the MarkKernelRow class
                    global ACTIVE_KERNEL_VERSION
                    ACTIVE_KERNEL_VERSION = version_id
                elif installed:
                    title = _("Installed")

                installable = (installable == "1")
                if kernel_type == CONFIGURED_KERNEL_TYPE:
                    label = version
                else:
                    label = version + kernel_type
                    self.allow_kernel_type_selection = True
                page_label = ".".join(label.replace("-",".").split(".")[:2])

                support_duration = int(support_duration)

                release = archive.split("-", 1)[0]
                if support_duration and origin == "1":
                    if not release in hwe_support_duration:
                        hwe_support_duration[release] = []
                    if not [x for x in hwe_support_duration[release] if x[0] == page_label]:
                        hwe_support_duration[release].append([page_label, support_duration])

                kernel_list_prelim.append([version_id, version, pkg_version, kernel_type, page_label, label, installed, used, title,
                    installable, origin, release, support_duration])
                if page_label not in pages_needed:
                    pages_needed.append(page_label)
                    pages_needed_sort.append([version_id, page_label])

        # get kernel support duration
        kernel_support_info = {}
        for release in hwe_support_duration:
            if release not in self.release_dates.keys():
                continue
            kernel_support_info[release] = []
            kernel_count = len(hwe_support_duration[release])
            time_since_release = (now.year - self.release_dates[release][0].year) * 12 + (now.month - self.release_dates[release][0].month)
            for point_release, kernel in enumerate(hwe_support_duration[release]):
                (page_label, support_duration) = kernel
                if support_duration == -1:
                    # here's some magic to determine hwe support duration based on the release cycle
                    # described here: https://wiki.ubuntu.com/Kernel/Support#A18.04.x_Ubuntu_Kernel_Support
                    if point_release >= 4:
                        # Regularly the 4th point release is the next LTS kernel. However, this sequence breaks when
                        # out-of-turn HWE kernels like 4.11 are introduced, so we have to work around that:
                        if kernel_count > 5 and point_release < kernel_count - 1:
                            support_duration = kernel_support_info[release][3][1]
                        # the 4th point release is LTS and scheduled 28 months after original release:
                        elif time_since_release >= 28:
                            support_duration = (self.release_dates[release][1].year - self.release_dates[release][0].year) * 12 + \
                                (self.release_dates[release][1].month - self.release_dates[release][0].month)
                    if point_release >= 1 and support_duration == -1:
                        # out of turn HWE kernels can be detected quite well at the time of release,
                        # but later on there's no way to know which one was the one that was out of turn
                        max_expected_point_release = (time_since_release - 3) // 6 + 1
                        if point_release > max_expected_point_release:
                            # out of turn HWE kernel
                            support_duration = 10 + max_expected_point_release * 6
                        else:
                            # treat as regular HWE kernel
                            support_duration = 10 + point_release * 6

                support_end_str = ""
                is_end_of_life = False
                (support_end_year, support_end_month) = get_maintenance_end_date(self.release_dates[release][0], support_duration)
                is_end_of_life = (now.year > support_end_year or (now.year == support_end_year and now.month > support_end_month))
                if not is_end_of_life:
                    support_end_str = "%s %s" % (locale.nl_langinfo(getattr(locale,"MON_%d" %support_end_month)), support_end_year)

                kernel_support_info[release].append([page_label, support_duration, support_end_str, is_end_of_life])

        kernel_list_prelim.sort(reverse=True)
        kernel_list = []
        supported_kernels = {}

        self.installed_kernels = []
        for kernel in kernel_list_prelim:
            (version_id, version, pkg_version, kernel_type, page_label, label, installed, used, title, installable, origin, release, support_duration) = kernel
            support_status = ""
            newest_supported_in_series = False
            if support_duration and origin == "1":
                if release in kernel_support_info.keys():
                    support_info = [x for x in kernel_support_info[release] if x[0] == page_label]
                else:
                    support_info = None
                if support_info:
                    (page_label, support_duration, support_end_str, is_end_of_life) = support_info[0]
                    if support_end_str:
                        if not kernel_type in supported_kernels.keys():
                            supported_kernels[kernel_type] = []
                        if not page_label in supported_kernels[kernel_type]:
                            supported_kernels[kernel_type].append(page_label)
                            support_status = '%s %s' % (_("Supported until"), support_end_str)
                            newest_supported_in_series = True
                        else:
                            support_status = _("Superseded")
                    elif is_end_of_life:
                        support_status = _("End of Life")
            else:
                support_status = _("Unsupported")
            if installed:
                self.installed_kernels.append((kernel_type, version))
                if not used:
                    self.button_massremove.set_sensitive(True)
                    self.remove_kernels_listbox.append(MarkKernelRow(Kernel(version, kernel_type, origin, installed),
                                                                            self.marked_kernels, version_id,
                                                                            newest_supported_in_series))

            kernel_list.append([version_id, version, pkg_version, kernel_type, page_label, label,
                                installed, used, title, installable, origin, support_status])
        del(kernel_list_prelim)

        # add kernels to UI
        pages_needed_sort.sort(reverse=True)
        for page in pages_needed_sort:
            page = page[1]
            scw = Gtk.ScrolledWindow()
            scw.set_shadow_type(Gtk.ShadowType.IN)
            list_box = Gtk.ListBox()
            list_box.set_header_func(list_header_func, None)
            list_box.set_selection_mode(Gtk.SelectionMode.NONE)
            list_box.set_activate_on_single_click(True)
            scw.add(list_box)
            self.stack.add_titled(scw, page, page)

            for kernel in kernel_list:
                (version_id, version, pkg_version, kernel_type, page_label, label, installed, used, title, installable, origin, support_status) = kernel
                if used:
                    currently_using = _("You are currently using the following kernel:")
                    self.current_label.set_markup(f"<b>{currently_using} {label}{kernel_type}{f' ({support_status})' if support_status else ''}</b>")
                if page_label == page:
                    row = KernelRow(version, pkg_version, kernel_type, label, installed, used, title,
                        installable, origin, support_status, self.window, self.application, self)
                    list_box.add(row)

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