📄 cleanerbackend.py
字号:
# vim: ts=4:sw=4:expandtab## BleachBit## Copyright (C) 2009 Andrew Ziem## http://bleachbit.sourceforge.net#### This program is free software: you can redistribute it and/or modify## it under the terms of the GNU General Public License as published by## the Free Software Foundation, either version 3 of the License, or## (at your option) any later version.#### This program is distributed in the hope that it will be useful,## but WITHOUT ANY WARRANTY; without even the implied warranty of## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the## GNU General Public License for more details.#### You should have received a copy of the GNU General Public License## along with this program. If not, see <http://www.gnu.org/licenses/>."""Perform (or assist with) cleaning operations."""from gettext import gettext as _import globimport gtkimport os.pathimport reimport subprocessimport sysimport xml.dom.minidomimport FileUtilitiesimport globalsfrom FileUtilities import children_in_directoryfrom Options import optionsclass Cleaner: """Base class for a cleaner""" def __init__(self): self.options = {} def add_option(self, option_id, name, description): self.options[option_id] = ( name, False, description ) def available(self): """Is the cleaner available?""" return True def get_description(self): """Brief description of the cleaner""" return "" def get_id(self): """Return the unique name of this cleaner""" return None def get_name(self): """Return the human name of this cleaner""" return None def get_option_descriptions(self): """Yield the names and descriptions of each option in a 2-tuple""" if self.options: for key in sorted(self.options.keys()): yield ((self.options[key][0], self.options[key][2])) def get_options(self): """Return user-configurable options in 3-tuple (id, name, enabled)""" r = [] if self.options: for key in sorted(self.options.keys()): r.append((key, self.options[key][0], self.options[key][1])) return r def list_files(self): """Iterate files that would be removed""" def other_cleanup(self, really_delete): """Perform an operation more specialized than removing a file""" def set_option(self, option_id, value): """Enable or disable an option""" assert self.options.has_key(option_id) self.options[option_id] = (self.options[option_id][0], \ value, self.options[option_id][2])class Bash(Cleaner): """Delete the Bash history""" def get_description(self): return _("Delete the Bash history") def get_id(self): return 'bash' def get_name(self): return "Bash" def list_files(self): filename = os.path.expanduser("~/.bash_history") if os.path.lexists(filename): yield filenameclass Beagle(Cleaner): """Beagle""" def get_description(self): return _("Delete Beagle indexes and logs") def get_id(self): return 'beagle' def get_name(self): return "Beagle" def list_files(self): dirs = [ "~/.beagle/Indexes", "~/.beagle/Log", "~/.beagle/TextCache" ] for dirname in dirs: dirname = os.path.expanduser(dirname) for filename in children_in_directory(dirname, False): if os.path.lexists(filename): yield filenameclass Epiphany(Cleaner): """Epiphany""" def __init__(self): Cleaner.__init__(self) self.add_option('cache', _('Cache'), _('Web cache reduces time to display revisited pages')) self.add_option('cookies', _('Cookies'), _('HTTP cookies contain information such as web site prefereneces, authentication, and tracking identification')) self.add_option('download_history', _('Download history'), _('List of files downloaded')) self.add_option('passwords', _('Passwords'), _('A database of usernames and passwords as well as a list of sites that should not store passwords')) self.add_option('places', _('Places'), _('A database of URLs including bookmarks and a history of visited web sites')) def get_description(self): return _("Epiphany web browser") def get_id(self): return 'epiphany' def get_name(self): return "Epiphany" def list_files(self): files = [] # browser cache if self.options["cache"][1]: dirs = glob.glob(os.path.expanduser("~/.gnome2/epiphany/mozilla/epiphany/Cache/")) dirs += glob.glob(os.path.expanduser("~/.gnome2/epiphany/favicon_cache/")) for dirname in dirs: for filename in children_in_directory(dirname, False): yield filename files += [ os.path.expanduser("~/.gnome2/epiphany/ephy-favicon-cache.xml") ] # cookies if self.options["cookies"][1]: files += [ os.path.expanduser("~/.gnome2/epiphany/mozilla/epiphany/cookies.txt") ] files += [ os.path.expanduser("~/.gnome2/epiphany/mozilla/epiphany/cookies.sqlite") ] files += [ os.path.expanduser("~/.gnome2/epiphany/mozilla/epiphany/cookies.sqlite-journal") ] # password if self.options["passwords"][1]: files += [ os.path.expanduser("~/.gnome2/epiphany/mozilla/epiphany/signons3.txt") ] # places database if self.options["places"][1]: files += [ os.path.expanduser("~/.gnome2/epiphany/mozilla/epiphany/places.sqlite") ] files += [ os.path.expanduser("~/.gnome2/epiphany/mozilla/epiphany/places.sqlite-journal") ] files += [ os.path.expanduser("~/.gnome2/epiphany/ephy-history.xml") ] # finish for filename in files: if os.path.lexists(filename): yield filenameclass Firefox(Cleaner): """Mozilla Firefox""" def __init__(self): Cleaner.__init__(self) self.add_option('cache', _('Cache'), _('Web cache reduces time to display revisited pages')) self.add_option('cookies', _('Cookies'), _('HTTP cookies contain information such as web site prefereneces, authentication, and tracking identification')) self.add_option('download_history', _('Download history'), _('List of files downloaded')) self.add_option('forms', _('Form history'), _('A history of forms entered in web sites and in the Search bar')) self.add_option('session_restore', _('Session restore'), _('Loads the initial session after the browser closes or crashes')) self.add_option('passwords', _('Passwords'), _('A database of usernames and passwords as well as a list of sites that should not store passwords')) self.add_option('places', _('Places'), _('A database of URLs including bookmarks and a history of visited web sites')) self.profile_dir = "~/.mozilla/firefox/*/" def get_description(self): return _("Mozilla Firefox web browser") def get_id(self): return 'firefox' def get_name(self): return "Firefox" def list_files(self): # browser cache if self.options["cache"][1]: dirs = glob.glob(os.path.expanduser(self.profile_dir + "/Cache/")) dirs += glob.glob(os.path.expanduser(self.profile_dir + "/OfflineCache/")) for dirname in dirs: for filename in children_in_directory(dirname, False): yield filename files = [] # cookies if self.options["cookies"][1]: files += glob.glob(os.path.expanduser(self.profile_dir + "/cookies.txt")) files += glob.glob(os.path.expanduser(self.profile_dir + "/cookies.sqlite")) # download history if self.options["download_history"][1]: # Firefox version 1 files += glob.glob(os.path.expanduser(self.profile_dir + "/downloads.rdf")) # Firefox version 3 files += glob.glob(os.path.expanduser(self.profile_dir + "/downloads.sqlite")) # forms if self.options["forms"][1]: files += glob.glob(os.path.expanduser(self.profile_dir + "/formhistory.sqlite")) files += glob.glob(os.path.expanduser(self.profile_dir + "/formhistory.dat")) # passwords if self.options["passwords"][1]: files += glob.glob(os.path.expanduser(self.profile_dir + "/signons.txt")) files += glob.glob(os.path.expanduser(self.profile_dir + "/signons[2-3].txt")) # places database if self.options["places"][1]: # Firefox version 1 files += glob.glob(os.path.expanduser(self.profile_dir + "/history.dat")) # Firefox version 3 files += glob.glob(os.path.expanduser(self.profile_dir + "/places.sqlite")) files += glob.glob(os.path.expanduser(self.profile_dir + "/places.sqlite-journal")) # session restore if self.options["session_restore"][1]: files += glob.glob(os.path.expanduser(self.profile_dir + "/sessionstore.js")) # finish for filename in files: yield filenameclass Flash(Cleaner): """Adobe Flash""" def get_description(self): return _("Delete Adobe Flash's cache and settings") def get_id(self): return 'flash' def get_name(self): return "Flash" def list_files(self): dirname = os.path.expanduser("~/.macromedia/Flash_Player/macromedia.com/support/flashplayer/sys") for filename in children_in_directory(dirname, True): yield filenameclass System(Cleaner): """System in general""" def __init__(self): Cleaner.__init__(self) self.add_option('desktop_entry', _('Broken desktop entries'), _('Unusable .desktop files (menu entries and file associtations) that are either invalid structurally or point to non-existant locations')) self.add_option('clipboard', _('Clipboard'), _('The desktop environment\'s clipboard used for copy and paste operations')) self.add_option('cache', _('Cache'), _('Cache location specified by XDG and used by various applications')) self.add_option('localizations', _('Localizations'), _('Data used to operate the system in various languages and countries')) self.add_option('tmp', _('Temporary files'), _('User-owned, unopened, regular files in /tmp/ and /var/tmp/')) self.add_option('trash', _('Trash'), _('Temporary storage for deleted files')) self.add_option('recent_documents', _('Recent documents list'), _('A common list of recently used documents')) def get_description(self): return _("The system in general") def get_id(self): return 'system' def get_name(self): return _("System") def list_files(self): # cache if self.options["cache"][1]: dirname = os.path.expanduser("~/.cache/") for filename in children_in_directory(dirname, True): yield filename # menu menu_dirs = [ '~/.local/share/applications', \ '~/.config/autostart', \ '~/.gnome/apps/', \ '~/.gnome2/panel2.d/default/launchers', \ '~/.gnome2/vfolders/applications/', \ '~/.kde/share/apps/RecentDocuments/', \ '~/.kde/share/mimelnk', \ '~/.kde/share/mimelnk/application/ram.desktop', \ '~/.kde2/share/mimelnk/application/', \ '~/.kde2/share/applnk' ] if self.options["desktop_entry"][1]: for dirname in menu_dirs: for filename in [fn for fn in children_in_directory(dirname, False) \ if fn.endswith('.desktop') ]: if FileUtilities.is_broken_xdg_desktop(filename): yield filename # unwanted locales if self.options["localizations"][1]: import Unix callback = lambda locale, language: options.get_language(language) for path in Unix.locales.localization_paths(callback): yield path # most recently used documents list files = [] if self.options["recent_documents"][1]: files += [ os.path.expanduser("~/.recently-used") ] files += [ os.path.expanduser("~/.recently-used.xbel") ] # fixme http://www.freedesktop.org/wiki/Specifications/desktop-bookmark-spec # temporary if self.options["trash"][1]: dirnames = [ '/tmp', '/var/tmp' ] for dirname in dirnames: for path in children_in_directory(dirname, True): is_open = FileUtilities.openfiles.is_open(path) ok = not is_open and os.path.isfile(path) and \ not os.path.islink(path) and \ FileUtilities.ego_owner(path) and \ not self.whitelisted(path) if ok: yield path # trash if self.options["trash"][1]: dirname = os.path.expanduser("~/.Trash") for filename in children_in_directory(dirname, False): yield filename # fixme http://www.ramendik.ru/docs/trashspec.html # http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html # ~/.local/share/Trash # * GNOME 2.22, Fedora 9 # * KDE 4.1.3, Ubuntu 8.10 dirname = os.path.expanduser("~/.local/share/Trash") for filename in children_in_directory(dirname, False): yield filename # finish for filename in files: if os.path.lexists(filename): yield filename
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -