Exemplo n.º 1
0
    def request_action(self, app, addons_install, addons_remove, action):
        """callback when an app action is requested from the appview,
           if action is "remove", must check if other dependencies have to be
           removed as well and show a dialog in that case
        """
        #~ LOG.debug("on_application_action_requested: '%s' %s"
            #~ % (app, action))
        appdetails = app.get_details(self.db)
        if action == AppActions.REMOVE:
            if not dependency_dialogs.confirm_remove(
                        None, self.datadir, app, self.db, self.icons):
                    # craft an instance of TransactionFinishedResult to send
                    # with the transaction-stopped signal
                    result = TransactionFinishedResult(None, False)
                    result.pkgname = app.pkgname
                    self.backend.emit("transaction-stopped", result)
                    return
        elif action == AppActions.INSTALL:
            # If we are installing a package, check for dependencies that will
            # also be removed and show a dialog for confirmation
            # generic removal text (fixing LP bug #554319)
            if not dependency_dialogs.confirm_install(
                        None, self.datadir, app, self.db, self.icons):
                    # craft an instance of TransactionFinishedResult to send
                    # with the transaction-stopped signal
                    result = TransactionFinishedResult(None, False)
                    result.pkgname = app.pkgname
                    self.backend.emit("transaction-stopped", result)
                    return

        # this allows us to 'upgrade' deb files
        if (action == AppActions.UPGRADE and app.request and
            isinstance(app, DebFileApplication)):
            action = AppActions.INSTALL

        # action_func is one of:
        #     "install", "remove", "upgrade", "apply_changes"
        action_func = getattr(self.backend, action)
        if action == AppActions.INSTALL:
            # the package.deb path name is in the request
            if app.request and isinstance(app, DebFileApplication):
                debfile_name = app.request
            else:
                debfile_name = None

            action_func(app, appdetails.icon,
                        debfile_name, addons_install, addons_remove)
        elif callable(action_func):
            action_func(app, appdetails.icon,
                        addons_install=addons_install,
                        addons_remove=addons_remove)
Exemplo n.º 2
0
    def _on_progress_changed(self, progress, ptype, data=None):
        """ de facto callback on transaction's progress change """
        tid = progress.get_property('transaction-id')
        status = progress.get_property('status')
        if not tid:
            LOG.debug("Progress without transaction")
            return

        trans, new = self._transactions_watcher.add_transaction(tid, progress)
        if new:
            trans.connect('deleted', self._on_transaction_deleted)
            LOG.debug("new transaction" + str(trans))
            # should add it to pending_transactions, but
            # i cannot get the pkgname here
            trans.meta_data['sc_appname'] = self.new_appname
            trans.meta_data['sc_pkgname'] = self.new_pkgname
            trans.meta_data['sc_iconname'] = self.new_iconname
            if self.new_pkgname not in self.pending_transactions:
                self.pending_transactions[self.new_pkgname] = trans

        # LOG.debug("Progress update %s %s %s %s" %
        #     (status, ptype, progress.get_property('transaction-id'),
        #     progress.get_property('status')))

        if status == packagekit.StatusEnum.FINISHED:
            LOG.debug("Transaction finished %s" % tid)
            self.emit("transaction-finished",
                      TransactionFinishedResult(trans, True))

        if status == packagekit.StatusEnum.CANCEL:
            LOG.debug("Transaction canceled %s" % tid)
            self.emit("transaction-stopped",
                      TransactionFinishedResult(trans, True))

        if ptype == packagekit.ProgressType.PACKAGE:
            # this should be done better
            # mvo: why getting package here at all?
            #package = progress.get_property('package')
            # fool sc ui about the name change
            trans.emit('role-changed', packagekit.RoleEnum.LAST)

        if ptype == packagekit.ProgressType.PERCENTAGE:
            pkgname = trans.meta_data.get('sc_pkgname', '')
            prog = progress.get_property('percentage')
            if prog >= 0:
                self.emit("transaction-progress-changed", pkgname, prog)
            else:
                self.emit("transaction-progress-changed", pkgname, 0)
    def request_action(self, app, addons_install, addons_remove, action):
        """callback when an app action is requested from the appview,
           if action is "remove", must check if other dependencies have to be
           removed as well and show a dialog in that case
        """
        #~ LOG.debug("on_application_action_requested: '%s' %s"
        #~ % (app, action))
        appdetails = app.get_details(self.db)
        if action == AppActions.REMOVE:
            if not dependency_dialogs.confirm_remove(None, self.datadir, app,
                                                     self.db, self.icons):
                # craft an instance of TransactionFinishedResult to send
                # with the transaction-stopped signal
                result = TransactionFinishedResult(None, False)
                result.pkgname = app.pkgname
                self.backend.emit("transaction-stopped", result)
                return
        elif action == AppActions.INSTALL:
            # If we are installing a package, check for dependencies that will
            # also be removed and show a dialog for confirmation
            # generic removal text (fixing LP bug #554319)
            if not dependency_dialogs.confirm_install(None, self.datadir, app,
                                                      self.db, self.icons):
                # craft an instance of TransactionFinishedResult to send
                # with the transaction-stopped signal
                result = TransactionFinishedResult(None, False)
                result.pkgname = app.pkgname
                self.backend.emit("transaction-stopped", result)
                return

        # this allows us to 'upgrade' deb files
        if (action == AppActions.UPGRADE and app.request
                and isinstance(app, DebFileApplication)):
            action = AppActions.INSTALL

        # action_func is one of:
        #     "install", "remove", "upgrade", "apply_changes"
        action_func = getattr(self.backend, action)
        if action == AppActions.INSTALL:
            # the package.deb path name is in the request
            if app.request and isinstance(app, DebFileApplication):
                debfile_name = app.request
            else:
                debfile_name = None

            action_func(app, appdetails.icon, debfile_name, addons_install,
                        addons_remove)
        elif callable(action_func):
            action_func(app,
                        appdetails.icon,
                        addons_install=addons_install,
                        addons_remove=addons_remove)