Merge ~laney/ubiquity:apt-update-oem into ubiquity:master

Proposed by Iain Lane
Status: Merged
Merge reported by: Iain Lane
Merged at revision: 8d93a5d10b4840130ddfbce1aae067579549a7bb
Proposed branch: ~laney/ubiquity:apt-update-oem
Merge into: ubiquity:master
Diff against target: 103 lines (+56/-1)
3 files modified
ubiquity/frontend/base.py (+3/-0)
ubiquity/frontend/gtk_ui.py (+44/-0)
ubiquity/plugins/ubi-prepare.py (+9/-1)
Reviewer Review Type Date Requested Status
Dimitri John Ledkov lgtm Approve
Review via email: mp+387747@code.launchpad.net

Commit message

gtk_ui, prepare: Run 'apt update' before installing OEM metapackages

We need to pick up any which might have been released after the ISO was
created.

LP: #1888241

To post a comment you must log in.
Revision history for this message
Dimitri John Ledkov (xnox) :
review: Approve (lgtm)
Revision history for this message
Colin Watson (cjwatson) :
Revision history for this message
Iain Lane (laney) :
Revision history for this message
Iain Lane (laney) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/ubiquity/frontend/base.py b/ubiquity/frontend/base.py
2index 0bbd152..1e89180 100644
3--- a/ubiquity/frontend/base.py
4+++ b/ubiquity/frontend/base.py
5@@ -475,3 +475,6 @@ class BaseFrontend:
6
7 def set_online_state(self, state):
8 pass
9+
10+ def save_oem_metapackages_list(self, wait_finished=False):
11+ pass
12diff --git a/ubiquity/frontend/gtk_ui.py b/ubiquity/frontend/gtk_ui.py
13index 8da7e5c..52f8c17 100644
14--- a/ubiquity/frontend/gtk_ui.py
15+++ b/ubiquity/frontend/gtk_ui.py
16@@ -255,6 +255,7 @@ class Wizard(BaseFrontend):
17 self.screen_reader = False
18 self.orca_process = None
19 self.a11y_settings = None
20+ self.have_apt_updated = False
21
22 # To get a "busy mouse":
23 self.watch = Gdk.Cursor.new(Gdk.CursorType.WATCH)
24@@ -406,8 +407,47 @@ class Wizard(BaseFrontend):
25 ['canberra-gtk-play', '--id=system-ready'],
26 preexec_fn=misc.drop_all_privileges)
27
28+ self.save_oem_metapackages_list()
29+
30+ def save_oem_metapackages_list(self, wait_finished=False):
31+ ''' If we can, update the apt indexes. Then run 'ubuntu-drivers
32+ list-oem' to find any OEM metapackages for this system. If we've
33+ already done this with updated apt indexes before, there's no point
34+ running again, so just return. '''
35+
36+ # We already did it
37+ if self.have_apt_updated:
38+ syslog.syslog(syslog.LOG_INFO, 'We\'ve already apt updated and '
39+ 'run, not doing so again.')
40+ return
41+
42 with misc.raised_privileges():
43+ try:
44+ import apt
45+ syslog.syslog(syslog.LOG_INFO, 'Trying to update apt indexes '
46+ 'to run ubuntu-drivers against fresh data.')
47+ cache = apt.cache.Cache()
48+ cache.update()
49+ cache.open()
50+ self.have_apt_updated = True
51+ except apt.cache.FetchFailedException:
52+ syslog.syslog(syslog.LOG_INFO,
53+ 'Failed to update apt indexes; offline? '
54+ 'Continuing without.')
55+ except apt.cache.LockFailedException:
56+ syslog.syslog(syslog.LOG_WARNING,
57+ 'Failed to update apt indexes, permission '
58+ 'denied: running under test?')
59+
60 if osextras.find_on_path('ubuntu-drivers'):
61+ # We already ran, were offline then, and are still offline, no
62+ # point running again.
63+ if os.path.exists('/run/ubuntu-drivers-oem.autoinstall') and \
64+ not self.have_apt_updated:
65+ return
66+
67+ # It's either the first run or a subsequent one but we now
68+ # managed to update the apt indexes.
69 self.ubuntu_drivers = subprocess.Popen(
70 ['ubuntu-drivers',
71 'list-oem',
72@@ -417,6 +457,10 @@ class Wizard(BaseFrontend):
73 stdout=subprocess.PIPE,
74 stderr=subprocess.DEVNULL)
75
76+ if wait_finished:
77+ self.ubuntu_drivers.communicate()
78+ self.ubuntu_drivers = None
79+
80 def all_children(self, parent):
81 if isinstance(parent, Gtk.Container):
82 def recurse(x, y):
83diff --git a/ubiquity/plugins/ubi-prepare.py b/ubiquity/plugins/ubi-prepare.py
84index af3b4d0..29392d6 100644
85--- a/ubiquity/plugins/ubi-prepare.py
86+++ b/ubiquity/plugins/ubi-prepare.py
87@@ -462,7 +462,15 @@ class Page(plugin.Plugin):
88 with open('/run/ubuntu-drivers-oem.autoinstall', 'r') as f:
89 syslog.syslog(F'ubuntu-drivers list-oem finished with: "{" ".join(f.read().splitlines())}"')
90 except FileNotFoundError:
91- syslog.syslog('ubuntu-drivers list-oem finished with no available packages')
92+ syslog.syslog('ubuntu-drivers list-oem finished with no available packages. Maybe we need to apt update? '
93+ 'Doing that and trying again.')
94+ # We only do this when we really have to since it could be slow: apt update & re-run of ubuntu-drivers
95+ self.frontend.save_oem_metapackages_list(wait_finished=True)
96+ try:
97+ with open('/run/ubuntu-drivers-oem.autoinstall', 'r') as f:
98+ syslog.syslog(F'ubuntu-drivers list-oem finished with: "{" ".join(f.read().splitlines())}"')
99+ except FileNotFoundError:
100+ syslog.syslog('No, we didn\'t find any OEM packages again.')
101
102 if self.should_show_rst_page():
103 if not self.ui.show_rst_page():

Subscribers

People subscribed via source and target branches