Please note:The SCons wiki is now restored from the attack in March 2013. All old passwords have been invalidated. Please reset your password if you have an account. If you note missing pages, please report them to webmaster@scons.org. Also, new account creation is currently disabled due to an ongoing spam flood (2013/08/27).

SCons Tool for Cheetah

Provides a SCons tool that allows SConstruct scripts to build files from Cheetah templates.

   1 import SCons.Builder
   2 import pickle
   3 
   4 def makeCheetahCommand(target, source, env, for_signature):
   5     base = 'export PYTHONPATH="${TARGET.dir}" &&' 
   6     base += 'cheetah fill --stdout --nobackup '
   7     sourceAndTarget = '$SOURCE >> $TARGET'
   8     if 'PICKLE' in env:
   9         env.Depends(target, env['PICKLE'])
  10         return base + '--pickle $PICKLE ' + sourceAndTarget
  11     else:
  12         return base + sourceAndTarget
  13 
  14 cheetahBldr = SCons.Builder.Builder(
  15     generator = makeCheetahCommand,
  16     src_suffix = '.tmpl',
  17     single_source = True,
  18 )
  19 
  20 def pickle_function(target, source, env):
  21     for i in range(len(target)):
  22         print(target[i])
  23         pickle.dump(source[i].read(), open(str(target[i]), 'wb'))
  24     return None
  25     
  26 pickleBldr = SCons.Builder.Builder(
  27     action = pickle_function,
  28     suffix = '.pkl'
  29 )
  30 
  31 def generate(env):
  32     env['BUILDERS']['Cheetah'] = cheetahBldr
  33     env['BUILDERS']['Pickle'] = pickleBldr
  34 
  35 
  36 def exists(env):
  37     return env.Detect('cheetah')

Use it something like this:

   1 pickle = env.Pickle('vars.pkl', Value({'var1':1, 'var2':2}))
   2 env.Cheetah('output.txt', 'input.tmpl', PICKLE=pickle)

CheetahBuilder (last edited 2009-02-13 20:08:17 by surface2)