Example #1
0
 def exception_handler(self, e):
     """Called if exception occours in methods with the
     @ExceptionHandler decorator.
     """
     close = True
     msg = str(e)
     logger.error('EXCEPTION : %s ' % msg)
     err, errmsg = self._parse_error(msg)
     logger.debug('err:  [%s] - msg: %s' % (err, errmsg))
     if err == 'LockedError':
         errmsg = 'dnf is locked by another process \n' \
                  '\nYum Extender will exit'
         close = False
     elif err == 'AccessDeniedError':
         errmsg = "Root backend was not authorized and can't continue"
         close = True
     elif err == 'FatalError':
         errmsg = 'Fatal error in yumex backend'
         close = False
     elif err == 'NoReply':
         errmsg = 'DNF Dbus backend is not responding \n'\
         '\nYum Extender will exit'
         close = False
     if errmsg == '':
         errmsg = msg
     dialogs.show_information(self, errmsg)
     # try to exit the backends, ignore errors
     if close:
         try:
             self.release_root_backend(quit=True)
         except:
             pass
     Gtk.main_quit()
     sys.exit(1)
Example #2
0
 def exception_handler(self, e):
     """Called if exception occours in methods with the
     @ExceptionHandler decorator.
     """
     close = True
     msg = str(e)
     logger.error('BASE EXCEPTION : %s ' % msg)
     err, errmsg = self._parse_error(msg)
     logger.debug('BASE err:  [%s] - msg: %s' % (err, errmsg))
     if err == 'LockedError':
         errmsg = 'DNF is locked by another process.\n'
         '\nYum Extender will exit'
         close = False
     elif err == 'NoReply':
         errmsg = 'DNF D-Bus backend is not responding.\n'
         '\nYum Extender will exit'
         close = False
     if errmsg == '':
         errmsg = msg
     dialogs.show_information(self, errmsg)
     # try to exit the backends, ignore errors
     if close:
         try:
             self.release_root_backend(quit=True)
         except:
             pass
     #self.status.SetWorking(False)  # reset working state
     #self.status.SetYumexIsRunning(self.pid, False)
     sys.exit(1)
Example #3
0
 def _open_url(self, url):
     """Open URL in default browser."""
     if misc.is_url(url):  # just to be sure and prevent shell injection
         rc = subprocess.call('xdg-open %s' % url, shell=True)
         # failover to gtk.show_uri, if xdg-open fails or is not installed
         if rc != 0:
             Gtk.show_uri(None, url, Gdk.CURRENT_TIME)
     else:
         dialogs.show_information('%s is not an url' % url)
Example #4
0
 def _open_url(self, url):
     """Open URL in default browser."""
     if misc.is_url(url):  # just to be sure and prevent shell injection
         rc = subprocess.call('xdg-open %s' % url, shell=True)
         # failover to gtk.show_uri, if xdg-open fails or is not installed
         if rc != 0:
             Gtk.show_uri(None, url, Gdk.CURRENT_TIME)
     else:
         dialogs.show_information('%s is not an url' % url)
Example #5
0
 def reset_cache(self):
     logger.debug('Refresh system cache')
     self.set_working(True, True)
     self.infobar.info(_('Refreshing Repository Metadata'))
     rc = self._root_backend.ExpireCache()
     self.set_working(False)
     if rc:
         self._set_cache_refreshed('system')
     else:
         dialogs.show_information(
             self, _('Could not refresh the DNF cache (root)'))
Example #6
0
    def _process_actions(self, from_queue=True):
        """Process the current actions in the queue.

        - setup the Dnf transaction
        - resolve dependencies
        - ask user for confirmation on result of depsolve
        - run the transaction
        """
        self.set_working(True, True)
        self.infobar.info(_('Preparing system for applying changes'))
        try:
            if from_queue:
                result = self._build_from_queue()
            else:
                result = self._get_transaction()
            self.set_working(False)
            # check for protected packages
            check = self._check_protected(result)
            if check:
                self.error_dialog.show(
                    ngettext("Can't remove protected package:",
                             "Can't remove protected packages:", len(check)) +
                    misc.list_to_string(check, "\n ", ",\n "))
                self._reset_on_cancel()
                return
            # transaction confirmation dialog
            self.transaction_result.populate(result, '')
            ok = self.transaction_result.run()
            if ok:  # Ok pressed
                self._run_transaction()
            else:  # user cancelled transaction
                self._reset_on_cancel()
                return
        except misc.QueueEmptyError:  # Queue is empty
            self.set_working(False)
            dialogs.show_information(self, _('No pending actions in queue'))
            self._reset_on_cancel()
        except misc.TransactionBuildError as e:
            # Error in building transaction
            self.error_dialog.show(
                ngettext('Error in building transaction',
                         'Errors in building transaction', len(e.msgs)) +
                '\n'.join(e.msgs))
            self._reset_on_cancel()
        except misc.TransactionSolveError as e:
            self.error_dialog.show(
                ngettext('Error in search for dependencies',
                         'Errors in search for dependencies', len(e.msgs)) +
                '\n'.join(e.msgs))
            self._reset_on_error()
Example #7
0
 def on_history_undo(self, widget):
     """Handle the undo button on history page."""
     tid = self.history_view.get_selected()
     logger.debug('History Undo : %s', tid)
     rc, messages = self.backend.HistoryUndo(tid)
     if rc:
         self._process_actions(from_queue=False)
     else:
         msg = "Can't undo history transaction :\n%s" % \
               ("\n".join(messages))
         logger.debug(msg)
         dialogs.show_information(self,
                                  _('Error in undo history transaction'),
                                  "\n".join(messages))
Example #8
0
 def on_history_undo(self, widget):
     """Handle the undo button on history page."""
     tid = self.history_view.get_selected()
     logger.debug('History Undo : %s', tid)
     rc, messages = self.backend.HistoryUndo(tid)
     if rc:
         self.process_actions(from_queue=False)
     else:
         msg = "Can't undo history transaction :\n%s" % \
               ("\n".join(messages))
         logger.debug(msg)
         dialogs.show_information(
             self, _('Error in undo history transaction'),
             "\n".join(messages))
Example #9
0
    def _process_actions_installmode(self, action, package, always_yes,
                                     app_quit):
        """Process the pending actions from the command line.

        :param action: action to perform (install/remove)
        :param package: package to work on
        :param always_yes: ask the user or default to yes/ok to all questions
        """
        if action == 'install':
            self.infobar.info(_('Installing package: %s') % package)
            exit_msg = _('%s was installed successfully') % package
            self.infobar.info_sub(package)
            txmbrs = self.backend.Install(package)
            logger.debug('txmbrs: %s' % str(txmbrs))
        elif action == 'remove':
            self.infobar.info(_('Removing package: %s') % package)
            exit_msg = _('%s was removed successfully') % package
            self.infobar.info_sub(package)
            txmbrs = self.backend.Remove(package)
            logger.debug('txmbrs: %s' % str(txmbrs))
        elif action == 'update':
            self.infobar.info(_('Updating all available updates'))
            exit_msg = _('Available updates was applied successfully')
            txmbrs = self.backend.Update('*')
        self.infobar.info(_('Searching for dependencies'))
        rc, result = self.backend.BuildTransaction()
        self.infobar.info(_('Dependencies resolved'))
        if rc:
            self.transaction_result.populate(result, '')
            if not always_yes:
                ok = self.transaction_result.run()
            else:
                ok = True
            if ok:  # Ok pressed
                self.infobar.info(_('Applying changes to the system'))
                self.backend.RunTransaction()
                self.release_root_backend()
                self.hide()
                misc.notify('Yum Extender', exit_msg)
        else:
            dialogs.show_information(
                self,
                ngettext('Error in search for dependencies',
                         'Errors in search for dependencies', len(result)),
                '\n'.join(result))
        if app_quit:
            self.release_root_backend(quit_dnfdaemon=True)
            self.app.quit()
