Ejemplo n.º 1
0
        def do_download():
            # get activity registry
            from jarabe.model.bundleregistry import get_registry
            registry = get_registry()  # requires a dbus-registered main loop
            install_event = Event()
            # progress bar bookkeeping.
            counts = [0, self.activity_list.updates_selected(), 0]

            def p(n, extra, icon):
                if n is None:
                    progress_cb(n, extra, icon)
                else:
                    progress_cb((n + (counts[0] / counts[1])) / 2, extra, icon)
                counts[2] = n  # last fraction.

            def q(n, row):
                p(n,
                  _('Downloading %s...') % row[model.DESCRIPTION_BIG],
                  row[model.ACTIVITY_ICON])

            for row, f in self.activity_list.download_selected_updates(q):
                if f is None: continue  # cancelled or network error.
                try:
                    p(counts[2],
                      _('Examining %s...') % row[model.DESCRIPTION_BIG],
                      row[model.ACTIVITY_ICON])
                    b = actutils.BundleHelper(f)
                    p(counts[2],
                      _('Installing %s...') % b.get_name(),
                      _svg2pixbuf(b.get_icon_data()))
                    install_event.clear()
                    GLib.idle_add(self.install_cb, registry, b, install_event)
                    install_event.wait()
                except:
                    logging.exception("Failed to install bundle")
                    pass  # XXX: use alert to indicate install failure.
                if os.path.exists(f):
                    os.unlink(f)
                counts[0] += 1
            # refresh when we're done.
            GObject.idle_add(self.refresh_cb, None, None, False)
Ejemplo n.º 2
0
def set_install_update(which):
    """
    Install any available updates for the activity identified by the
    given (localized) name or bundle id, or all available updates if
    'all' is given.
    """
    import os
    ul = UpdateList(skip_icons=True)
    ul.refresh(_print_status)

    def too_many():
        raise ValueError(
            _('More than one match found for the given activity name or id.'))

    def no_updates():
        raise ValueError(_('The given activity is already up-to-date.'))

    if which != 'all':
        found = False
        for row in ul:
            row[UPDATE_SELECTED] = False
        for row in ul:
            if row[IS_HEADER]: continue
            if which == row[ACTIVITY_ID]:
                if found: too_many()
                found = True
                if not row[UPDATE_EXISTS]: no_updates()
                row[UPDATE_SELECTED] = True
        if not found:
            found_but_uptodate = False
            for row in ul:
                if row[IS_HEADER]: continue
                if which in row[DESCRIPTION_BIG]:
                    if not row[UPDATE_EXISTS]:  # could be false match
                        found_but_uptodate = True
                        continue
                    if found: too_many()
                    found = True
                    row[UPDATE_SELECTED] = True
        if not found:
            if found_but_uptodate: no_updates()
            raise ValueError(_('No activity found with the given name or id.'))
        assert ul.updates_selected() == 1
    # okay, now we've selected only our desired updates.  Download and
    # install them!
    # we need to set up a glib event loop in order to connect to the
    # activity registry (sigh) in ActivityBundle.upgrade() below.
    from dbus.mainloop.glib import DBusGMainLoop
    DBusGMainLoop(set_as_default=True)
    # we'll fetch the main loop, but we don't actually have to run it.
    loop = GObject.MainLoop()
    from jarabe.model.bundleregistry import get_registry
    registry = get_registry()

    def reporthook(n, row):
        _print_status(n, _('Downloading %s...') % row[DESCRIPTION_BIG])

    for row, f in ul.download_selected_updates(reporthook):
        if f is None: continue  # cancelled or network error
        try:
            _print_status(None, _('Examining %s...') % row[DESCRIPTION_BIG])
            b = actutils.BundleHelper(f)
            if b.is_installed(registry):
                _print_status(None,
                              _('Upgrading %s...') % row[DESCRIPTION_BIG])
            else:
                _print_status(None,
                              _('Installing %s...') % row[DESCRIPTION_BIG])
            b.install_or_upgrade(registry)
        except:
            print
            print _('Error installing %s.') % row[DESCRIPTION_BIG]
            import traceback
            traceback.print_exc()  # complain!  but go on.
        if os.path.exists(f):
            os.unlink(f)
        else:
            print "Failed trying to clean up", f