-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpywps.wsgi
153 lines (130 loc) · 4.5 KB
/
pywps.wsgi
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright notice
# --------------------------------------------------------------------
# Copyright (C) 2022 Deltares
# Ioanna Micha
#
#
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------------------
#
# This tool is part of <a href="http://www.OpenEarth.eu">OpenEarthTools</a>.
# OpenEarthTools is an online collaboration to share and manage data and
# programming tools in an open source, version controlled environment.
# Sign up to recieve regular updates of this function, and to contribute
# your own tools.
# base package
import os
import logging
# imported packages
import flask
import pywps
from pywps.app.Service import Service
# from flask_cors import CORS
# Ultimate question
from processes.ultimate_question import UltimateQuestion
from processes.wps_mp_dataingestion import WPSMPDataIngestion
# TODO add the proces in the processes list
processes = [
UltimateQuestion(),
WPSMPDataIngestion(),
]
# Description used in template
process_descriptor = {}
for process in processes:
abstract = process.abstract
identifier = process.identifier
process_descriptor[identifier] = abstract
service = Service(processes, ["pywps.cfg"])
application = flask.Flask(__name__)
# CORS(application)
@application.route("/")
def hello():
server_url = pywps.configuration.get_config_value("server", "url")
request_url = flask.request.url
return flask.render_template(
"index.html",
request_url=request_url,
server_url=server_url,
title="Example service",
process_descriptor=process_descriptor,
)
@application.route("/wps", methods=["GET", "POST"])
def wps():
return service
@application.route("/data/" + "<path:filename>")
def outputfile(filename):
targetfile = os.path.join("data", filename)
if os.path.isfile(targetfile):
file_ext = os.path.splitext(targetfile)[1]
with open(targetfile, mode="rb") as f:
file_bytes = f.read()
mime_type = None
if "xml" in file_ext:
mime_type = "text/xml"
return flask.Response(file_bytes, content_type=mime_type)
else:
flask.abort(404)
@application.route("/static/" + "<path:filename>")
def staticfile(filename):
targetfile = os.path.join("static", filename)
if os.path.isfile(targetfile):
with open(targetfile, mode="rb") as f:
file_bytes = f.read()
mime_type = None
return flask.Response(file_bytes, content_type=mime_type)
else:
flask.abort(404)
if __name__ == "__main__":
import argparse
# application.run(debug=True)
parser = argparse.ArgumentParser(
description="""Script for starting an example PyWPS
instance with sample processes""",
epilog="""Do not use this service in a production environment.
It's intended to be running in test environment only!
For more documentation, visit http://pywps.org/doc
""",
)
parser.add_argument(
"-d", "--daemon", action="store_true", help="run in daemon mode"
)
parser.add_argument(
"-a",
"--all-addresses",
action="store_true",
help="run flask using IPv4 0.0.0.0 (all network interfaces),"
+ "otherwise bind to 127.0.0.1 (localhost). This maybe necessary in systems that only run Flask",
)
args = parser.parse_args()
if args.all_addresses:
bind_host = "0.0.0.0"
else:
bind_host = "127.0.0.1"
if args.daemon:
pid = None
try:
pid = os.fork()
except OSError as e:
raise Exception("%s [%d]" % (e.strerror, e.errno))
if pid == 0:
os.setsid()
application.run(threaded=True, host=bind_host)
else:
os._exit(0)
else:
application.run(threaded=True, host=bind_host)