Newer
Older
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
import os
import yaml
from mako.lookup import TemplateLookup
import pyrtek, pyrtek.rst, pyrtek.mako
mako_filter = pyrtek.mako.Filter(TemplateLookup(['../templates']))
rst_filter = pyrtek.rst.Filter()
filters = {'mako': mako_filter,
'rst': rst_filter,
'default': pyrtek.chain_filters(rst_filter, mako_filter)}
default_meta = {'__filter__': 'default',
'__template__': 'default.mako'}
# rexp, repl, priority, func
rules = [(r'(.*)\.txt$', r'\1.html', 0,
lambda s, d: pyrtek.Text(s, d, filters, default_meta))]
def main():
# Load catalog, if it exists.
try:
with open('catalog.yaml') as f:
catalog = yaml.load(f)
except IOError:
catalog = {}
# The following block of code is executed inside the content directory.
saved_cwd = os.getcwd();
os.chdir('content')
try:
catalog = pyrtek.build(pyrtek.expand_rules(rules), catalog)
finally:
os.chdir(saved_cwd)
# Save catalog.
with open('catalog.yaml', 'w') as f:
yaml.dump(catalog, f)
if __name__ == '__main__':
main()