Skip to content

Instantly share code, notes, and snippets.

@greenarrow
Created October 29, 2010 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenarrow/653168 to your computer and use it in GitHub Desktop.
Save greenarrow/653168 to your computer and use it in GitHub Desktop.
Delete Gnome thumbnails for a list of given locations
#!/usr/bin/env python
__doc__ = """
Deletes Gnome thumbnails for a given list of directories.
Very much helped by http://software.maexotic.de/python/cleanthumbs/
"""
import os, optparse, Image, urllib
thumb_path = os.path.expanduser("~/.thumbnails")
def process_thumbnail(f):
global thumb_path
thumb = os.path.join(path, f)
try:
img = Image.open(thumb)
except IOError:
print "WARNING: Could not read file '%s'\n Thumbnail will not be deleted" % thumb
return
if not img.info.has_key("Thumb::URI"):
if options.verbose:
print "WARNING: Could not determine source file for '%s'\n Thumbnail will not be deleted" % thumb
return
original_file = urllib.unquote( img.info["Thumb::URI"] )[7:]
if len( filter( lambda p:original_file.startswith(p), args ) ):
os.remove(thumb)
if options.verbose: print "removed thumbnail: %s" % original_file
if __name__ == "__main__":
parser = optparse.OptionParser(usage="Usage: %prog [OPTION]... PATH...")
parser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False)
options, args = parser.parse_args()
# Process every file found in the thumbnail path
for path, dirs, files in os.walk(thumb_path):
map(process_thumbnail, files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment