home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / computerjanitor / plugins / dpkg_status_plugin.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-10-12  |  3.0 KB  |  65 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from apt_pkg import ParseTagFile, PkgSystemLock, PkgSystemUnLock
  5. import subprocess
  6. import logging
  7. import computerjanitor
  8. _ = computerjanitor.setup_gettext()
  9.  
  10. class DpkgStatusCruft(computerjanitor.Cruft):
  11.     
  12.     def __init__(self, n_items):
  13.         self.n_items = n_items
  14.  
  15.     
  16.     def get_prefix(self):
  17.         return 'dpkg-status'
  18.  
  19.     
  20.     def get_prefix_description(self):
  21.         return _('%i obsolete entries in the status file') % self.n_items
  22.  
  23.     
  24.     def get_shortname(self):
  25.         return _('Obsolete entries in dpkg status')
  26.  
  27.     
  28.     def get_description(self):
  29.         return _('Obsolete dpkg status entries')
  30.  
  31.     
  32.     def cleanup(self):
  33.         logging.debug('calling dpkg --forget-old-unavail')
  34.         res = subprocess.call([
  35.             'dpkg',
  36.             '--forget-old-unavail'])
  37.         logging.debug('dpkg --forget-old-unavail returned %s' % res)
  38.  
  39.  
  40.  
  41. class DpkgStatusPlugin(computerjanitor.Plugin):
  42.     
  43.     def __init__(self, fname = '/var/lib/dpkg/status'):
  44.         self.status = fname
  45.         self.condition = [
  46.             'PostCleanup']
  47.  
  48.     
  49.     def get_cruft(self):
  50.         n_cruft = 0
  51.         tagf = ParseTagFile(open(self.status))
  52.         while tagf.Step():
  53.             statusline = tagf.Section.get('Status')
  54.             (want, flag, status) = statusline.split()
  55.             if want == 'purge' and flag == 'ok' and status == 'not-installed':
  56.                 n_cruft += 1
  57.                 continue
  58.         logging.debug('DpkgStatusPlugin found %s cruft items' % n_cruft)
  59.         if n_cruft:
  60.             return [
  61.                 DpkgStatusCruft(n_cruft)]
  62.         return []
  63.  
  64.  
  65.