-
Notifications
You must be signed in to change notification settings - Fork 0
/
website.py
executable file
·196 lines (162 loc) · 5.34 KB
/
website.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env python3
# vim: set noet ts=4 sts=4 sw=4:
import glob
import jinja2 as jinja
import argparse
import os
import datetime
from sh import cp
from sh import mkdir
import logger
import index
import pcb_table
import people
import publications
import posters
import projects
import grants
parser = argparse.ArgumentParser()
parser.description = """\
Script to generate 4908 website.
By default if no arguments are provided the entire website it rebuilt.
Please, do not check in code that generates any errors (fix them!).
Warning are okay if you must."""
parser.add_argument("-i", "--index",
help="Build the index",
action='store_true')
parser.add_argument("-I", "--no-index",
help="Don't build the index",
action='store_true')
parser.add_argument("-p", "--pcb",
help="Build the PCB table (slowest part)",
action='store_true')
parser.add_argument("-P", "--no-pcb",
help="Don't build the PCB table (faster)",
action='store_true')
parser.add_argument("-o", "--people",
help="Build the people page",
action='store_true')
parser.add_argument("-O", "--no-people",
help="Don't build the people page",
action='store_true')
parser.add_argument("-b", "--pubs",
help="Build the pubs page",
action='store_true')
parser.add_argument("-B", "--no-pubs",
help="Don't build the pubs page",
action='store_true')
parser.add_argument('-s', '--posters',
help="Build the posters",
action='store_true')
parser.add_argument('-S', '--no-posters',
help="Don't build the posters",
action='store_true')
parser.add_argument("-j", "--projects",
help="Build the projects",
action='store_true')
parser.add_argument("-J", "--no-projects",
help="Don't build the projects",
action='store_true')
args = parser.parse_args()
build_index = True
build_pcb = True
build_people = True
build_pubs = True
build_posters = True
build_projects = True
build_grants = True
if args.index or args.pcb or args.people or args.pubs or args.posters or args.projects:
build_index = False
build_pcb = False
build_people = False
build_pubs = False
build_posters = False
build_projects = False
if args.index: build_index = True
if args.pcb: build_pcb = True
if args.people: build_people = True
if args.pubs: build_pubs = True
if args.posters: build_posters = True
if args.projects: build_projects = True
if args.no_index: build_index = False
if args.no_pcb: build_pcb = False
if args.no_people: build_people = False
if args.no_pubs: build_pubs = False
if args.no_posters: build_posters = False
if args.no_projects: build_projects = False
jinja_env = jinja.Environment(loader=jinja.FileSystemLoader('templates'))
pcb_tmpl = jinja_env.get_template('pcb.html')
footer_tmpl = jinja_env.get_template('footer.html')
mkdir('-p', 'docs')
logger.info('Initializing projects')
projects_list = projects.init()
logger.info('Initializing people')
people_groups = people.init(jinja_env)
logger.info('Initializing publications')
pubs_groups = publications.init(jinja_env)
logger.info('Initializing posters')
posters = posters.init(jinja_env)
logger.info('Initializing grants')
grants_all = grants.init(jinja_env)
if build_index:
logger.info('Building site index...')
index.generate_index(projects_list, jinja_env)
if build_pcb:
logger.info('Building PCB tables...')
pcb_table = pcb_table.run(jinja_env)
pcb = pcb_tmpl.render(pcb_table=pcb_table, footer=footer_tmpl.render(curr_year=datetime.datetime.now().year))
with open('docs/pcb.html', 'w') as f:
f.write(pcb)
if build_people:
logger.info('Building people page...')
people.generate_people_page(people_groups, jinja_env)
if build_pubs:
logger.info('Building publications database...')
publications.generate_publications_page(pubs_groups, jinja_env)
if build_posters:
logger.info('Building posters...')
# no-op, this is actually all done every time because fuck it
if build_projects:
logger.info('Building projects pages...')
projects.make_project_page(
projects_list,
people_groups,
pubs_groups,
posters,
grants_all,
jinja_env)
if build_grants:
logger.info('Building grants page...')
grants.make_grant_page(grants_all, projects_list, jinja_env)
# Put all static content in the docs folder
logger.info('Copying static content...')
for dirpath,dirnames,filenames in os.walk('static'):
# Create the mirrored folders in the html directory
if len(dirnames) > 0:
for dirname in dirnames:
path = os.path.join(dirpath, dirname)
path = 'docs' + path[6:] # now that there is a hack
mkdir('-p', path)
if len(filenames) > 0:
for filename in filenames:
ext = os.path.splitext(filename)[1]
if ext in ['.css', '.js', '.ttf', '.eot', '.svg', '.woff']:
# These do not need to be compiled in any way
# Just copy them
spath = os.path.join(dirpath, filename)
dpath = 'docs' + spath[6:]
cp(spath, dpath)
# Put all the images in the html folder
logger.info('Copying HTML image content...')
mkdir('-p', os.path.join('docs', 'images'))
for dirpath,dirnames,filenames in os.walk('images'):
# Create the mirrored folders in the html directory
if len(dirnames) > 0:
for dirname in dirnames:
path = os.path.join('docs', dirpath, dirname)
mkdir('-p', path)
for filename in filenames:
spath = os.path.join(dirpath, filename)
dpath = os.path.join('docs', spath)
cp(spath, dpath)
logger.info('Site Built.')