Bonjour,
Puisque tu fais référence à la rapidité... c'est précisément à cela que sert la mémorisation des vignettes pour les photos.
Lorsque tu supprimes ces données, tu gagnes en effet (un peu) de place, mais à la prochaine ouverture du dossier qui contient les photos, les vignettes sont recréées, ça prend du temps et tu as l'impression que ton système est moins réactif !
Par contre, je suis d'accord avec toi sur le fait que TOUTES les vignettes n'ont pas à être conservées, notamment celles correspondant à des supports amovibles qui ne sont plus en ligne, celles dont l'image correspondante a été supprimée, déplacée, etc...
Il existe un petit script qui fait un nettoyage "intelligent" en identifiant les vignettes pour lesquelles il existe encore une image correspondante qui sont à conserver, et les autres qu'il peut détruire.
Ceci a l'avantage de ménager l'espace de stockage et la rapidité d'accès aux images, la chèvre et le chou en quelque sorte !
Bon, le script doit quand même être lancé manuellement de temps en temps pour faire le boulot, mais rien n'interdit de prévoir son lancement automatique à l'ouverture de session pour qu'il nettoie chaque fois les vignettes sans fondement...
Ce script s'appelle "ThCleaner.py" (on doit sûrement le trouver encore sur le net) et en voici le code ci-dessous :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Date : oct 01 2010
#
# Author : Vincent Vande Vyvre <vins@swing.be>
# Licence : WTPFL v2 <http://sam.zoy.org/wtfpl/>
import sys
import os
import glob
import time
import getopt
from urlparse import urlparse
from urllib import unquote
import Image
class Cleaner(object):
def __init__(self, fn, fl, web=True, removable=False):
self.fn = fn
self.fl = fl
self.web = web
self.rem = removable
self.amount_normal = 0
self.amount_large = 0
self.size_normal = 0
self.size_large = 0
self.unremoved = []
def process(self):
"""Main process.
"""
if self.fn:
# Begin ~/.thumbnails/normal process
print " Nettoyage du dossier %s en cours ..." % self.fn
reply = self.clean(self.fn)
self.size_normal, self.amount_normal = reply[0], reply[1]
print "\n Nettoyage du dossier %s terminé.\n" % self.fn
print " %s thumbnails supprimés." % self.amount_normal
print " %s octets libérés.\n" % self.size_normal
if self.fl:
# Begin ~/.thumbnails/large process
print " Nettoyage du dossier %s en cours ..." % self.fl
reply = self.clean(self.fl)
self.size_large, self.amount_large = reply[0], reply[1]
print "\n Nettoyage du dossier %s terminé.\n" % self.fl
print " %s thumbnails supprimés." % self.amount_large
print " %s octets libérés.\n" % self.size_large
at = self.amount_normal + self.amount_large
st = self.size_normal + self.size_large
print " Terminé, total des thumbnails supprimés : %s" % at
print " total de l'espace disque libéré : %s" % st
if self.unremoved:
# Some files are non regular
chain = """\n Les fichiers suivants ne semblent pas"\
être des thumbnails
conformes et n'ont pas pu être supprimés :"""
if len(self.unremoved) < 20:
print chain
for ur in self.unremoved:
print " ", ur
else:
# If the list is too long, we create a text file
f = os.path.join(os.path.expanduser("~"),
"thumbnail_unremoved.txt")
with open(f, "w") as fobj:
fobj.write(time.strftime("%A %d %B %Y %H:%M:%S",
time.localtime()))
fobj.write("\n")
fobj.write(chain)
fobj.write("\n ")
for u in self.unremoved:
fobj.write(u)
fobj.write("\n ")
print "\n Certains fichiers n'ont pu être supprimés."
print " La liste de ces fichiers a été créée dans "\
"ce fichier :\n"
print " %s" % f
print "\n"
# Ite missa est
sys.exit()
def clean(self, f):
"""Open one folder and create the list of files into the folder.
Keyword arguments :
f -- folder
Returns :
Number of deleted files
Sum of size of all deleted files
"""
chain = os.path.join(f, "*.*")
lst = glob.glob(chain)
thumbs = len(lst)
loop = int(thumbs/100)
tot_size, tot_thumb = 0, 0
i = 0
pc = 0
for l in lst:
i += 1
if i == loop:
pc += 1
print "\rProgress",
print ".............%s %%" % pc, #XXX strange result
i = 0
if os.path.isfile(l) and l.endswith(".png"):
try:
img = Image.open(l)
# Source: http://jens.triq.net/thumbnail-spec/index.html
if img.info.has_key("Thumb::URI"):
uri = unquote(img.info["Thumb::URI"])
reply = self.control_origin(uri, l)
if reply:
tot_size += reply
tot_thumb += 1
else:
self.unremoved.append("".join([l, " No URI key"]))
except Exception, why:
self.unremoved.append("".join([l, " ", str(why)]))
else:
self.unremoved.append("".join([l, " Not a .png file"]))
return (tot_size, tot_thumb)
def control_origin(self, uri, th):
"""Validate thumbnail or not.
Keyword arguments :
uri -- the uri of original image
th -- thumbnail (full path)
Returns :
The size of deleted file or false if not deleted
"""
delete = False
(scheme, n, path, p, q, f) = urlparse(uri)
if self.web and (scheme[:4] == "http" or scheme == "ftp"):
delete = os.stat(th).st_size
elif self.rem and path.startswith('/media/'):
delete = os.stat(th).st_size
elif scheme == "file" and not os.path.isfile(path):
delete = os.stat(th).st_size
if delete:
try:
os.unlink(th)
except Exception, why:
self.unremoved.append("".join([th, " ", str(why)]))
delete = False
return delete
print "\n ** ThCleaner **\n\n Vérification des dossiers ..."
thpath = os.path.join(os.path.expanduser("~"), ".thumbnails")
if os.path.isdir(thpath):
error = 0
thnpath = os.path.join(thpath, "normal")
# Search ~/.thumbnails/normal
if not os.path.isdir(thnpath):
thnpath, error = None, 1
thlpath = os.path.join(thpath, "large")
# Search ~/.thumbnails/large
if not os.path.isdir(thlpath):
thlpath = None
error += 1
if error != 2:
# There's at last one folder
# Assume stdout is console
print "\n Dossier %s reconnu, choisissez les options "\
"de nettoyage :\n" % thpath
while 1:
# Delete thumbnail of image from the web ?
r = raw_input(" - Supprimer les thumbnails provenant"
" d'internet : O-N Oui ")
if r in ["", "O", "o", "Oui", "oui", "OUI", "Oh oui"]:
w = True
break
elif r in ["N", "n", "Non", "non", "NON", "NOOON!"]:
w = False
break
else:
print " !! La réponse doit être Oui ou Non."
while 1:
# Delete thumbnails of image from removable medias ?
r = raw_input(" - Supprimer les thumbnails provenant "
"de supports amovibles : O-N Non ")
if r in ["O", "o", "Oui", "oui", "OUI", "Oh oui"]:
d = True
break
elif r in ["", "N", "n", "Non", "non", "NON", "NOOON!"]:
d = False
break
else:
print " !! La réponse doit être Oui ou Non."
cl = Cleaner(thnpath, thlpath, w, d)
cl.process()
else:
print "\n !! ThCleaner ne peut trouver les dossiers %s" \
"\n %s\n" % (thnpath, thlpath)
else:
print "\n !! ThCleaner ne peut trouver le dossier %s \n" % thpath
Si ça te tente de l'essayer...