Merge lp:~dobey/ubuntuone-installer/fix-aptdaemon into lp:ubuntuone-installer

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: 27
Merged at revision: 30
Proposed branch: lp:~dobey/ubuntuone-installer/fix-aptdaemon
Merge into: lp:ubuntuone-installer
Diff against target: 203 lines (+78/-49)
2 files modified
ubuntuone/installer/gui.py (+58/-45)
ubuntuone/installer/tests/test_gui.py (+20/-4)
To merge this branch: bzr merge lp:~dobey/ubuntuone-installer/fix-aptdaemon
Reviewer Review Type Date Requested Status
Mike McCracken (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+106693@code.launchpad.net

Commit message

Add handling of errors for cache update and install
Add a page for displaying error information, and to try again or cancel
Update the entire cache, not only the PPA cache that we aren't adding
Remove the code to add the stable PPA as it is unneeded/unused

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) :
review: Approve
Revision history for this message
Mike McCracken (mikemc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/installer/gui.py'
2--- ubuntuone/installer/gui.py 2012-03-13 20:24:31 +0000
3+++ ubuntuone/installer/gui.py 2012-05-21 19:06:19 +0000
4@@ -20,6 +20,7 @@
5 import gettext
6 import os
7
8+from aptdaemon.enums import EXIT_SUCCESS
9 from gi.repository import Gtk, GObject, GLib, Gdk, GdkPixbuf, Pango
10 from ubuntuone.installer import (CLIENT_SHELL_PACKAGE,
11 CONTROL_PANEL_COMMAND,
12@@ -163,6 +164,15 @@
13 self.__notebook.append_page(self.__progress_page, None)
14 self.__progress_page.show()
15
16+ # Label widget for error text
17+ self.__err_label = Gtk.Label('')
18+ self.__err_label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
19+ self.__err_label.set_line_wrap(True)
20+
21+ self.__error_page = self.__construct_error_page()
22+ self.__notebook.append_page(self.__error_page, None)
23+ self.__error_page.show()
24+
25 vbox.pack_start(self.__notebook, False, False, 0)
26 self.__notebook.show()
27
28@@ -181,13 +191,20 @@
29
30 self.__main_button = Gtk.Button.new_with_mnemonic(_(u'I_nstall'))
31 self.__main_button.set_image(Gtk.Image.new_from_stock(
32- Gtk.STOCK_OK, Gtk.IconSize.BUTTON))
33+ Gtk.STOCK_EXECUTE, Gtk.IconSize.BUTTON))
34 self.__main_button.connect('clicked', lambda x: self.emit(
35 'response', Gtk.ResponseType.OK))
36 self.__action_area.add(self.__main_button)
37 self.__main_button.grab_focus()
38 self.__main_button.show()
39
40+ # Button for error conditions
41+ self.__close_button = Gtk.Button.new_from_stock(Gtk.STOCK_CLOSE)
42+ self.__close_button.connect('clicked', lambda x: self.emit(
43+ 'response', Gtk.ResponseType.CANCEL))
44+ self.__action_area.add(self.__close_button)
45+
46+ # Button for the external link
47 self.__lm_button = Gtk.LinkButton.new_with_label(
48 'https://one.ubuntu.com/', _(u'Learn more'))
49 self.__action_area.add(self.__lm_button)
50@@ -336,42 +353,45 @@
51
52 return page
53
54- def __get_series(self):
55- """Get the series we're running on."""
56- on_ubuntu = False
57- series = None
58-
59- def get_value(keypair):
60- return keypair.split('=')[1].strip()
61-
62- try:
63- with open('/etc/lsb-release', 'r') as f:
64- for line in f.readlines():
65- if line.startswith('DISTRIB_ID'):
66- on_ubuntu = get_value(line) == u'Ubuntu'
67- if line.startswith('DISTRIB_CODENAME'):
68- series = get_value(line)
69- if not on_ubuntu or series is None:
70- raise UnsupportedDistribution(
71- 'This distribution is not supported by Ubuntu One.')
72- except (OSError, IOError, UnsupportedDistribution), error:
73- self.__got_error(error)
74-
75- return series
76+ def __construct_error_page(self):
77+ """A page for showing errors to the user."""
78+ page = Gtk.HBox()
79+ page.set_border_width(24)
80+ page.set_spacing(12)
81+ page.show()
82+
83+ image = Gtk.Image.new_from_stock(Gtk.STOCK_DIALOG_ERROR,
84+ Gtk.IconSize.DIALOG)
85+ image.set_alignment(0.5, 0.0)
86+ page.pack_start(image, False, False, 0)
87+ image.show()
88+
89+ # Align and pack the error label
90+ self.__err_label.set_alignment(0.0, 0.0)
91+ page.pack_start(self.__err_label, True, True, 0)
92+ self.__err_label.show()
93+
94+ return page
95
96 def __got_error(self, error):
97 """Got an error trying to set up Ubuntu One."""
98- print error
99- Gtk.main_quit()
100+ self.__cancel_button.hide()
101+ self.__main_button.show()
102+ self.__close_button.show()
103+ self.__err_label.set_text(error)
104+ self.__notebook.set_current_page(2)
105
106 @inline_callbacks
107 def __install_u1(self, *args, **kwargs):
108 """Install the packages."""
109 self.__apt_progress.set_fraction(0.0)
110
111- def finished(*args, **kwargs):
112- GLib.spawn_command_line_async(CONTROL_PANEL_COMMAND)
113- Gtk.main_quit()
114+ def finished(transaction, exit_status, *args, **kwargs):
115+ if exit_status != EXIT_SUCCESS:
116+ self.__got_error(transaction.error_details)
117+ else:
118+ GLib.spawn_command_line_async(CONTROL_PANEL_COMMAND)
119+ Gtk.main_quit()
120
121 transaction = yield self.client.install_packages(
122 package_names=self.__get_package_list())
123@@ -383,23 +403,15 @@
124 def __update_cache(self, *args, **kwargs):
125 """Update the cache."""
126 self.__apt_progress.set_fraction(0.0)
127- transaction = yield self.client.update_cache(
128- sources_list='ubuntuone-stable-ppa.list')
129- transaction.connect('finished', self.__install_u1)
130- self.__apt_progress.set_transaction(transaction)
131- transaction.run()
132-
133- @inline_callbacks
134- def __add_stable_ppa(self):
135- """Add the Ubuntu One 'stable' PPA to apt."""
136- transaction = yield self.client.add_repository(
137- src_type='deb',
138- uri='http://ppa.launchpad.net/ubuntuone/stable/ubuntu',
139- dist=self.__get_series(),
140- comps=['main'],
141- comment='added by Ubuntu One installer',
142- sourcesfile='ubuntuone-stable-ppa.list')
143- transaction.connect('finished', self.__update_cache)
144+
145+ def finished(transaction, exit_status, *args, **kwargs):
146+ if exit_status != EXIT_SUCCESS:
147+ self.__got_error(transaction.error_details)
148+ else:
149+ self.__install_u1()
150+
151+ transaction = yield self.client.update_cache()
152+ transaction.connect('finished', finished)
153 self.__apt_progress.set_transaction(transaction)
154 transaction.run()
155
156@@ -408,6 +420,7 @@
157 # Hide the buttons
158 self.__cancel_button.hide()
159 self.__main_button.hide()
160+ self.__close_button.hide()
161
162 # Switch to the progress page
163 self.__notebook.set_current_page(1)
164
165=== modified file 'ubuntuone/installer/tests/test_gui.py'
166--- ubuntuone/installer/tests/test_gui.py 2012-02-17 16:01:23 +0000
167+++ ubuntuone/installer/tests/test_gui.py 2012-05-21 19:06:19 +0000
168@@ -38,15 +38,31 @@
169
170 def test_page_switched(self):
171 """Test the page switching."""
172- #self.assertEquals(self.dlg.active_page, 0)
173+ #self.assertEqual(self.dlg.active_page, 0)
174 self.dlg.response(Gtk.ResponseType.OK)
175- self.assertEquals(self.dlg.active_page, 1)
176+ self.assertEqual(self.dlg.active_page, 1)
177
178 def test_initial_page(self):
179 """Test the initial info page."""
180- self.assertEquals(self.dlg.active_page, 0)
181+ self.assertEqual(self.dlg.active_page, 0)
182
183 def test_progress_page(self):
184 """Test the install progresss page."""
185 self.dlg.response(Gtk.ResponseType.OK)
186- self.assertEquals(self.dlg.active_page, 1)
187+ self.assertEqual(self.dlg.active_page, 1)
188+
189+ def test_error_page(self):
190+ """Test the error page."""
191+ error = u'Just an error.'
192+ self.dlg._Window__got_error(error)
193+ self.assertEqual(self.dlg.active_page, 2)
194+ self.assertEqual(error, self.dlg._Window__err_label.get_text())
195+
196+ def test_update_cache(self):
197+ """Test that updating cache succeeds."""
198+ test_update_cache.skip = 'Need to test that cache update works.'
199+
200+ def test_update_cache_without_network(self):
201+ """Test that updating cache fails cleanly without network."""
202+ test_update_cache_without_network.skip = \
203+ 'Need to test that we do the right thing on cache update failure.'

Subscribers

People subscribed via source and target branches

to all changes: