-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb.py
More file actions
145 lines (111 loc) · 3.13 KB
/
web.py
File metadata and controls
145 lines (111 loc) · 3.13 KB
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
'''
The Web module for the frontend
'''
import os
import pathlib
from flask import Flask, request, session, g, redirect, url_for, abort, \
render_template, flash
# Create our little application :)
app = Flask(
__name__,
static_folder='docs/static'
)
# Read config
app.config.from_pyfile('config.py')
# Set for jinja template engine
app.jinja_env.variable_start_string = '[['
app.jinja_env.variable_end_string = ']]'
# routers
@app.route('/')
@app.route('/index.html')
def index():
return render_template('index.html')
@app.route('/ie_editor')
@app.route('/ie_editor.html')
def ie_editor():
return render_template('ie_editor.html')
@app.route('/dt_builder')
@app.route('/dt_builder.html')
def dt_builder():
return render_template('dt_builder.html')
@app.route('/test_ie_editor')
@app.route('/test_ie_editor.html')
def test_ie_editor():
return render_template('ie_editor.html')
@app.route('/brat_demo')
@app.route('/brat_demo.html')
def brat_demo():
return render_template('brat_demo.html')
def build():
'''
Build the static website
'''
with app.test_client() as client:
with app.app_context():
for url in [
'/index.html',
'/ie_editor.html']:
make_page(
client,
url,
os.path.join(
pathlib.Path(__file__).parent.absolute(),
app.config['STATIC_PAGE_ROOT_PATH']
)
)
print('* done building static pages')
def build_test():
'''
Build the static website for test
'''
with app.test_client() as client:
with app.app_context():
for url in [
'/test_ie_editor.html']:
make_page(
client,
url,
os.path.join(
pathlib.Path(__file__).parent.absolute(),
app.config['STATIC_PAGE_ROOT_PATH']
)
)
print('* done building static pages')
def make_page(client, url, path, new_fn=None, param=None):
'''
Make static page from url
'''
rv = client.get(url)
if new_fn is None:
fn = os.path.join(
path,
url[1:]
)
else:
fn = os.path.join(
path,
new_fn
)
with open(fn, 'w') as f:
f.write(rv.data.decode('utf8'))
print('* made static page %s' % (fn))
if __name__=='__main__':
import argparse
parser = argparse.ArgumentParser(description='N3C ')
# add paramters
parser.add_argument("--mode", type=str,
choices=['build', 'build_test', 'run'], default='run',
help="Which mode?")
parser.add_argument("--path", type=str,
help="Which path for the output?")
args = parser.parse_args()
if args.mode == 'run':
app.run(
host=app.config['DEV_LISTEN'],
port=app.config['DEV_PORT'])
elif args.mode == 'build':
build()
elif args.mode == 'build_test':
build_test()
else:
parser.print_usage()