]> projects.mako.cc - freedom_for_users-l10n/blob - render_templates.py
merged the translation over to using my templates
[freedom_for_users-l10n] / render_templates.py
1 #!/usr/bin/env python
2
3 import os
4 import re
5 import codecs
6 from time import ctime
7 from os.path import walk, getctime
8
9 root = os.path.dirname(os.path.abspath(__file__))
10
11 from jinja2 import Environment, FileSystemLoader
12 jinja_env = Environment(loader=FileSystemLoader(root))
13
14 def render_walk(arg=None, dirname='', filenames=[]):
15     for filename in filenames:
16         match = re.match(r'(.*)\.tmpl$', filename)
17         if match:
18             filename_base = match.group(1)
19
20             # skip if this is the layout file
21             if filename_base == 'layout': continue
22             if filename_base == 'latex-like-layout': continue
23
24             vars = { 'last_modified' :
25                      unicode(ctime(getctime(os.path.join(dirname, filename)))) }
26
27             # remove the root from the dirname
28             dirname = re.sub(re.escape(root) + r'/?(.*)$', r'\1', dirname) 
29
30             tmpl = jinja_env.get_template(os.path.join(dirname, filename))
31             tmpl.render(vars)
32
33             output_file = codecs.open(os.path.join(dirname, filename_base + '.html'), 'w', 'utf-8')
34             print >>output_file, tmpl.render(vars)
35             output_file.close()
36
37 os.chdir(root)
38 walk(root, render_walk, None)
39
40

Benjamin Mako Hill || Want to submit a patch?