Merge update-notifier:list-oem into update-notifier:master

Proposed by Iain Lane
Status: Needs review
Proposed branch: update-notifier:list-oem
Merge into: update-notifier:master
Diff against target: 146 lines (+97/-4)
4 files modified
data/Makefile.am (+1/-1)
data/list-oem-metapackages (+48/-0)
debian/control (+2/-1)
src/update.c (+46/-2)
Reviewer Review Type Date Requested Status
Julian Andres Klode Approve
Review via email: mp+389424@code.launchpad.net

Description of the change

This goes with https://code.launchpad.net/~ubuntu-core-dev/update-manager/oem/+merge/389421

I wanted to have it out of update-manager's process, to keep update-manager always "fast" to launch - running ubuntu-drivers list-oem is pretty slow. It doesn't matter if update-notifier is slow though, since it runs in the background.

To post a comment you must log in.
Revision history for this message
Julian Andres Klode (juliank) :
review: Approve

Unmerged commits

25348c2... by Iain Lane

List OEM metapackages before invoking update-manager

Before invoking update-manager, run a helper script to figure out if
there are any oem-*-meta packages which apply to this system. These are
enablement packages maintained by Canonical which install any tweaks
required by a particular piece of hardware.

The script takes care to exit quickly if it's been run before or if
the system is already enabled.

It uses ubuntu-drivers' python interface, so we need to add a dependency
to make sure that is available.

There will be a companion change in update-manager to consume this list.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/data/Makefile.am b/data/Makefile.am
2index 0cd6d1a..eebbb5d 100644
3--- a/data/Makefile.am
4+++ b/data/Makefile.am
5@@ -13,7 +13,7 @@ policydir = $(datadir)/polkit-1/actions
6 policy_DATA = com.ubuntu.update-notifier.policy
7
8 helperdir = $(libdir)/update-notifier
9-helper_SCRIPTS = apt_check.py apt-cdrom-check cddistupgrader update-motd-reboot-required update-motd-updates-available update-motd-fsck-at-reboot update-motd-hwe-eol backend_helper.py package-data-downloader package-system-locked
10+helper_SCRIPTS = apt_check.py apt-cdrom-check cddistupgrader list-oem-metapackages update-motd-reboot-required update-motd-updates-available update-motd-fsck-at-reboot update-motd-hwe-eol backend_helper.py package-data-downloader package-system-locked
11
12 notifydir = $(datadir)/update-notifier
13 notify_SCRIPTS = notify-reboot-required notify-updates-outdated
14diff --git a/data/list-oem-metapackages b/data/list-oem-metapackages
15new file mode 100755
16index 0000000..1bb6c58
17--- /dev/null
18+++ b/data/list-oem-metapackages
19@@ -0,0 +1,48 @@
20+#!/usr/bin/python3
21+
22+import fnmatch
23+import logging
24+import os
25+import sys
26+
27+import apt
28+import UbuntuDrivers.detect
29+
30+from gi.repository import GLib
31+
32+STAMP_FILE = os.path.join(GLib.get_user_runtime_dir(), "ubuntu-drivers-oem.package-list")
33+
34+
35+def any_oem_metapackages_installed(cache):
36+ installed_oem_packages = (
37+ pkg
38+ for pkg in cache
39+ if fnmatch.fnmatch(pkg.name, "oem-*-meta") and pkg.is_installed
40+ )
41+
42+ # Empty if there are no installed OEM packages
43+ return any((True for _ in installed_oem_packages))
44+
45+
46+def write_oem_metapackage_list(cache, filename):
47+ packages = UbuntuDrivers.detect.system_device_specific_metapackages(
48+ apt_cache=cache
49+ )
50+
51+ if not packages:
52+ return
53+
54+ with open(STAMP_FILE, "w") as f:
55+ f.write("\n".join(packages))
56+
57+
58+if __name__ == "__main__":
59+ if os.path.exists(STAMP_FILE):
60+ sys.exit(0)
61+
62+ cache = apt.Cache()
63+
64+ if any_oem_metapackages_installed(cache):
65+ sys.exit(0)
66+
67+ write_oem_metapackage_list(cache, STAMP_FILE)
68diff --git a/debian/control b/debian/control
69index f629114..776e580 100644
70--- a/debian/control
71+++ b/debian/control
72@@ -53,7 +53,8 @@ Depends: ${shlibs:Depends},
73 python3:any,
74 python3-apt, python3-dbus, python3-debian,
75 python3-debconf | debconf (<< 1.5.64~),
76- patch, update-manager-core (>= 1:17.04.2)
77+ patch, ubuntu-drivers-common,
78+ update-manager-core (>= 1:17.04.2)
79 Recommends: libpam-modules (>= 1.0.1-9ubuntu3)
80 Suggests: policykit-1
81 Description: Files shared between update-notifier and other packages
82diff --git a/src/update.c b/src/update.c
83index 8f20f39..588fa66 100644
84--- a/src/update.c
85+++ b/src/update.c
86@@ -531,6 +531,26 @@ auto_launch_now (TrayApplet *ta)
87 return FALSE;
88 }
89
90+static void
91+launch_update_manager (GPid pid,
92+ gint status,
93+ gpointer user_data G_GNUC_UNUSED)
94+{
95+ g_autoptr(GError) error = NULL;
96+
97+ g_spawn_check_exit_status (status, &error);
98+
99+ /* list-oem-metapackages exited abnormally */
100+ if (error != NULL)
101+ {
102+ g_printerr ("list-oem-metapackages exited abnormally: %s\n", error->message);
103+ return;
104+ }
105+
106+ g_spawn_command_line_async("nice ionice -c3 update-manager "
107+ "--no-update --no-focus-on-map", NULL);
108+}
109+
110 gboolean
111 update_check (TrayApplet *ta)
112 {
113@@ -640,8 +660,32 @@ update_check (TrayApplet *ta)
114 tray_applet_ui_set_visible(ta, FALSE);
115 if (auto_launch_now(ta))
116 {
117- g_spawn_command_line_async("nice ionice -c3 update-manager "
118- "--no-update --no-focus-on-map", NULL);
119+ g_autoptr(GError) error = NULL;
120+ g_autofree gchar *list_oem_metapackages = NULL;
121+ GPid pid;
122+ g_auto(GStrv) argv = g_new0(char *, 2);
123+
124+ argv[0] = g_build_filename (PACKAGE_LIB_DIR,
125+ "update-notifier",
126+ "list-oem-metapackages",
127+ NULL);
128+
129+ g_spawn_async (NULL, /* working_directory */
130+ argv,
131+ NULL, /* envp */
132+ G_SPAWN_DO_NOT_REAP_CHILD,
133+ NULL, /* child_setup */
134+ NULL, /* user_data */
135+ &pid,
136+ &error);
137+
138+ if (error != NULL)
139+ {
140+ g_printerr("Failed to spawn ‘list-oem-metapackages’: %s\n", error->message);
141+ return FALSE;
142+ }
143+
144+ g_child_watch_add (pid, launch_update_manager, NULL);
145 }
146 return TRUE;
147

Subscribers

People subscribed via source and target branches