Example #10
0
    def _process_actions_installmode(self, action, package, always_yes,
                                     app_quit):
        """Process the pending actions from the command line.

        :param action: action to perform (install/remove)
        :param package: package to work on
        :param always_yes: ask the user or default to yes/ok to all questions
        """
        if action == 'install':
            self.infobar.info(_('Installing package: %s') % package)
            exit_msg = _('%s was installed successfully') % package
            self.infobar.info_sub(package)
            txmbrs = self.backend.Install(package)
            logger.debug('txmbrs: %s' % str(txmbrs))
        elif action == 'remove':
            self.infobar.info(_('Removing package: %s') % package)
            exit_msg = _('%s was removed successfully') % package
            self.infobar.info_sub(package)
            txmbrs = self.backend.Remove(package)
            logger.debug('txmbrs: %s' % str(txmbrs))
        elif action == 'update':
            self.infobar.info(_('Updating all available updates'))
            exit_msg = _('Available updates was applied successfully')
            txmbrs = self.backend.Update('*')
        self.infobar.info(_('Searching for dependencies'))
        rc, result = self.backend.BuildTransaction()
        self.infobar.info(_('Dependencies resolved'))
        if rc:
            self.transaction_result.populate(result, '')
            if not always_yes:
                ok = self.transaction_result.run()
            else:
                ok = True
            if ok:  # Ok pressed
                self.infobar.info(_('Applying changes to the system'))
                self.backend.RunTransaction()
                self.release_root_backend()
                self.hide()
                misc.notify('Yum Extender', exit_msg)
        else:
            dialogs.show_information(
                self, _('Error(s) in search for dependencies'),
                        '\n'.join(result))
        if app_quit:
            self.release_root_backend(quit=True)
            self.app.quit()
Example #11
0
    def get_root_backend(self):
        """Get the current root backend.

        if it is not setup yet, the create it
        if it is not locked, then lock it
        """
        if self._root_backend is None:
            self._root_backend = yumex.dnf_backend.DnfRootBackend(self)
        if self._root_locked is False:
            logger.debug('Lock the DNF root daemon')
            locked, msg = self._root_backend.setup()
            if locked:
                self._root_locked = True
                if self._check_cache_expired('system'):
                    logger.debug('Refresh system cache')
                    self.set_working(True, True)
                    self.infobar.info(_('Refreshing Repository Metadata'))
                    rc = self._root_backend.ExpireCache()
                    self.set_working(False)
                    if rc:
                        self._set_cache_refreshed('system')
                    else:
                        dialogs.show_information(
                            self, _('Could not refresh the DNF cache (root)'))
            else:
                logger.critical("can't get root backend lock")
                if msg == 'not-authorized':  # user canceled the polkit dialog
                    errmsg = _(
                        'DNF root backend was not authorized.\n'
                        'Yum Extender will exit')
                # DNF is locked by another process
                elif msg == 'locked-by-other':
                    errmsg = _(
                        'DNF is locked by another process.\n\n'
                        'Yum Extender will exit')
                dialogs.show_information(self, errmsg)
                # close down and exit yum extender
                #self.status.SetWorking(False)  # reset working state
                #self.status.SetYumexIsRunning(self.pid, False)
                sys.exit(1)
        return self._root_backend
Example #12
0
 def __init__(self, app):
     Gtk.ApplicationWindow.__init__(self,
                                    title='Yum Extender - Powered by DNF',
                                    application=app)
     BaseYumex.__init__(self)
     self.app = app
     self.connect('delete_event', self.on_delete_event)
     icon = Gtk.IconTheme.get_default().load_icon('yumex-dnf', 128, 0)
     self.set_icon(icon)
     self.ui = Gtk.Builder()
     self.ui.set_translation_domain('yumex-dnf')
     try:
         self.ui.add_from_file(const.DATA_DIR + "/yumex.ui")
     except:
         raise
         dialogs.show_information(
             self, 'GtkBuilder ui file not found : ' +
             const.DATA_DIR + '/yumex.ui')
         sys.exit()
     # transaction result dialog
     self.transaction_result = dialogs.TransactionResult(self)
Example #13
0
 def __init__(self, app):
     Gtk.ApplicationWindow.__init__(self,
                                    title='Yum Extender - Powered by DNF',
                                    application=app)
     BaseYumex.__init__(self)
     self.get_style_context().add_class("yumex-dnf-window")
     self.app = app
     self.connect('delete_event', self.on_delete_event)
     icon = Gtk.IconTheme.get_default().load_icon('yumex-dnf', 128, 0)
     self.set_icon(icon)
     self.ui = Gtk.Builder()
     self.ui.set_translation_domain('yumex-dnf')
     try:
         self.ui.add_from_file(const.DATA_DIR + "/yumex.ui")
     except:
         raise
         dialogs.show_information(
             self, 'GtkBuilder ui file not found : ' + const.DATA_DIR +
             '/yumex.ui')
         sys.exit()
     # transaction result dialog
     self.transaction_result = dialogs.TransactionResult(self)
     self.error_dialog = dialogs.ErrorDialog(self)
