File: cheetah.py

package info (click to toggle)
xmds2 3.0.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 52,068 kB
  • sloc: python: 63,652; javascript: 9,230; cpp: 3,929; ansic: 1,463; makefile: 121; sh: 54
file content (57 lines) | stat: -rw-r--r-- 1,306 bytes parent folder | download | duplicates (3)
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))