File:  [LON-CAPA] / doc / tutorial / Attic / converter-daemon.py
Revision 1.1: download - view: text, annotated - select for diffs
Mon Jun 3 05:15:58 2002 UTC (22 years, 1 month ago) by bowersj2
Branches: MAIN
CVS tags: version_0_4, stable_2002_july, STABLE, HEAD
Added in stuff, working on Numerical Response. Commiting from home so I
can get to it from school tommorow.

----------------------------------------------------------------------

    1: """Run this script in the background while you're working on the
    2: tutorial. Every five seconds, it scans for .pngs, .jpgs, and ..gifs
    3: that have not yet been coverted to encapsulated postscript. If it
    4: finds one, it converts it to an encapsulated postscript file of
    5: the same name.
    6: 
    7: Requires the Python Imaging Library, a very common python library."""
    8: 
    9: import Image
   10: import os
   11: import time
   12: import string
   13: 
   14: extensionsToConvert = [ 'png', 'gif', 'jpg' ]
   15: 
   16: def stripSuffix(s):
   17:     return s[:string.rfind(s, ".")]
   18: def suffix(s):
   19:     return s[string.rfind(s, ".")+1:]
   20: 
   21: while 1:
   22:     filelist = os.listdir(".")
   23: 
   24:     epsDict = {}
   25:     for f in filelist:
   26:         if suffix(f) == "eps":
   27:             epsDict[stripSuffix(f)] = 0
   28: 
   29:     for f in filelist:
   30:         if suffix(f) in extensionsToConvert and \
   31:            not epsDict.has_key(stripSuffix(f)):
   32:             try:
   33:                 im = Image.open(f)
   34:             except:
   35:                 print "failed:", f
   36:             im.save(stripSuffix(f) + ".eps")
   37:             print "Converted " + f
   38: 
   39:     time.sleep(5)
   40: 
   41: 
   42:     
   43:     
   44:     
   45:     
   46:     
   47:     

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>