Merge ~osomon/ubiquity:impish-live-session-release-notes-1945658 into ubiquity:master

Proposed by Olivier Tilloy
Status: Merged
Merged at revision: 40e86a074c82caad2196f197698294ef1c7ebb1e
Proposed branch: ~osomon/ubiquity:impish-live-session-release-notes-1945658
Merge into: ubiquity:master
Diff against target: 74 lines (+24/-7)
3 files modified
data/ubiquity.desktop.in (+1/-1)
ubiquity/gsettings.py (+4/-6)
ubiquity/misc.py (+19/-0)
Reviewer Review Type Date Requested Status
Jean-Baptiste Lallement Approve
Iain Lane Approve
Review via email: mp+409584@code.launchpad.net

Commit message

Also preserve XDG_DATA_DIRS when running ubiquity in a live session.

This fixes opening the release notes hyperlink (and all other hyperlinks)
with the correct application (firefox vs gedit) (LP: #1945658).

To post a comment you must log in.
Revision history for this message
Iain Lane (laney) wrote :

👍

review: Approve
Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

Maybe move the sudo wrapper to misc.py. WDYT?

Revision history for this message
Olivier Tilloy (osomon) wrote :

Good suggestion. Done.

Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

Approved! thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/data/ubiquity.desktop.in b/data/ubiquity.desktop.in
2index 691f802..3cb3434 100644
3--- a/data/ubiquity.desktop.in
4+++ b/data/ubiquity.desktop.in
5@@ -6,7 +6,7 @@ _Name=Install RELEASE
6 _Comment=Install this system permanently to your hard disk
7 _Keywords=ubiquity;
8 #use sh because pkexec is broken under xfce/lxce http://pad.lv/1193526
9-Exec=sudo --preserve-env=DBUS_SESSION_BUS_ADDRESS,XDG_RUNTIME_DIR sh -c 'ubiquity gtk_ui'
10+Exec=sudo --preserve-env=DBUS_SESSION_BUS_ADDRESS,XDG_DATA_DIRS,XDG_RUNTIME_DIR sh -c 'ubiquity gtk_ui'
11 Icon=ubiquity
12 Terminal=false
13 Categories=GTK;System;Settings;
14diff --git a/ubiquity/gsettings.py b/ubiquity/gsettings.py
15index 7b1cced..d31d044 100644
16--- a/ubiquity/gsettings.py
17+++ b/ubiquity/gsettings.py
18@@ -48,8 +48,7 @@ def get(schema, key, user=None):
19 user = os.getenv("SUDO_USER", os.getenv("USER", "root"))
20
21 subp = subprocess.Popen(
22- ['sudo', '--preserve-env=DBUS_SESSION_BUS_ADDRESS,XDG_RUNTIME_DIR',
23- '-H', '-u', user, 'gsettings', 'get', schema, key],
24+ misc.sudo_wrapper(user) + ['gsettings', 'get', schema, key],
25 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
26 preexec_fn=misc.drop_all_privileges, universal_newlines=True)
27 value = subp.communicate()[0].rstrip('\n')
28@@ -106,8 +105,8 @@ def set(schema, key, value, user=None):
29 value = "true" if value else "false"
30
31 subprocess.call(
32- ['sudo', '--preserve-env=DBUS_SESSION_BUS_ADDRESS,XDG_RUNTIME_DIR',
33- '-H', '-u', user, 'gsettings', 'set', schema, key, str(value)],
34+ misc.sudo_wrapper(user) +
35+ ['gsettings', 'set', schema, key, str(value)],
36 preexec_fn=misc.drop_all_privileges)
37
38
39@@ -127,6 +126,5 @@ def unset(schema, key, user=None):
40 user = os.getenv("SUDO_USER", os.getenv("USER", "root"))
41
42 subprocess.call(
43- ['sudo', '--preserve-env=DBUS_SESSION_BUS_ADDRESS,XDG_RUNTIME_DIR',
44- '-H', '-u', user, 'gsettings', 'reset', schema, key],
45+ misc.sudo_wrapper(user) + ['gsettings', 'reset', schema, key],
46 preexec_fn=misc.drop_all_privileges)
47diff --git a/ubiquity/misc.py b/ubiquity/misc.py
48index bc88d5d..7ff6629 100644
49--- a/ubiquity/misc.py
50+++ b/ubiquity/misc.py
51@@ -1086,4 +1086,23 @@ class SystemdUnitWatcher:
52 raise
53
54
55+def sudo_wrapper(user):
56+ """Return a list of args suitable for use with the subprocess module,
57+ to invoke a command as a given user, while preserving a set of useful
58+ environment variables. Append the command and list of args to be invoked
59+ to the return value of this helper.
60+ """
61+ preserve_env = [
62+ 'DBUS_SESSION_BUS_ADDRESS',
63+ 'XDG_DATA_DIRS',
64+ 'XDG_RUNTIME_DIR',
65+ ]
66+ return [
67+ 'sudo',
68+ '--preserve-env={}'.format(','.join(preserve_env)),
69+ '-H',
70+ '-u', user
71+ ]
72+
73+
74 # vim:ai:et:sts=4:tw=80:sw=4:

Subscribers

People subscribed via source and target branches