373
381
self.install_box.show_all()
374
382
self.add(self.install_box)
385
def _authenticate_for_add_and_install(self):
386
"""Authenticate with aptdaemon"""
387
bus = dbus.SystemBus()
388
name = bus.get_unique_name()
389
action = policykit1.PK_ACTION_INSTALL_PACKAGES_FROM_NEW_REPO
390
flags = policykit1.CHECK_AUTH_ALLOW_USER_INTERACTION
391
yield policykit1.check_authorization_by_name(name, action, flags=flags)
376
394
def _start_mp3_install(self, btn):
377
395
"""Add the 'partner' repository and update the package list from it."""
378
396
self.ac = aptdaemon.client.AptClient()
380
self.ac.add_repository("deb","http://archive.canonical.com/", "lucid", ["partner"])
381
except dbus.exceptions.DBusException, e:
382
if e.get_dbus_name() == "org.freedesktop.PolicyKit.Error.NotAuthorized":
383
# user cancelled, so exit from here so they can press the button again
385
self.ac.update_cache(reply_handler=self._finish_updating_packages,
386
error_handler=self._on_error)
388
def _finish_updating_packages(self, transaction):
389
"""Now that partner is added, install our mp3 codec package."""
390
self.update_progress = AptProgressBar(transaction)
391
self.update_progress.show()
392
self.install_label_head.set_text("")
393
self.install_label_body.set_text(_("Finding MP3 plugins"))
394
self.install_label_eula.hide()
395
self.install_hbtn.hide()
396
self.install_vbox.pack_start(self.update_progress, expand=False)
397
transaction.run(reply_handler=lambda: True,
398
error_handler=self._on_error)
399
self.ac.install_packages(["gstreamer0.10-fluendo-plugins-mp3-partner"],
400
reply_handler=self._run_transaction,
401
error_handler=self._on_error)
398
yield self._authenticate_for_add_and_install()
399
trans = yield self.ac.add_repository(
401
uri="http://archive.canonical.com/",
404
comment="added by U1MusicStoreWidget",
405
sourcesfile=PARTNER_LIST, defer=True)
406
yield trans.run(defer=True)
407
trans = yield self.ac.update_cache(sources_list=SOURCES_DIR
410
self.update_progress = AptProgressBar(trans)
411
self.update_progress.show()
412
self.install_label_head.set_text("")
413
self.install_label_body.set_text(_("Finding MP3 plugins"))
414
self.install_label_eula.hide()
415
self.install_hbtn.hide()
416
self.install_vbox.pack_start(self.update_progress, expand=False)
417
trans.connect("finished", self._package_update_finished)
418
yield trans.run(defer=True)
403
def _run_transaction(self, transaction):
404
"""Show progress of aptdaemon package installation."""
423
def _package_update_finished(self, transaction, exit_code):
424
"""Packagelist update complete; kick off the install"""
405
425
self.update_progress.hide()
406
self.install_progress = AptProgressBar(transaction)
407
self.install_progress.show()
408
self.install_label_head.set_text("")
409
self.install_label_body.set_text(_("Installing MP3 plugins"))
410
self.install_label_eula.hide()
411
self.install_hbtn.hide()
412
self.install_vbox.pack_start(self.install_progress, expand=False)
413
transaction.run(reply_handler=lambda: True,
414
error_handler=self._on_error)
415
transaction.connect("finished", self._finished)
426
if exit_code != EXIT_SUCCESS:
427
self._on_error(transaction)
430
trans = yield self.ac.install_packages([PLUGIN_PACKAGENAME],
432
self.install_progress = AptProgressBar(transaction)
433
self.install_progress.show()
434
self.install_label_head.set_text("")
435
self.install_label_body.set_text(_("Installing MP3 plugins"))
436
self.install_label_eula.hide()
437
self.install_hbtn.hide()
438
self.install_vbox.pack_start(self.install_progress, expand=False)
439
trans.connect("finished", self._package_install_finished)
440
yield trans.run(defer=True)
417
def _finished(self, trans, exit_code):
444
def _package_install_finished(self, trans, exit_code):
418
445
"""Aptdaemon package installation finished; show music store."""
419
if exit_code == 0 or exit_code == 2: # 0: success, 2: already installed
446
if exit_code == EXIT_SUCCESS:
420
447
self.remove(self.install_box)
421
448
gst.update_registry()
422
449
self.add_music_store_widget()
424
self._on_error("Could not find the "
425
"gstreamer0.10-fluendo-plugins-mp3-partner package.")
451
self._on_error("Could not find the %r package" % PLUGIN_PACKAGENAME)
427
453
def _on_error(self, error):
428
454
"""Error handler for aptdaemon."""