~ubuntu-core-dev/update-manager/main

« back to all changes in this revision

Viewing changes to UpdateManager/UpdateManager.py

  • Committer: Brian Murray
  • Date: 2016-07-21 20:30:51 UTC
  • mto: This revision was merged to the branch mainline in revision 2728.
  • Revision ID: brian@canonical.com-20160721203051-rpga5obh3ccb71yu
Include HWE support tools and information. (LP: #1498059)

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
                        DeprecationWarning)
35
35
 
36
36
import apt_pkg
 
37
import distro_info
37
38
import os
38
39
import subprocess
39
40
import sys
48
49
from .UnitySupport import UnitySupport
49
50
from .Dialogs import (DistUpgradeDialog,
50
51
                      ErrorDialog,
 
52
                      HWEUpgradeDialog,
51
53
                      NeedRestartDialog,
52
54
                      NoUpdatesDialog,
 
55
                      PartialUpgradeDialog,
53
56
                      StoppedUpdatesDialog,
54
 
                      PartialUpgradeDialog,
55
57
                      UnsupportedDialog,
56
58
                      UpdateErrorDialog)
57
59
from .MetaReleaseGObject import MetaRelease
60
62
from .Core.MyCache import MyCache
61
63
from .Core.roam import NetworkManagerHelper
62
64
from .Core.UpdateList import UpdateList
 
65
from .Core.utils import get_dist
63
66
from .backend import (InstallBackend,
64
67
                      get_backend)
65
68
 
82
85
        self.cache = None
83
86
        self.update_list = None
84
87
        self.meta_release = None
 
88
        self.hwe_replacement_packages = None
85
89
 
86
90
        # Basic GTK+ parameters
87
91
        self.set_title(_("Software Updater"))
212
216
        update_backend = get_backend(self, InstallBackend.ACTION_UPDATE)
213
217
        self._start_pane(update_backend)
214
218
 
215
 
    def start_install(self):
 
219
    def start_install(self, hwe_upgrade=False):
216
220
        install_backend = get_backend(self, InstallBackend.ACTION_INSTALL)
 
221
        if hwe_upgrade:
 
222
            for pkgname in self.hwe_replacement_packages:
 
223
                self.cache[pkgname].mark_install()
217
224
        self._start_pane(install_backend)
218
225
 
219
226
    def start_available(self, cancelled_update=False, error_occurred=False):
227
234
 
228
235
    def _make_available_pane(self, install_count, need_reboot=False,
229
236
                             cancelled_update=False, error_occurred=False):
 
237
        self._check_hwe_support_status()
230
238
        if install_count == 0:
231
239
            # Need Restart > New Release > No Updates
232
240
            if need_reboot:
233
241
                return NeedRestartDialog(self)
234
 
            pane = self._check_meta_release()
235
 
            if pane:
236
 
                return pane
 
242
            dist_upgrade = self._check_meta_release()
 
243
            if dist_upgrade:
 
244
                return dist_upgrade
237
245
            elif cancelled_update:
238
246
                return StoppedUpdatesDialog(self)
 
247
            elif self.hwe_replacement_packages:
 
248
                return HWEUpgradeDialog(self)
239
249
            else:
240
250
                return NoUpdatesDialog(self, error_occurred=error_occurred)
241
251
        else:
247
257
                header = _("You stopped the check for updates.")
248
258
                desc = _("Updated software is available from "
249
259
                         "a previous check.")
 
260
            # Display HWE updates first as an old HWE stack is vulnerable
 
261
            elif self.hwe_replacement_packages:
 
262
                return HWEUpgradeDialog(self)
250
263
            return UpdatesAvailable(self, header, desc, need_reboot)
251
264
 
252
265
    def start_error(self, is_update_error, header, desc):
303
316
            self.meta_release.connect("done_downloading", Gtk.main_quit)
304
317
        return False
305
318
 
 
319
    def _check_hwe_support_status(self):
 
320
        di = distro_info.UbuntuDistroInfo()
 
321
        codename = get_dist()
 
322
        lts = di.is_lts(codename)
 
323
        if not lts:
 
324
            return None
 
325
        HWE = "/usr/bin/hwe-support-status"
 
326
        if not os.path.exists(HWE):
 
327
            return None
 
328
        cmd = [HWE, "--show-replacements"]
 
329
        self._parse_hwe_support_status(cmd)
 
330
 
 
331
    def _parse_hwe_support_status(self, cmd):
 
332
        try:
 
333
            subprocess.check_output(cmd)
 
334
            # for debugging
 
335
            # print("nothing unsupported running")
 
336
        except subprocess.CalledProcessError as e:
 
337
            if e.returncode == 10:
 
338
                packages = e.output.strip().split()
 
339
                self.hwe_replacement_packages = []
 
340
                for pkgname in packages:
 
341
                    pkgname = pkgname.decode('utf-8')
 
342
                    if pkgname in self.cache and not self.cache[pkgname].is_installed:
 
343
                        self.hwe_replacement_packages.append(pkgname)
 
344
                # for debugging
 
345
                # print(self.hwe_replacement_packages)
 
346
 
306
347
    # fixme: we should probably abstract away all the stuff from libapt
307
348
    def refresh_cache(self):
308
349
        # get the lock
360
401
            self._start_pane(PartialUpgradeDialog(self))
361
402
 
362
403
    def _setup_dbus(self):
363
 
        """ this sets up a dbus listener if none is installed alread """
 
404
        """ this sets up a dbus listener if none is installed already """
364
405
        # check if there is another g-a-i already and if not setup one
365
406
        # listening on dbus
366
407
        try: