Annotation of doc/tutorial/converter-daemon.py, revision 1.1

1.1     ! bowersj2    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>