Merge ~waveform/ubiquity:soup3 into ubiquity:main

Proposed by Dave Jones
Status: Merged
Merged at revision: e9b4f67c0fc4dcb893bf36c31cd89fb2f382d438
Proposed branch: ~waveform/ubiquity:soup3
Merge into: ubiquity:main
Diff against target: 126 lines (+46/-27)
2 files modified
debian/changelog (+6/-0)
ubiquity/plugins/ubi-timezone.py (+40/-27)
Reviewer Review Type Date Requested Status
Steve Langasek Approve
Review via email: mp+464248@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Dave Jones (waveform) wrote :

This merge fixes the oem-config process on preinstalled desktop images (most notably, the Ubuntu Desktop for Raspberry Pi images) by updating the ubi-timezone plugin to support the libsoup3 API. This is now required by other components, and libsoup2.4 and libsoup3 cannot co-exist in the process, so ubi-timezone must be updated.

The change has been successfully tested on the noble Desktop for Pi images, with networking present, absent, and initially present but removed when the plugin is active (to test the cancellation pathway).

Revision history for this message
Steve Langasek (vorlon) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 62abe5b..e9e8ab2 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,9 @@
6+ubiquity (24.04.5) UNRELEASED; urgency=medium
7+
8+ * plugins/ubi-timezone.py: Update to support libsoup3 API (LP: #1987454)
9+
10+ -- Dave Jones <dave.jones@canonical.com> Sun, 14 Apr 2024 14:23:58 +0100
11+
12 ubiquity (24.04.4) noble; urgency=medium
13
14 * Bump webkit gir dependency to 4.1.
15diff --git a/ubiquity/plugins/ubi-timezone.py b/ubiquity/plugins/ubi-timezone.py
16index 4f2fdb7..3806a1a 100644
17--- a/ubiquity/plugins/ubi-timezone.py
18+++ b/ubiquity/plugins/ubi-timezone.py
19@@ -95,7 +95,7 @@ class PageGtk(plugin.PluginUI):
20 def changed(self, entry):
21 import gi
22 gi.require_version('Soup', '3.0')
23- from gi.repository import Gtk, GObject, GLib, Soup
24+ from gi.repository import Gtk, GObject, GLib, Gio, Soup
25
26 text = misc.utf8(self.city_entry.get_text())
27 if not text:
28@@ -114,15 +114,17 @@ class PageGtk(plugin.PluginUI):
29 self.geoname_session = Soup.Session()
30 url = _geoname_url % (quote(text), misc.get_release().version)
31 message = Soup.Message.new('GET', url)
32- message.request_headers.append('User-agent', 'Ubiquity/1.0')
33+ message.get_request_headers().replace('User-agent', 'Ubiquity/1.0')
34 self.geoname_session.abort()
35 if self.geoname_timeout_id is not None:
36 GLib.source_remove(self.geoname_timeout_id)
37+ cancellable = Gio.Cancellable()
38 self.geoname_timeout_id = \
39 GLib.timeout_add_seconds(2, self.geoname_timeout,
40- (text, model))
41- self.geoname_session.queue_message(message, self.geoname_cb,
42- (text, model))
43+ (text, model, cancellable))
44+ self.geoname_session.send_and_read_async(
45+ message, GLib.PRIORITY_DEFAULT, cancellable, self.geoname_cb,
46+ (text, model))
47
48 def geoname_add_tzdb(self, text, model):
49 if len(model):
50@@ -147,16 +149,17 @@ class PageGtk(plugin.PluginUI):
51 str(loc.latitude), str(loc.longitude)])
52
53 def geoname_timeout(self, user_data):
54- text, model = user_data
55+ text, model, cancellable = user_data
56+ cancellable.cancel()
57 self.geoname_add_tzdb(text, model)
58 self.geoname_timeout_id = None
59 self.city_entry.get_completion().set_model(model)
60 return False
61
62- def geoname_cb(self, session, message, user_data):
63+ def geoname_cb(self, session, result, user_data):
64 import syslog
65 import json
66- from gi.repository import GLib, Soup
67+ from gi.repository import GLib, Gio, Soup
68
69 text, model = user_data
70
71@@ -165,27 +168,37 @@ class PageGtk(plugin.PluginUI):
72 self.geoname_timeout_id = None
73 self.geoname_add_tzdb(text, model)
74
75- if message.status_code == Soup.KnownStatusCode.CANCELLED:
76- # Silently ignore cancellation.
77- pass
78- elif message.status_code != Soup.KnownStatusCode.OK:
79- # Log but otherwise ignore failures.
80- syslog.syslog(
81- 'Geoname lookup for "%s" failed: %d %s' %
82- (text, message.status_code, message.reason_phrase))
83+ message = session.get_async_result_message(result)
84+ try:
85+ response = session.send_and_read_finish(result)
86+ except GLib.GError as err:
87+ if err.code == Gio.IOErrorEnum.CANCELLED:
88+ # Silently ignore cancellation.
89+ pass
90+ else:
91+ # Log but otherwise ignore failures.
92+ syslog.syslog(
93+ 'Geoname lookup for "%s" failed: %s' % (text, err.message))
94 else:
95- try:
96- for result in json.loads(message.response_body.data):
97- model.append([
98- result['name'], result['admin1'], result['country'],
99- result['latitude'], result['longitude']])
100-
101- # Only cache positive results.
102- self.geoname_cache[text] = model
103-
104- except ValueError:
105+ if message.get_status() != Soup.Status.OK:
106+ # Log but otherwise ignore failures
107 syslog.syslog(
108- 'Server return does not appear to be valid JSON.')
109+ 'Geoname lookup for "%s" failed: %s %s' %
110+ (text, message.get_status(), message.get_reason_phrase()))
111+ else:
112+ try:
113+ for result in json.loads(response.get_data().decode()):
114+ model.append([
115+ result['name'], result['admin1'],
116+ result['country'], result['latitude'],
117+ result['longitude']])
118+
119+ # Only cache positive results.
120+ self.geoname_cache[text] = model
121+
122+ except ValueError:
123+ syslog.syslog(
124+ 'Server return does not appear to be valid JSON.')
125
126 self.city_entry.get_completion().set_model(model)
127

Subscribers

People subscribed via source and target branches