-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate.py
executable file
·54 lines (48 loc) · 1.51 KB
/
template.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
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/Users/sfishman/.venvs/general/bin/python
from jinja2 import FileSystemLoader, Template
from jinja2.environment import Environment
from datetime import date
import re
import subprocess
import os
env = Environment()
env.loader = FileSystemLoader('.')
cwd = os.getcwd()
if not os.path.exists('rendered/'):
os.mkdir('rendered/')
cur_year = date.today().year
cur_month = date.today().month
if cur_month <= 6:
cur_season = "Spring"
else:
cur_season = "Fall"
subtitle = "%s Comp %d" % (cur_season, cur_year)
for root, dirs, files in os.walk(cwd):
if 'rendered' in dirs:
dirs.remove('rendered')
if '.git' in dirs:
dirs.remove('.git')
for f in files:
if root.replace(cwd, '') != '':
fname = root.replace(cwd, '')[1:] + '/' + f
else:
fname = f
if not (f == "base.html.tmp" or f == __file__[2:]):
if fname.find('.html.tmp') != -1:
if fname != "index.html.tmp":
path_start = 'rendered/' + fname[:-9]
out_name = path_start + '/index.html'
if not os.path.exists(path_start):
os.makedirs(path_start)
else:
out_name = 'rendered/' + fname[:-4]
url_path = out_name[out_name.find('/'):out_name.rfind('/') + 1]
contents = env.get_template('/' + fname).render(__path__=url_path, subtitle=subtitle)
else:
out_name = 'rendered/' + fname
with open(fname) as orig:
contents = orig.read()
if not os.path.exists(out_name[:out_name.rfind('/')]):
os.makedirs(out_name[:out_name.rfind('/')])
with open(out_name, 'w+') as out_file:
out_file.write(contents)