Logo Search packages:      
Sourcecode: jockey version File versions  Download package

def jockey::ui::AbstractUI::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.

Definition at line 309 of file ui.py.

00309                    :
        '''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.
        '''
        os.nice(10)

        if not oslib.OSLib.inst.is_admin():
            logging.error('Only administrators can use this function.')
            return False

        # read previously seen/used handlers
        seen = set()
        used = set()

        if os.path.exists(oslib.OSLib.inst.check_cache):
            f = open(oslib.OSLib.inst.check_cache)
            for line in f:
                try:
                    (flag, h) = line.split(None, 1)
                    h = unicode(h, 'UTF-8')
                except ValueError:
                    logging.error('invalid line in %s: %s',
                        oslib.OSLib.inst.check_cache, line)
                if flag == 'seen':
                    seen.add(h.strip())
                elif flag == 'used':
                    used.add(h.strip())
                else:
                    logging.error('invalid flag in %s: %s',
                        oslib.OSLib.inst.check_cache, line)
            f.close()

        # check for newly used/available handlers
        new_avail = {}
        new_used = {}
        for h in self.handlers:
            id = h.id()
            if id not in seen:
                new_avail[id] = h
                logging.debug('handler %s previously unseen', id)
            if id not in used and h.used():
                new_used[id] = h
                logging.debug('handler %s previously unused', id)

        # write back cache
        if new_avail or new_used:
            logging.debug('new available/used drivers, writing back check cache %s', 
                oslib.OSLib.inst.check_cache)
            seen.update(new_avail.keys())
            used.update(new_used.keys())
            f = open(oslib.OSLib.inst.check_cache, 'w')
            for s in seen:
                print >> f, 'seen', s
            for u in used:
                print >> f, 'used', u
            f.close()

        # throw out newly available handlers which are already enabled, no need
        # to bother people about them
        restricted_available = False
        for h in new_avail.keys(): # create a copy for iteration
            try:
                if new_avail[h].enabled():
                    logging.debug('%s is already enabled or not available, not announcing', id)
                    del new_avail[h]
                elif not new_avail[h].free():
                    restricted_available = True
            except ValueError:
                # thrown if package does not exist; might be a race condition
                # between jockey --check and a cron job fetching new package
                # indexes at session start, see LP #200089
                continue

        # throw out newly used free drivers; no need for education here
        for h in new_used.keys():
            if new_used[h].free():
                logging.debug('%s is a newly used free driver, not announcing', id)
                del new_used[h]

        notified = False

        # launch notifications if anything remains
        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.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()

        return new_avail

    def check_composite(self):


Generated by  Doxygen 1.6.0   Back to index