home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / computerjanitor / file_cruft.py < prev    next >
Encoding:
Python Source  |  2009-04-27  |  1.7 KB  |  59 lines

  1. # file_cruft.py - implementation of file cruft 
  2. # Copyright (C) 2008, 2009  Canonical, Ltd.
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, version 3 of the License.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15.  
  16.  
  17. import os
  18.  
  19. import computerjanitor
  20. _ = computerjanitor.setup_gettext()
  21.  
  22.  
  23. class FileCruft(computerjanitor.Cruft):
  24.  
  25.     """Cruft that is individual files.
  26.     
  27.     This type of cruft consists of individual files that should be
  28.     removed. Various plugins may decide that various files are cruft;
  29.     they can all use objects of FileCruft type to mark such files,
  30.     regardless of the reason the files are considered cruft.
  31.     
  32.     When FileCruft instantiated, the file is identified by a pathname.
  33.     
  34.     """
  35.  
  36.     def __init__(self, pathname, description):
  37.         self.pathname = pathname
  38.         st = os.stat(pathname)
  39.         self.disk_usage = st.st_blocks * 512
  40.         self.description = description
  41.  
  42.     def get_prefix(self):
  43.         return "file"
  44.  
  45.     def get_prefix_description(self):
  46.         return _("A file on disk")
  47.  
  48.     def get_shortname(self):
  49.         return self.pathname
  50.  
  51.     def get_description(self):
  52.         return "%s\n" % self.description
  53.  
  54.     def get_disk_usage(self):
  55.         return self.disk_usage
  56.  
  57.     def cleanup(self):
  58.         os.remove(self.pathname)
  59.