This repository has been archived by the owner on Jun 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatictipy.py
68 lines (47 loc) · 1.73 KB
/
statictipy.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
# https://github.com/pymug/website-AV19-AV20
from flask import Flask
import os
import sys
from os.path import join
import settings
from jinja2 import FileSystemLoader
from jinja2 import Environment
import uuid
import datetime
from livereload import Server, shell
def generate(file_in_templates, outpath, template_dir='templates', assets_path_append='', **kwargs):
'''the raw generate function to generate files'''
file_loader = FileSystemLoader(template_dir)
env = Environment(loader=file_loader)
template = env.get_template(file_in_templates)
build_id = str(uuid.uuid4()) # to be used
output = template.render(kwargs, year=datetime.datetime.now().year,
build_id=build_id, assets_path_append=assets_path_append)
print(output, file=open(outpath, 'w+', encoding="utf8"))
context = {
'SITE_NAME': settings.SITE_NAME,
'CFP_LINK': settings.CFP_LINK,
'REVIEWERS': settings.REVIEWERS,
'ORGANISERS': settings.ORGANISERS,
'MEDIA': settings.MEDIA
}
def main(args):
def gen():
generate('index.html', join(settings.OUTPUT_FOLDER, 'index.html'), **context)
if len(args) > 1 and args[1] == '--no-server':
gen()
else:
app = Flask(__name__)
# remember to use DEBUG mode for templates auto reload
# https://github.com/lepture/python-livereload/issues/144
app.debug = True
server = Server(app.wsgi_app)
# run a shell command
#server.watch('.', 'make static')
# run a function
server.watch('.', gen, delay=3)
# output stdout into a file
#server.watch('style.less', shell('lessc style.less', output='style.css'))
server.serve()
if __name__ == '__main__':
main(sys.argv)