~ubuntuone-control-tower/rhythmbox-ubuntuone/trunk

« back to all changes in this revision

Viewing changes to umusicstore/MusicStoreWidget.py

  • Committer: Tarmac
  • Author(s): john.lenton at canonical
  • Date: 2010-09-15 23:01:00 UTC
  • mfrom: (86.1.2 fix-634545)
  • Revision ID: ubuntuone-tarmac@balleny-20100915230100-y85gezy0jrfr03fk
Fix the mp3 plugin install code wrt aptdaemon changes (fixes LP:634545)

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import gtk, gobject, os, urllib, gconf, stat, urlparse, gio
21
21
import gst, gst.pbutils
22
22
import aptdaemon.client
 
23
from aptdaemon import policykit1
 
24
from aptdaemon.defer import inline_callbacks
23
25
from aptdaemon.enums import *
24
26
from aptdaemon.gtkwidgets import AptErrorDialog, \
25
27
                                 AptProgressBar
 
28
from commands import getstatusoutput
26
29
import rb, rhythmdb
27
30
from ubuntuone.gtkwidgets import MusicStore as U1MusicStore
28
31
import xdg.BaseDirectory
 
32
import dbus
29
33
import dbus.exceptions
30
34
 
31
35
import gettext
36
40
MUSIC_STORE_WIDGET = U1MusicStore() # keep this around for later
37
41
U1LIBRARYPATH = MUSIC_STORE_WIDGET.get_library_location()
38
42
RB_LIBRARY_LOCATIONS = "/apps/rhythmbox/library_locations"
 
43
PARTNER_LIST = "canonical-partner-maverick.list"
 
44
SOURCES_DIR = "/etc/apt/sources.list.d/"
 
45
PLUGIN_PACKAGENAME = "gstreamer0.10-fluendo-plugins-mp3-partner"
39
46
 
40
47
class U1EntryType(rhythmdb.EntryType):
41
48
    def __init__(self):
340
347
            ', you need to install MP3 plugins. Click below to install them.'))
341
348
        self.install_label_body.set_alignment(0.0, 0.5)
342
349
        self.install_label_eula = gtk.Label()
343
 
        # EULA text copied from /var/lib/dpkg/info/gstreamer0.10-fluendo-plugins-mp3-partner.templates
 
350
        # EULA text copied from
 
351
        # /var/lib/dpkg/info/gstreamer0.10-fluendo-plugins-mp3-partner.templates
344
352
        # The partner package shows the EULA itself on installations, but
345
353
        #  aptdaemon installations work like DEBIAN_FRONTEND=noninteractive
346
354
        # so we show the EULA here. (This also avoids a popup window.)
373
381
        self.install_box.show_all()
374
382
        self.add(self.install_box)
375
383
 
 
384
    @inline_callbacks
 
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)
 
392
 
 
393
    @inline_callbacks
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()
379
397
        try:
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
384
 
                return
385
 
        self.ac.update_cache(reply_handler=self._finish_updating_packages,
386
 
                        error_handler=self._on_error)
387
 
    
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(
 
400
                src_type="deb",
 
401
                uri="http://archive.canonical.com/",
 
402
                dist="maverick",
 
403
                comps=["partner"],
 
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
 
408
                                               + PARTNER_LIST,
 
409
                                               defer=True)
 
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)
 
419
        except Exception, e:
 
420
            self._on_error(e)
402
421
 
403
 
    def _run_transaction(self, transaction):
404
 
        """Show progress of aptdaemon package installation."""
 
422
    @inline_callbacks
 
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)
 
428
            return
 
429
        try:
 
430
            trans = yield self.ac.install_packages([PLUGIN_PACKAGENAME],
 
431
                                                   defer=True)
 
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)
 
441
        except Exception, e:
 
442
            self._on_error(e)
416
443
 
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()
423
450
        else:
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)
426
452
 
427
453
    def _on_error(self, error):
428
454
        """Error handler for aptdaemon."""
432
458
            '%s</span>' % problem_installing)
433
459
        self.install_label_body.set_text(_('Check your internet connection and '
434
460
            'try again.'))
435
 
        if getattr(self, "install_progress"):
436
 
            self.install_progress.hide()
 
461
        for widget in ("install_progress", "update_progress"):
 
462
            widget = getattr(self, widget, None)
 
463
            if widget is not None:
 
464
                widget.hide()
437
465
        self.install_hbtn.show()
438
466
 
439
467
    def add_music_store_widget(self):