2 from mako
.lookup
import TemplateLookup
7 rfc3339
= "%Y-%m-%dT%H:%M:%S"
11 templates
= TemplateLookup(directories
=[cfg
['templatedir']])
12 def render(name
, **namespace
):
14 return templates
.get_template(name
).render(
20 # gnu make like functinality
21 def last_modified(filename
):
22 return os
.stat(filename
).st_mtime
24 def make(target
, deps
, content_generator
, *args
, **kwargs
):
25 if cfg
['regen'] or not os
.path
.exists(target
) or \
26 True in [last_modified(target
) < last_modified(d
) for d
in deps
]:
29 content
= content_generator(*args
, **kwargs
)
30 open(target
, 'w').write(content
)
32 def make_mako(target
, deps
, name
, **additional_namespace
):
34 Wrapper around make/mako. Introduces mako files itself as one of deps
36 templatefile
= os
.path
.join(cfg
['templatedir'], name
)
38 namespace
= sys
._getframe
(1).f_locals
39 namespace
.update(additional_namespace
)
41 return make(target
, deps
+[templatefile
], mako
, name
, **namespace
)
43 __all__
= ['rfc3339', 'mako', 'make', 'make_mako', 'last_modified']