def _check_repositories(self): '''Check if we have package repositories, and if not, offer to update.''' if self._dbus_iface.has_repositories(): return if self.have_ui: success = False try: self._repository_progress_shown = False success = convert_dbus_exceptions(dbus_sync_call_signal_wrapper, self._dbus_iface, 'update_repository_indexes', {'repository_update_progress': self._repository_progress_handler}) finally: if self._repository_progress_shown: self.ui_progress_finish() # check success if not success: self.error_message('', self._( 'Downloading package indexes failed, please check your network status. ' 'Most drivers will not be available.')) else: # This happens when running in --check mode. We do not particularly # care about success here. convert_dbus_exceptions(self._dbus_iface.update_repository_indexes)
def _check_repositories(self): '''Check if we have package repositories, and if not, offer to update.''' if self._dbus_iface.has_repositories(): return if self.have_ui: success = False try: self._repository_progress_shown = False success = convert_dbus_exceptions( dbus_sync_call_signal_wrapper, self._dbus_iface, 'update_repository_indexes', { 'repository_update_progress': self._repository_progress_handler }) finally: if self._repository_progress_shown: self.ui_progress_finish() # check success if not success: self.error_message( '', self. _('Downloading package indexes failed, please check your network status. ' 'Most drivers will not be available.')) else: # This happens when running in --check mode. We do not particularly # care about success here. convert_dbus_exceptions(self._dbus_iface.update_repository_indexes)
def set_handler_enable(self, handler_id, action, confirm, gui=True): '''Enable, disable, or toggle a handler. action can be 'enable', 'disable', or 'toggle'. If confirm is True, this first presents a confirmation dialog. Then a progress dialog is presented for installation/removal of the handler. If gui is True, error messags and install progress will be shown in the GUI, otherwise just printed to stderr (CLI mode). Return True if anything was changed and thus the UI needs to be refreshed. ''' try: i = convert_dbus_exceptions(self.backend().handler_info, handler_id) except UnknownHandlerException: self.error_msg('%s: %s' % (self.string_unknown_driver, handler_id)) self.error_msg(self._('Use --list to see available drivers')) return False # determine new status if action == 'enable': enable = True elif action == 'disable': enable = False elif action == 'toggle': enable = not bool(i['enabled']) else: raise ValueError('invalid action %s; allowed are enable, disable, toggle') # check if we can change at all if 'can_change' in i: msg = i['can_change'] if gui: self.error_message(self._('Cannot change driver'), self._(msg)) else: self.error_msg(self._(msg)) return False # actually something to change? if enable == bool(i['enabled']): return False if confirm: # construct and ask confirmation question if enable: title = self._('Enable driver?') action = self.string_button_enable else: title = self._('Disable driver?') action = self.string_button_disable n = i['name'] # self._(i['name']) is misinterpreted by xgettext if not self.confirm_action(title, self._(n), self._get_description_rationale_text(i), action): return False # go try: if gui: try: self._install_progress_shown = False convert_dbus_exceptions(dbus_sync_call_signal_wrapper, self.backend(), 'set_enabled', {'install_progress': self._install_progress_handler, 'remove_progress': self._remove_progress_handler}, handler_id, enable) finally: if self._install_progress_shown: self.ui_progress_finish() else: convert_dbus_exceptions(dbus_sync_call_signal_wrapper, self.backend(), 'set_enabled', {}, handler_id, enable) except PermissionDeniedByPolicy: self.error_message('', self.string_unprivileged) return False except BackendCrashError: self._dbus_iface = None self.error_message('', '%s\n\n https://launchpad.net/jockey/+filebug\n\n%s' % ( self._('Sorry, the Jockey backend crashed. Please file a bug at:'), self._('Trying to recover by restarting backend.'))) return False except SystemError as e: self.error_message('', str(e).strip().splitlines()[-1]) return False newstate = bool(self.backend().handler_info(handler_id)['enabled']) if enable and not newstate: self.error_message('', '%s\n\n%s: /var/log/jockey.log' % ( self._('Sorry, installation of this driver failed.'), self._('Please have a look at the log file for details'))) return i['enabled'] != newstate
def check(self): '''Notify the user about newly used or available drivers since last check(). Return True if any new driver is available which is not yet enabled. ''' # if the user is running Jockey with package installation or another # long-running task in parallel, the automatic --check invocation will # time out on this. try: convert_dbus_exceptions(self.backend) except Exception as e: print >> sys.stderr, 'Cannot connect to backend, is it busy?\n', e return False try: (new_used, new_avail) = convert_dbus_exceptions( self.backend().new_used_available, self.argv_options.mode) except PermissionDeniedByPolicy: self.error_msg(self.string_unprivileged) return False # any new restricted drivers? also throw out the non-announced ones restricted_available = False for h_id in set(new_avail): # create copy info = self.backend().handler_info(h_id) if not bool(info['announce']): new_avail.remove(h_id) continue if not bool(info['free']): restricted_available = True break # throw out newly used free drivers; no need for education here for h_id in new_used + []: # create copy for iteration if bool(self.backend().handler_info(h_id)['free']): new_used.remove(h_id) notified = False # launch notifications if anything remains if new_avail or new_used: # defer UI initialization until here, since --check should not # spawn a progress dialog for searching drivers self.ui_init() self.have_ui = True if new_avail: if restricted_available: self.ui_notification(self._('Restricted drivers available'), self._('In order to use your hardware more efficiently, you' ' can enable drivers which are not free software.')) else: self.ui_notification(self._('New drivers available'), self._('There are new or updated drivers available for ' 'your hardware.')) notified = True elif new_used: self.ui_notification(self._('New restricted drivers in use'), # %(os)s stands for the OS name. Prefix it or suffix it, # but do not replace it. self._('In order for this computer to function properly, %(os)s is ' 'using driver software that cannot be supported by %(os)s.') % {'os': OSLib.inst.os_vendor}) notified = True if notified: # we need to stay in the main loop so that the tray icon stays # around self.ui_main_loop() self.backend().shutdown() return len(new_avail) > 0
def set_handler_enable(self, handler_id, action, confirm, gui=True): '''Enable, disable, or toggle a handler. action can be 'enable', 'disable', or 'toggle'. If confirm is True, this first presents a confirmation dialog. Then a progress dialog is presented for installation/removal of the handler. If gui is True, error messags and install progress will be shown in the GUI, otherwise just printed to stderr (CLI mode). Return True if anything was changed and thus the UI needs to be refreshed. ''' try: i = convert_dbus_exceptions(self.backend().handler_info, handler_id) except UnknownHandlerException: self.error_msg('%s: %s' % (self.string_unknown_driver, handler_id)) self.error_msg(self._('Use --list to see available drivers')) return False # determine new status if action == 'enable': enable = True elif action == 'disable': enable = False elif action == 'toggle': enable = not bool(i['enabled']) else: raise ValueError( 'invalid action %s; allowed are enable, disable, toggle') # check if we can change at all if 'can_change' in i: msg = i['can_change'] if gui: self.error_message(self._('Cannot change driver'), self._(msg)) else: self.error_msg(self._(msg)) return False # actually something to change? if enable == bool(i['enabled']): return False if confirm: # construct and ask confirmation question if enable: title = self._('Enable driver?') action = self.string_button_enable else: title = self._('Disable driver?') action = self.string_button_disable n = i['name'] # self._(i['name']) is misinterpreted by xgettext if not self.confirm_action(title, self._(n), self._get_description_rationale_text(i), action): return False # go try: if gui: try: self._install_progress_shown = False convert_dbus_exceptions( dbus_sync_call_signal_wrapper, self.backend(), 'set_enabled', { 'install_progress': self._install_progress_handler, 'remove_progress': self._remove_progress_handler }, handler_id, enable) finally: if self._install_progress_shown: self.ui_progress_finish() else: convert_dbus_exceptions(dbus_sync_call_signal_wrapper, self.backend(), 'set_enabled', {}, handler_id, enable) except PermissionDeniedByPolicy: self.error_message('', self.string_unprivileged) return False except BackendCrashError: self._dbus_iface = None self.error_message( '', '%s\n\n https://launchpad.net/jockey/+filebug\n\n%s' % (self. _('Sorry, the Jockey backend crashed. Please file a bug at:'), self._('Trying to recover by restarting backend.'))) return False except SystemError as e: self.error_message('', str(e).strip().splitlines()[-1]) return False newstate = bool(self.backend().handler_info(handler_id)['enabled']) if enable and not newstate: self.error_message( '', '%s\n\n%s: /var/log/jockey.log' % (self._('Sorry, installation of this driver failed.'), self._('Please have a look at the log file for details'))) return i['enabled'] != newstate
def check(self): '''Notify the user about newly used or available drivers since last check(). Return True if any new driver is available which is not yet enabled. ''' # if the user is running Jockey with package installation or another # long-running task in parallel, the automatic --check invocation will # time out on this. try: convert_dbus_exceptions(self.backend) except Exception as e: print >> sys.stderr, 'Cannot connect to backend, is it busy?\n', e return False try: (new_used, new_avail) = convert_dbus_exceptions( self.backend().new_used_available, self.argv_options.mode) except PermissionDeniedByPolicy: self.error_msg(self.string_unprivileged) return False # any new restricted drivers? also throw out the non-announced ones restricted_available = False for h_id in set(new_avail): # create copy info = self.backend().handler_info(h_id) if not bool(info['announce']): new_avail.remove(h_id) continue if not bool(info['free']): restricted_available = True break # throw out newly used free drivers; no need for education here for h_id in new_used + []: # create copy for iteration if bool(self.backend().handler_info(h_id)['free']): new_used.remove(h_id) notified = False # launch notifications if anything remains if new_avail or new_used: # defer UI initialization until here, since --check should not # spawn a progress dialog for searching drivers self.ui_init() self.have_ui = True if new_avail: if restricted_available: self.ui_notification( self._('Restricted drivers available'), self._( 'In order to use your hardware more efficiently, you' ' can enable drivers which are not free software.')) else: self.ui_notification( self._('New drivers available'), self._('There are new or updated drivers available for ' 'your hardware.')) notified = True elif new_used: self.ui_notification( self._('New restricted drivers in use'), # %(os)s stands for the OS name. Prefix it or suffix it, # but do not replace it. self. _('In order for this computer to function properly, %(os)s is ' 'using driver software that cannot be supported by %(os)s.' ) % {'os': OSLib.inst.os_vendor}) notified = True if notified: # we need to stay in the main loop so that the tray icon stays # around self.ui_main_loop() self.backend().shutdown() return len(new_avail) > 0