-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathapp_main_page.py
67 lines (49 loc) · 1.87 KB
/
app_main_page.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
import os
import sys
import flask
import pywps
import processes
import app_config
# This is, how you start PyWPS instance
service = pywps.Service(processes=processes.processes)
# config is read in app_config so we don't need to pass it to Service as well
# service = pywps.Service(processes=processes.processes, cfgfiles=cfgfiles)
main_page = flask.Blueprint('main_page', __name__, template_folder='templates')
@main_page.route('/test')
def test():
return 'hello test!'
@main_page.route("/sys_path")
def sys_path():
return str(sys.path)
# returns 'hello to the WPS server root'
@main_page.route('/wps', methods=['GET', 'POST'])
def wps():
return service
@main_page.route("/")
def hello():
request_url = flask.request.url
return flask.render_template('home.html', request_url=request_url,
server_url=app_config.server_wps_url,
process_descriptor=processes.process_descriptor)
def flask_response(targetfile):
if os.path.isfile(targetfile):
with open(targetfile, mode='rb') as f:
file_bytes = f.read()
file_ext = os.path.splitext(targetfile)[1]
mime_type = 'text/xml' if 'xml' in file_ext else None
return flask.Response(file_bytes, content_type=mime_type)
else:
flask.abort(404)
@main_page.route('/outputs/' + '<path:filename>')
def outputfile(filename):
targetfile = os.path.join('outputs', filename)
return flask_response(targetfile)
@main_page.route('/data/' + '<path:filename>')
def datafile(filename):
targetfile = os.path.join('static', 'data', filename)
return flask_response(targetfile)
# not sure how the static route works. static route doesn't reach this function.
@main_page.route('/static/' + '<path:filename>')
def staticfile(filename):
targetfile = os.path.join('static', filename)
return flask_response(targetfile)