Example #14
0
    def _process_actions(self, from_queue=True):
        """Process the current actions in the queue.

        - setup the Dnf transaction
        - resolve dependencies
        - ask user for confirmation on result of depsolve
        - run the transaction
        """
        self.set_working(True, True)
        self.infobar.info(_('Preparing system for applying changes'))
        try:
            if from_queue:
                result = self._build_from_queue()
            else:
                result = self._get_transaction()
            self.set_working(False)
            # check for protected packages
            check = self._check_protected(result)
            if check:
                dialogs.show_information(
                self, _("Can't remove protected package(s)"),
                        '\n'.join(check))
                self._reset_on_cancel()
                return
            # transaction confirmation dialog
            self.transaction_result.populate(result, '')
            ok = self.transaction_result.run()
            if ok:  # Ok pressed
                self._run_transaction()
            else:  # user cancelled transaction
                self._reset_on_cancel()
                return
        except misc.QueueEmptyError:  # Queue is empty
            self.set_working(False)
            dialogs.show_information(self, _('No pending actions in queue'))
            self._reset_on_cancel()
        except misc.TransactionBuildError as e:  # Error in building transaction
            dialogs.show_information(
                self, _('Error(s) in building transaction'),
                        '\n'.join(e.msgs))
            self._reset_on_cancel()
        except misc.TransactionSolveError as e:
            dialogs.show_information(
                    self, _('Error(s) in search for dependencies'),
                            '\n'.join(e.msgs))
            self._reset_on_error()
Example #15
0
    def _run_transaction(self):
        """Run the current transaction."""
        self.infobar.info(_('Applying changes to the system'))
        self.set_working(True, True)
        rc, result = self.backend.RunTransaction()
        # This can happen more than once (more gpg keys to be
        # imported)
        while rc == 1:
            # get info about gpgkey to be comfirmed
            values = self.backend._gpg_confirm
            if values:  # There is a gpgkey to be verified
                (pkg_id, userid, hexkeyid, keyurl, timestamp) = values
                logger.debug('GPGKey : %s' % repr(values))
                ok = dialogs.ask_for_gpg_import(self, values)
                if ok:
                    # tell the backend that the gpg key is confirmed
                    self.backend.ConfirmGPGImport(hexkeyid, True)
                    # rerun the transaction
                    # FIXME: It should not be needed to populate
                    # the transaction again
                    self._populate_transaction()
                    rc, result = self.backend.BuildTransaction()
                    rc, result = self.backend.RunTransaction()
                else:
                    break
            else:  # error in signature verification
                dialogs.show_information(
                    self, _('Error checking package signatures\n'),
                    '\n'.join(result))
                break

        if rc == 4:  # Download errors
            dialogs.show_information(
                self,
                ngettext('Downloading error\n', 'Downloading errors\n',
                         len(result)), '\n'.join(result))
            self._reset_on_cancel()
            return
        elif rc != 0:  # other transaction errors
            dialogs.show_information(
                self,
                ngettext('Error in transaction\n', 'Errors in transaction\n',
                         len(result)), '\n'.join(result))
        self._reset()
        return
Example #16
0
    def _run_transaction(self):
        """Run the current transaction."""
        self.infobar.info(_('Applying changes to the system'))
        self.set_working(True, True)
        rc, result = self.backend.RunTransaction()
        # This can happen more than once (more gpg keys to be
        # imported)
        while rc == 1:
            # get info about gpgkey to be comfirmed
            values = self.backend._gpg_confirm
            if values:  # There is a gpgkey to be verified
                (pkg_id, userid, hexkeyid, keyurl, timestamp) = values
                logger.debug('GPGKey : %s' % repr(values))
                ok = dialogs.ask_for_gpg_import(self, values)
                if ok:
                    # tell the backend that the gpg key is confirmed
                    self.backend.ConfirmGPGImport(hexkeyid, True)
                    # rerun the transaction
                    # FIXME: It should not be needed to populate
                    # the transaction again
                    self._populate_transaction()
                    rc, result = self.backend.BuildTransaction()
                    rc, result = self.backend.RunTransaction()
                else:
                    break
            else:  # error in signature verification
                dialogs.show_information(
                    self, _('Error checking package signatures\n'),
                             '\n'.join(result))
                break

        if rc == 4:  # Download errors
            dialogs.show_information(
                self, _('Downloading error(s)\n'),
                         '\n'.join(result))
            self._reset_on_cancel()
            return
        elif rc != 0:  # other transaction errors
            dialogs.show_information(
                self, _('Error in transaction\n'),
                         '\n'.join(result))
        self._reset()
        return