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
=== modified file 'ubuntuone/installer/gui.py'
--- ubuntuone/installer/gui.py 2012-03-13 20:24:31 +0000
+++ ubuntuone/installer/gui.py 2012-05-21 19:06:19 +0000
@@ -20,6 +20,7 @@
20import gettext20import gettext
21import os21import os
2222
23from aptdaemon.enums import EXIT_SUCCESS
23from gi.repository import Gtk, GObject, GLib, Gdk, GdkPixbuf, Pango24from gi.repository import Gtk, GObject, GLib, Gdk, GdkPixbuf, Pango
24from ubuntuone.installer import (CLIENT_SHELL_PACKAGE,25from ubuntuone.installer import (CLIENT_SHELL_PACKAGE,
25 CONTROL_PANEL_COMMAND,26 CONTROL_PANEL_COMMAND,
@@ -163,6 +164,15 @@
163 self.__notebook.append_page(self.__progress_page, None)164 self.__notebook.append_page(self.__progress_page, None)
164 self.__progress_page.show()165 self.__progress_page.show()
165166
167 # Label widget for error text
168 self.__err_label = Gtk.Label('')
169 self.__err_label.set_ellipsize(Pango.EllipsizeMode.MIDDLE)
170 self.__err_label.set_line_wrap(True)
171
172 self.__error_page = self.__construct_error_page()
173 self.__notebook.append_page(self.__error_page, None)
174 self.__error_page.show()
175
166 vbox.pack_start(self.__notebook, False, False, 0)176 vbox.pack_start(self.__notebook, False, False, 0)
167 self.__notebook.show()177 self.__notebook.show()
168178
@@ -181,13 +191,20 @@
181191
182 self.__main_button = Gtk.Button.new_with_mnemonic(_(u'I_nstall'))192 self.__main_button = Gtk.Button.new_with_mnemonic(_(u'I_nstall'))
183 self.__main_button.set_image(Gtk.Image.new_from_stock(193 self.__main_button.set_image(Gtk.Image.new_from_stock(
184 Gtk.STOCK_OK, Gtk.IconSize.BUTTON))194 Gtk.STOCK_EXECUTE, Gtk.IconSize.BUTTON))
185 self.__main_button.connect('clicked', lambda x: self.emit(195 self.__main_button.connect('clicked', lambda x: self.emit(
186 'response', Gtk.ResponseType.OK))196 'response', Gtk.ResponseType.OK))
187 self.__action_area.add(self.__main_button)197 self.__action_area.add(self.__main_button)
188 self.__main_button.grab_focus()198 self.__main_button.grab_focus()
189 self.__main_button.show()199 self.__main_button.show()
190200
201 # Button for error conditions
202 self.__close_button = Gtk.Button.new_from_stock(Gtk.STOCK_CLOSE)
203 self.__close_button.connect('clicked', lambda x: self.emit(
204 'response', Gtk.ResponseType.CANCEL))
205 self.__action_area.add(self.__close_button)
206
207 # Button for the external link
191 self.__lm_button = Gtk.LinkButton.new_with_label(208 self.__lm_button = Gtk.LinkButton.new_with_label(
192 'https://one.ubuntu.com/', _(u'Learn more'))209 'https://one.ubuntu.com/', _(u'Learn more'))
193 self.__action_area.add(self.__lm_button)210 self.__action_area.add(self.__lm_button)
@@ -336,42 +353,45 @@
336353
337 return page354 return page
338355
339 def __get_series(self):356 def __construct_error_page(self):
340 """Get the series we're running on."""357 """A page for showing errors to the user."""
341 on_ubuntu = False358 page = Gtk.HBox()
342 series = None359 page.set_border_width(24)
343360 page.set_spacing(12)
344 def get_value(keypair):361 page.show()
345 return keypair.split('=')[1].strip()362
346363 image = Gtk.Image.new_from_stock(Gtk.STOCK_DIALOG_ERROR,
347 try:364 Gtk.IconSize.DIALOG)
348 with open('/etc/lsb-release', 'r') as f:365 image.set_alignment(0.5, 0.0)
349 for line in f.readlines():366 page.pack_start(image, False, False, 0)
350 if line.startswith('DISTRIB_ID'):367 image.show()
351 on_ubuntu = get_value(line) == u'Ubuntu'368
352 if line.startswith('DISTRIB_CODENAME'):369 # Align and pack the error label
353 series = get_value(line)370 self.__err_label.set_alignment(0.0, 0.0)
354 if not on_ubuntu or series is None:371 page.pack_start(self.__err_label, True, True, 0)
355 raise UnsupportedDistribution(372 self.__err_label.show()
356 'This distribution is not supported by Ubuntu One.')373
357 except (OSError, IOError, UnsupportedDistribution), error:374 return page
358 self.__got_error(error)
359
360 return series
361375
362 def __got_error(self, error):376 def __got_error(self, error):
363 """Got an error trying to set up Ubuntu One."""377 """Got an error trying to set up Ubuntu One."""
364 print error378 self.__cancel_button.hide()
365 Gtk.main_quit()379 self.__main_button.show()
380 self.__close_button.show()
381 self.__err_label.set_text(error)
382 self.__notebook.set_current_page(2)
366383
367 @inline_callbacks384 @inline_callbacks
368 def __install_u1(self, *args, **kwargs):385 def __install_u1(self, *args, **kwargs):
369 """Install the packages."""386 """Install the packages."""
370 self.__apt_progress.set_fraction(0.0)387 self.__apt_progress.set_fraction(0.0)
371388
372 def finished(*args, **kwargs):389 def finished(transaction, exit_status, *args, **kwargs):
373 GLib.spawn_command_line_async(CONTROL_PANEL_COMMAND)390 if exit_status != EXIT_SUCCESS:
374 Gtk.main_quit()391 self.__got_error(transaction.error_details)
392 else:
393 GLib.spawn_command_line_async(CONTROL_PANEL_COMMAND)
394 Gtk.main_quit()
375395
376 transaction = yield self.client.install_packages(396 transaction = yield self.client.install_packages(
377 package_names=self.__get_package_list())397 package_names=self.__get_package_list())
@@ -383,23 +403,15 @@
383 def __update_cache(self, *args, **kwargs):403 def __update_cache(self, *args, **kwargs):
384 """Update the cache."""404 """Update the cache."""
385 self.__apt_progress.set_fraction(0.0)405 self.__apt_progress.set_fraction(0.0)
386 transaction = yield self.client.update_cache(406
387 sources_list='ubuntuone-stable-ppa.list')407 def finished(transaction, exit_status, *args, **kwargs):
388 transaction.connect('finished', self.__install_u1)408 if exit_status != EXIT_SUCCESS:
389 self.__apt_progress.set_transaction(transaction)409 self.__got_error(transaction.error_details)
390 transaction.run()410 else:
391411 self.__install_u1()
392 @inline_callbacks412
393 def __add_stable_ppa(self):413 transaction = yield self.client.update_cache()
394 """Add the Ubuntu One 'stable' PPA to apt."""414 transaction.connect('finished', finished)
395 transaction = yield self.client.add_repository(
396 src_type='deb',
397 uri='http://ppa.launchpad.net/ubuntuone/stable/ubuntu',
398 dist=self.__get_series(),
399 comps=['main'],
400 comment='added by Ubuntu One installer',
401 sourcesfile='ubuntuone-stable-ppa.list')
402 transaction.connect('finished', self.__update_cache)
403 self.__apt_progress.set_transaction(transaction)415 self.__apt_progress.set_transaction(transaction)
404 transaction.run()416 transaction.run()
405417
@@ -408,6 +420,7 @@
408 # Hide the buttons420 # Hide the buttons
409 self.__cancel_button.hide()421 self.__cancel_button.hide()
410 self.__main_button.hide()422 self.__main_button.hide()
423 self.__close_button.hide()
411424
412 # Switch to the progress page425 # Switch to the progress page
413 self.__notebook.set_current_page(1)426 self.__notebook.set_current_page(1)
414427
=== modified file 'ubuntuone/installer/tests/test_gui.py'
--- ubuntuone/installer/tests/test_gui.py 2012-02-17 16:01:23 +0000
+++ ubuntuone/installer/tests/test_gui.py 2012-05-21 19:06:19 +0000
@@ -38,15 +38,31 @@
3838
39 def test_page_switched(self):39 def test_page_switched(self):
40 """Test the page switching."""40 """Test the page switching."""
41 #self.assertEquals(self.dlg.active_page, 0)41 #self.assertEqual(self.dlg.active_page, 0)
42 self.dlg.response(Gtk.ResponseType.OK)42 self.dlg.response(Gtk.ResponseType.OK)
43 self.assertEquals(self.dlg.active_page, 1)43 self.assertEqual(self.dlg.active_page, 1)
4444
45 def test_initial_page(self):45 def test_initial_page(self):
46 """Test the initial info page."""46 """Test the initial info page."""
47 self.assertEquals(self.dlg.active_page, 0)47 self.assertEqual(self.dlg.active_page, 0)
4848
49 def test_progress_page(self):49 def test_progress_page(self):
50 """Test the install progresss page."""50 """Test the install progresss page."""
51 self.dlg.response(Gtk.ResponseType.OK)51 self.dlg.response(Gtk.ResponseType.OK)
52 self.assertEquals(self.dlg.active_page, 1)52 self.assertEqual(self.dlg.active_page, 1)
53
54 def test_error_page(self):
55 """Test the error page."""
56 error = u'Just an error.'
57 self.dlg._Window__got_error(error)
58 self.assertEqual(self.dlg.active_page, 2)
59 self.assertEqual(error, self.dlg._Window__err_label.get_text())
60
61 def test_update_cache(self):
62 """Test that updating cache succeeds."""
63 test_update_cache.skip = 'Need to test that cache update works.'
64
65 def test_update_cache_without_network(self):
66 """Test that updating cache fails cleanly without network."""
67 test_update_cache_without_network.skip = \
68 'Need to test that we do the right thing on cache update failure.'

Subscribers

People subscribed via source and target branches

to all changes: