Update of /cvsroot/freevo/freevo/src/helpers
In directory sc8-pr-cvs1:/tmp/cvs-serv20407

Modified Files:
        cache.py 
Log Message:
also cache thumbnails for config.OVERLAY_DIR_STORE_THUMBNAILS:

Index: cache.py
===================================================================
RCS file: /cvsroot/freevo/freevo/src/helpers/cache.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** cache.py    30 Dec 2003 15:36:42 -0000      1.10
--- cache.py    31 Dec 2003 16:43:28 -0000      1.11
***************
*** 12,15 ****
--- 12,18 ----
  # -----------------------------------------------------------------------
  # $Log$
+ # Revision 1.11  2003/12/31 16:43:28  dischi
+ # also cache thumbnails for config.OVERLAY_DIR_STORE_THUMBNAILS:
+ #
  # Revision 1.10  2003/12/30 15:36:42  dischi
  # support OVERLAY_DIR_STORE_MMPYTHON_DATA
***************
*** 60,63 ****
--- 63,67 ----
  import stat
  import time
+ import copy
  
  def delete_old_files():
***************
*** 144,150 ****
      if rebuild:
          print 'deleting cache files'
!         for f in ([ os.path.join(mmcache, fname) for fname in os.listdir(mmcache) ]):
!             if os.path.isfile(f):
!                 os.unlink(f)
      all_dirs = []
      print 'caching directories...'
--- 148,158 ----
      if rebuild:
          print 'deleting cache files'
!         if config.OVERLAY_DIR_STORE_MMPYTHON_DATA:
!             print 'XXX FIXME: code not written yet'
!         else:
!             for f in ([ os.path.join(mmcache, fname) for fname in 
os.listdir(mmcache) ]):
!                 if os.path.isfile(f):
!                     os.unlink(f)
! 
      all_dirs = []
      print 'caching directories...'
***************
*** 157,160 ****
--- 165,169 ----
              continue
          os.path.walk(d, cache_helper, all_dirs)
+ 
      for d in all_dirs:
          dname = d
***************
*** 165,168 ****
--- 174,248 ----
          
      util.touch('%s/VERSION' % mmcache)
+     print
+ 
+ 
+ def cache_thumbnails():
+     from mmpython.image import EXIF as exif
+     import cStringIO
+     import stat
+     import Image
+     
+     print 'caching thumbnails'
+ 
+     files = []
+     for d in config.VIDEO_ITEMS + config.AUDIO_ITEMS + config.IMAGE_ITEMS:
+         try:
+             d = d[1]
+         except:
+             pass
+         if not os.path.isdir(d):
+             continue
+         files += util.match_files_recursively(d, config.IMAGE_SUFFIX)
+ 
+     for filename in copy.copy(files):
+         sinfo = os.stat(filename)
+         thumb = vfs.getoverlay(filename + '.raw')
+         try:
+             if os.stat(thumb)[stat.ST_MTIME] > sinfo[stat.ST_MTIME]:
+                 files.remove(filename)
+         except OSError:
+             pass
+ 
+     for filename in files:
+         fname = filename
+         if len(fname) > 65:
+             fname = fname[:20] + ' [...] ' + fname[-40:]
+         print '  %4d/%-4d %s' % (files.index(filename)+1, len(files), fname)
+ 
+         sinfo = os.stat(filename)
+         thumb = vfs.getoverlay(filename + '.raw')
+         try:
+             if os.stat(thumb)[stat.ST_MTIME] > sinfo[stat.ST_MTIME]:
+                 continue
+         except OSError:
+             pass
+ 
+         f=open(filename, 'rb')
+         tags=exif.process_file(f)
+         f.close()
+ 
+         try:
+             if tags.has_key('JPEGThumbnail'):
+                 image = Image.open(cStringIO.StringIO(tags['JPEGThumbnail']))
+             else:
+                 # convert with Imaging
+                 image = Image.open(filename)
+         except:
+             continue
+         
+         if image.size[0] > 300 and image.size[1] > 300:
+             image.thumbnail((300,300))
+ 
+         if image.mode == 'P':
+             image = image.convert('RGB')
+ 
+         # save for future use
+         if config.OVERLAY_DIR_STORE_THUMBNAILS:
+             data = (image.tostring(), image.size, image.mode)
+             util.save_pickle(data, thumb)
+         else:
+             data = (filename, image.tostring(), image.size, image.mode)
+             util.save_pickle(data, thumb)
+ 
  
  
***************
*** 187,188 ****
--- 267,271 ----
          delete_old_mmpython_cache()
          cache_directories(0)
+ 
+     if config.OVERLAY_DIR_STORE_THUMBNAILS:
+         cache_thumbnails()




-------------------------------------------------------
This SF.net email is sponsored by: IBM Linux Tutorials.
Become an expert in LINUX or just sharpen your skills.  Sign up for IBM's
Free Linux Tutorials.  Learn everything from the bash shell to sys admin.
Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click
_______________________________________________
Freevo-cvslog mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to