Exemplo n.º 1
0
class AptInstallation(GObject.GObject):

    __gsignals__ = {
        "finished": (GObject.SIGNAL_RUN_FIRST, GObject.TYPE_NONE, ())
    }

    def __init__(self, replacement):
        GObject.GObject.__init__(self)

        self.replacement = replacement
        self.apt_client = AptClient()

    def run(self):
        apt_cache = open_apt_cache()

        if not apt_cache.has_key(self.replacement["apt"]):
            self.do_update()
        else:
            self.do_install()

    def do_update(self):
        trans_update = self.apt_client.update_cache()
        trans_update.connect("finished", self.on_finished_update)

        dia = AptProgressDialog(trans_update)
        dia.run(close_on_finished=True,
                show_error=False,
                reply_handler=lambda: True,
                error_handler=self.on_error)
        return

    def on_finished_update(self, trans, exit):
        if exit == "exit-success":
            GLib.timeout_add(200, self.do_install)
        return True

    def do_install(self):
        trans_inst = self.apt_client.install_packages(
            package_names=[self.replacement["apt"]])
        trans_inst.connect("finished", self.on_finished_install)
        dia = AptProgressDialog(transaction=trans_inst)
        dia.connect("finished", self.on_install_dialog_finished)
        dia.run(close_on_finished=True,
                show_error=False,
                reply_handler=lambda: True,
                error_handler=self.on_error)
        return

    def on_install_dialog_finished(self, dia):
        if self.exit == "exit-success":
            try:
                replacement_desktop = Gio.DesktopAppInfo.new(
                    self.replacement["desktopLauncher"])
                launch_desktop_app(replacement_desktop)
            except:
                self.finished_dialog(
                    _("%s has been installed") % self.replacement["name"])

        self.emit("finished")

    def on_finished_install(self, trans, exit):
        self.exit = exit
        return

    def finished_dialog(self, message):
        dialog = Gtk.MessageDialog(message_type=Gtk.MessageType.INFO,
                                   buttons=Gtk.ButtonsType.OK,
                                   text=message)
        dialog.run()
        dialog.destroy()
        return

    def on_error(self, error):
        if isinstance(error, aptdaemon.errors.NotAuthorizedError):
            # Silently ignore auth failures
            return
        elif not isinstance(error, aptdaemon.errors.TransactionFailed):
            # Catch internal errors of the client
            error = aptdaemon.errors.TransactionFailed(ERROR_UNKNOWN,
                                                       str(error))
        dia = AptErrorDialog(error)
        dia.run()
        dia.hide()
Exemplo n.º 2
0
        dia = AptProgressDialog(t)
        dia.run()
        dia.destroy()
    else:
        t.run()


if __name__ == "__main__":
    #logging.basicConfig(level=logging.DEBUG)

    context = GObject.main_context_default()
    c = AptClient()
    for i in range(100):

        print "inst: 3dchess"
        t = c.install_packages(["3dchess"], exit_handler=exit_handler)
        run(t)
        active += 1

        print "inst: 2vcard"
        t = c.install_packages(["2vcard"], exit_handler=exit_handler)
        run(t)
        active += 1

        print "rm: 3dchess 2vcard"
        t = c.remove_packages(["3dchess", "2vcard"], exit_handler=exit_handler)
        run(t)

        while active > MAX_ACTIVE:
            while context.pending():
                context.iteration()
Exemplo n.º 3
0
class PackageInstaller(GObject.GObject):

    __gsignals__ = {
        'auth-failed': (GObject.SignalFlags.RUN_LAST, None, ()),
        'done': (GObject.SignalFlags.RUN_LAST, None, (object, )),
    }

    def __init__(self):
        super(PackageInstaller, self).__init__()

        self._client = AptClient()

    #
    #  Public API
    #

    def install(self, *packages):
        def reply(transaction):
            transaction.connect('finished', self._on_transaction__finished)
            self._transaction = transaction
            # dependencis not available on lucid
            for p in getattr(transaction, 'dependencies', []):
                if p:
                    self._confirm()
                    break
            else:
                self._install()

        self._client.install_packages(list(packages),
                                      reply_handler=reply,
                                      error_handler=self._error_handler)

    #
    #  Private
    #

    def _confirm(self):
        dia = AptConfirmDialog(self._transaction)
        response = dia.run()
        dia.destroy()
        if response == Gtk.ResponseType.OK:
            self._install()

    def _install(self):
        dialog = AptProgressDialog(self._transaction)
        dialog.run(close_on_finished=True,
                   show_error=True,
                   reply_handler=lambda: True,
                   error_handler=self._error_handler)

    def _error_handler(self, error):
        try:
            raise error
        except NotAuthorizedError:
            # Silently ignore auth failures
            sys.exit(11)
            return
        except TransactionFailed:
            pass
        except Exception as error:
            error = TransactionFailed(ERROR_UNKNOWN, str(error))

        dia = AptErrorDialog(error)
        dia.run()
        sys.exit(10)

    #
    #  Callbacks
    #

    def _on_transaction__finished(self, transaction, exitcode):
        sys.exit(0 if exitcode in [0, 'exit-success'] else 10)
Exemplo n.º 4
0
#!/usr/bin/python
import aptdaemon, sys, gettext
from aptdaemon.client import AptClient

# i18n
gettext.install("mintinstall", "/usr/share/linuxmint/locale")

if len(sys.argv) == 3:
    operation = sys.argv[1]
    package = sys.argv[2]
    aptd_client = AptClient()
    if operation == "install":
        transaction = aptd_client.install_packages([package])    
        transaction.set_meta_data(mintinstall_label=_("Installing %s") % package)        
    elif operation == "remove":
        transaction = aptd_client.remove_packages([package])    
        transaction.set_meta_data(mintinstall_label=_("Removing %s") % package)
    else:
        print "Invalid operation: %s" % operation
        sys.exit(1)        
    transaction.set_meta_data(mintinstall_pkgname=package)
    transaction.run()