7 from os.path import walk, getctime
9 root = os.path.dirname(os.path.abspath(__file__))
11 from jinja2 import Environment, FileSystemLoader
12 jinja_env = Environment(loader=FileSystemLoader(root))
14 def render_walk(arg=None, dirname='', filenames=[]):
15 for filename in filenames:
16 match = re.match(r'(.*)\.tmpl$', filename)
18 filename_base = match.group(1)
20 # skip if this is the layout file
21 if filename_base == 'layout': continue
22 if filename_base == 'latex-like-layout': continue
24 vars = { 'last_modified' :
25 unicode(ctime(getctime(os.path.join(dirname, filename)))) }
27 # remove the root from the dirname
28 dirname = re.sub(re.escape(root) + r'/?(.*)$', r'\1', dirname)
30 tmpl = jinja_env.get_template(os.path.join(dirname, filename))
33 output_file = codecs.open(os.path.join(dirname, filename_base + '.html'), 'w', 'utf-8')
34 print >>output_file, tmpl.render(vars)
38 walk(root, render_walk, None)