1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#!/usr/bin/env python3
# encoding: utf-8
"""
cheetah.py
Created by Graham Dennis on 2009-02-28.
"""
import random
random.seed(0)
try:
from Cheetah.Template import Template
except ImportError:
Template = None
from waflib import Task, TaskGen
def configure(conf):
conf.start_msg('Checking for the Cheetah python module')
if Template:
conf.end_msg('ok')
else:
conf.end_msg('Not found')
class cheetah(Task.Task):
ext_in = ['.tmpl']
ext_out = ['.py']
vars = ['CHEETAH_SETTINGS']
def run(self):
env = self.env
bld = self.generator.bld
input_node = self.inputs[0]
output_node = self.outputs[0]
compilerSettings = 'CHEETAH_SETTINGS' in env and env['CHEETAH_SETTINGS'] or {}
basename = input_node.change_ext('').name
pysrc = Template.compile(
file = input_node.abspath(),
compilerSettings = compilerSettings,
moduleName = basename,
className = basename,
returnAClass = False,
).decode("utf-8")
output_node.write(pysrc)
return 0
@TaskGen.extension('.tmpl')
def cheetah_callback(self, node):
out = node.change_ext('.py').name
self.create_task('cheetah', node, node.parent.find_or_declare(out))
|