Merge ~pieq/bugit/+git/qabro:no-sudo into bugit:master

Proposed by Pierre Equoy
Status: Merged
Approved by: Pierre Equoy
Approved revision: e0a2642e5da27b1fffc41451f8790a292d665579
Merged at revision: 64db5e1c5e357bf4254f99eb5a8e8513804b2b93
Proposed branch: ~pieq/bugit/+git/qabro:no-sudo
Merge into: bugit:master
Diff against target: 182 lines (+47/-33)
7 files modified
README (+3/-5)
qabro/__init__.py (+14/-17)
qabro/__version__.py (+1/-1)
qabro/bug_assistant.py (+15/-9)
snap/hooks/install (+8/-0)
snap/hooks/remove (+4/-0)
snap/snapcraft.yaml (+2/-1)
Reviewer Review Type Date Requested Status
Pierre Equoy (community) Approve
Review via email: mp+348449@code.launchpad.net

Description of the change

Remove the need for sudo and adds the dbus-launch command in the snap to allow Launchpad authorization page to automatically load in the default Web browser if qabro is launched on a desktop image.

To post a comment you must log in.
Revision history for this message
Pierre Equoy (pieq) wrote :

Self-approved

review: Approve
Revision history for this message
Pierre Equoy (pieq) wrote :

Tested on:

- 18.04 desktop
- 18.04 server
- Ubuntu Core 16

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README b/README
2index 21dade0..99917b2 100644
3--- a/README
4+++ b/README
5@@ -14,15 +14,13 @@ Ubuntu Core and Ubuntu classic systems.
6 Installation
7 ------------
8
9-$ sudo snap install qabro --devmode
10+$ snap install qabro --devmode
11
12
13 Usage
14 -----
15
16-`sudo` is required to run the app:
17-
18-$ sudo qabro
19+$ qabro
20
21 You will be presented with a text user interface (TUI) to fill the important
22 information (bug title, description, status, etc.).
23@@ -34,4 +32,4 @@ report.
24
25 If you want to submit your issue to the Staging instance of Launchpad, use:
26
27-$ sudo APPORT_STAGING=1 qabro
28+$ APPORT_STAGING=1 qabro
29diff --git a/qabro/__init__.py b/qabro/__init__.py
30index ddc45b8..83c6b75 100644
31--- a/qabro/__init__.py
32+++ b/qabro/__init__.py
33@@ -7,24 +7,21 @@ from bug_assistant import BugAssistant
34 from ui import ReportScreen
35
36 def main():
37- if os.getenv('SUDO_USER'):
38- snap_name = os.getenv('SNAP_NAME')
39- code = subprocess.call('snap list {} | grep devmode'.format(snap_name),
40- stdout=subprocess.PIPE,
41- stderr=subprocess.PIPE,
42- shell=True
43- )
44- if code == 0:
45- logfile = os.path.join(os.getenv('SNAP_DATA'), 'qabro.log')
46- logging.basicConfig(filename=logfile,
47- format='%(asctime)s - %(levelname)s - %(message)s',
48- level=logging.ERROR
49- )
50- start_ui()
51- else:
52- sys.exit("This tool requires --devmode option to run properly.")
53+ snap_name = os.getenv('SNAP_NAME')
54+ code = subprocess.call('snap list {} | grep devmode'.format(snap_name),
55+ stdout=subprocess.PIPE,
56+ stderr=subprocess.PIPE,
57+ shell=True
58+ )
59+ if code == 0:
60+ logfile = os.path.join(os.getenv('SNAP_USER_COMMON'), 'qabro.log')
61+ logging.basicConfig(filename=logfile,
62+ format='%(asctime)s - %(levelname)s - %(message)s',
63+ level=logging.ERROR
64+ )
65+ start_ui()
66 else:
67- sys.exit("Please run this tool using sudo!")
68+ sys.exit("This tool requires --devmode option to run properly.")
69
70 def start_ui():
71 ui = ReportScreen()
72diff --git a/qabro/__version__.py b/qabro/__version__.py
73index e83815e..72c0657 100644
74--- a/qabro/__version__.py
75+++ b/qabro/__version__.py
76@@ -1,5 +1,5 @@
77 __title__ = 'qabro'
78-__version__ = '0.4'
79+__version__ = '0.5'
80 __description__ = 'Report bug information with attachments in Launchpad'
81 __author__ = 'Pierre Equoy'
82 __author_email__ = 'pierre.equoy@canonical.com'
83diff --git a/qabro/bug_assistant.py b/qabro/bug_assistant.py
84index bd030f2..ea7c131 100644
85--- a/qabro/bug_assistant.py
86+++ b/qabro/bug_assistant.py
87@@ -190,7 +190,8 @@ class AttachmentAssistant:
88 data=attachments[a])
89
90 def run_attachment_methods(self):
91- """Runs all the methods in the class whose names start with `attach_`."""
92+ """Runs the different attachment methods to add logs to the
93+ attachments dictionary."""
94 self.attach_snaplist()
95 self.attach_sosreport()
96 if 'include_checkbox_session' in self.options and self.options['include_checkbox_session']:
97@@ -198,15 +199,19 @@ class AttachmentAssistant:
98
99 def attach_sosreport(self):
100 home_dir = os.getenv('HOME')
101+ conf_file = os.path.expandvars('$SNAP/etc/sos.conf')
102 print("Running sosreport...")
103 try:
104- command = ['sosreport', '--no-report', '--batch',
105- '--tmp-dir', home_dir,
106- '--config-file', os.path.expandvars("$SNAP/etc/sos.conf")
107- ]
108- output = subprocess.check_output(command)
109+ # Call sosreport while preserving the user $PATH when using sudo
110+ # to have access to the sosreport version from the snap
111+ command = ("sudo env \"PATH=$PATH\" sosreport "
112+ "--no-report --batch --tmp-dir {} "
113+ "--config-file {}").format(home_dir, conf_file)
114+ output = subprocess.check_output(command, shell=True)
115 archive_path = output.splitlines()[-6].strip()
116 print("Report generated: {}".format(archive_path))
117+ command = "sudo chown $USER:$USER {}".format(archive_path)
118+ output = subprocess.check_output(command, shell=True)
119 attachment_name = os.path.basename(archive_path)
120 with open(archive_path, mode='rb') as f:
121 data = f.read()
122@@ -228,13 +233,14 @@ class AttachmentAssistant:
123 os.remove(session_tgz)
124
125 # Determine if we use a classic install or a snap install
126- classic_path = os.path.expandvars('/home/$SUDO_USER/.cache/plainbox/sessions')
127+ classic_path = os.path.expandvars('/home/$USER/.cache/plainbox/sessions')
128 rootpath = ''
129 if os.path.exists(classic_path):
130 rootpath = classic_path
131 else:
132- snap_name = subprocess.check_output("snap list | grep checkbox | awk '{print $1}'", shell=True).strip()
133- snap_path = os.path.expandvars('/home/$SUDO_USER/snap/{}/current/plainbox/sessions'.format(snap_name))
134+ snap_command = "snap list | grep checkbox | awk '{print $1}'"
135+ snap_name = subprocess.check_output(snap_command, shell=True).strip()
136+ snap_path = os.path.expandvars("/home/$USER/snap/{}/current/plainbox/sessions".format(snap_name))
137 if os.path.exists(snap_path):
138 rootpath = snap_path
139
140diff --git a/snap/hooks/install b/snap/hooks/install
141new file mode 100755
142index 0000000..aefc3b4
143--- /dev/null
144+++ b/snap/hooks/install
145@@ -0,0 +1,8 @@
146+#!/bin/sh
147+#
148+# This hook allows software requiring sudo (including qabro) to be run without
149+# having to input password.
150+
151+set -e
152+
153+echo "%sudo ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/qabro
154diff --git a/snap/hooks/remove b/snap/hooks/remove
155new file mode 100755
156index 0000000..6a6cfc0
157--- /dev/null
158+++ b/snap/hooks/remove
159@@ -0,0 +1,4 @@
160+#!/bin/sh
161+set -e
162+
163+rm -f /etc/sudoers.d/qabro
164diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
165index 5e8e93e..acff5b6 100644
166--- a/snap/snapcraft.yaml
167+++ b/snap/snapcraft.yaml
168@@ -1,5 +1,5 @@
169 name: qabro
170-version: '0.4'
171+version: '0.5'
172 summary: QA OEM bug reporting tool
173 description: |
174 Tool to generate a Launchpad bug report and attach useful logs (using
175@@ -28,6 +28,7 @@ parts:
176 - urwid
177 stage-packages:
178 - libc6
179+ - dbus-x11
180
181 sosreport:
182 plugin: nil

Subscribers

People subscribed via source and target branches

to all changes: