-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild_examples.py
41 lines (36 loc) · 1.29 KB
/
build_examples.py
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
import glob
import os
import sys
import jinja2
def main():
_, theme, build_path = sys.argv
base_path = os.path.abspath(os.path.dirname(__file__))
template_path = os.path.join(base_path, 'examples')
target_path = os.path.join(base_path, build_path, theme)
try:
os.makedirs(target_path)
except OSError: # directory exists
pass
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(template_path),
extensions=['jinja2.ext.i18n'])
kwargs = {
'theme': theme,
}
kwargs['class_name'] = {
'win98': 'windows-98',
'winxp-classic': 'windows-xp-classic',
'winxp-green': 'windows-xp-green',
}[theme]
for file_path in glob.glob(os.path.join(template_path, '*.html')):
_, _, file_name = file_path.partition(template_path)
file_name = file_name.lstrip(os.path.sep)
if file_name == '_index.html':
# XXX redundant
open(os.path.join(base_path, build_path, 'index.html'), 'w+').write(
env.get_template(file_name).render(**kwargs).encode('utf-8'))
if file_name.startswith('_'):
continue
open(os.path.join(target_path, file_name), 'w+').write(
env.get_template(file_name).render(**kwargs).encode('utf-8'))
main()