forked from geopython/pywps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
290 lines (204 loc) · 7.96 KB
/
__init__.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
"""
This package contains classes necessary for input parsing OGC WPS requests,
working with list of processes, executing them and redirecting OGC WPS
responses back to client.
example how to use this module::
import sys
request="service=wps&request=getcapabilities"
wps = Pywps(pywps.METHOD_GET)
if wps.parserRequest(request):
response = wps.performRequest()
if response:
wps.printResponse(sys.stdout)
.. moduleauthor:: Jachym Cepicky <jachym bnhelp cz>
.. data:: METHOD_GET
String for HTTP GET method identification
.. data:: METHOD_POST
String for HTTP POST method identification
.. data:: OWS_NAMESPACE
Namespace of OGC OWS 1.1. standard
.. data:: WPS_NAMESPACE
Namespace of OGC OWS 1.0.0 standard
.. data:: XLINK_NAMESPACE
Namespace of OGC OWS 1.0.0 standard
.. data:: PYWPS_INSTALL_DIR
Directory, where Pywps is installed
.. data:: DEFAULT_LANG
Default language for WPS instance
.. data:: DEFAULT_VERSION
Default version of WPS instance
.. data:: config
Configuration file parser
.. data:: responsePrinter
:class:`ResponsePrinter` instance, which will print the resulting
response for you.
"""
__all__ = [ "Parser","processes", "Process", "Exceptions", "Wps", "Templates","Template","XSLT","Ftp"]
# Author: Jachym Cepicky
# http://les-ejk.cz
# License:
#
# Web Processing Service implementation
# Copyright (C) 2006 Jachym Cepicky
#
# This program 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 2 of the License.
#
# This program 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 program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import pywps
import config
import response
import Parser
import Exceptions
import Wps
from Exceptions import *
import logging, uuid
# global variables
METHOD_GET="GET"
METHOD_POST="POST"
OWS_NAMESPACE = "http://www.opengis.net/ows/1.1"
WPS_NAMESPACE = "http://www.opengis.net/wps/1.0.0"
XLINK_NAMESPACE = "http://www.w3.org/1999/xlink"
PYWPS_INSTALL_DIR = None # this working directory
DEFAULT_LANG = "en-CA"
DEFAULT_VERSION = "1.0.0"
logFile = None
class Pywps:
"""This is main PyWPS Class, which parses the request, performs the
desired operation and writes required response back.
:param method: Used HTTP method, which is either :data:`METHOD_POST`
or :data:`METHOD_GET`:
:type method: string
:param configFiles: List of configuration files. Ignore, if you want to use standard files location
:type configFiles: list
.. attribute:: method
METHOD_GET or METHOD_POST
.. attribute:: parser
WPS request parser
.. attribute:: inputs
Parsed inputs object
.. attribute:: request
GetCapabilities, DescribeProcess or Execute (response) object
.. attribute:: parser
GetCapabilities, DescribeProcess or Execute, POST or GET (parsing) object
.. attribute:: languages
List of supported languages
.. attribute:: versions
Default supported versions
.. attribute:: logFile
File objects, where some logs are written to.
.. note:: Use ::
import logging
logging.debug("hallo world")
for any debugging information, you want to get
"""
method = METHOD_GET # HTTP POST or GET
inputs = None # parsed input values
request = None # object with getcapabilities/describeprocess/execute
parser = None
languages = [DEFAULT_LANG]
versions=[DEFAULT_VERSION]
UUID = None
def __init__(self, method=METHOD_GET, configFiles=None):
"""Class constructor
"""
# get settings
config.loadConfiguration(configFiles)
self.setLogFile()
self.UUID = uuid.uuid1().__str__()
self.languages = config.getConfigValue("wps","lang").split(",")
DEFAULT_LANG = self.languages[0]
# set default version
self.versions = config.getConfigValue("wps","version").split(",")
DEFAULT_VERSION = self.versions[0]
# find out the request method
self.method = method
def parseRequest(self,queryStringObject):
"""
Parse input OGC WPS request, which is either URL Query string or
file object, e.g. :mod:`sys.stdin`
:param queryStringObject: string or file object with the request
:returns: Dictionary of parsed input values
:rtype: dict
"""
# decide, which method to use
# HTTP GET vs. HTTP POST
if self.method == METHOD_GET:
from Parser.Get import Get
self.parser = Get(self)
else:
from pywps.Parser.Post import Post
self.parser = Post(self)
self.inputs = self.parser.parse(queryStringObject)
return self.inputs
def performRequest(self,inputs = None, processes=None):
"""Performs the desired WSP Request.
:param inputs: idealy self.inputs (Default) object, result from
parseRequest. Default is self.inputs
:rtype: pywps.Wps.Response
"""
if inputs == None:
inputs = self.inputs
# the modules are imported first, when the request type is known
if inputs.has_key("request"):
if inputs["request"] == "getcapabilities":
from pywps.Wps.GetCapabilities import GetCapabilities
self.request = GetCapabilities(self,processes=processes)
elif inputs["request"] == "describeprocess":
from pywps.Wps.DescribeProcess import DescribeProcess
self.request = DescribeProcess(self, processes=processes)
elif inputs["request"] == "execute":
from pywps.Wps.Execute import Execute
self.request = Execute(self,processes=processes)
elif inputs.has_key("wsdl"):
inputs["version"]="1.0.0"
from pywps.Wps.Wsdl import Wsdl
self.request = Wsdl(self)
else:
raise Exceptions.InvalidParameterValue(
"request: "+inputs["request"])
self.response = self.request.response
return self.response
def setLogFile(self):
"""Set :data:`logFile`. Default is sys.stderr
"""
global logFile
fileName = config.getConfigValue("server","logFile")
logLevel = eval("logging."+config.getConfigValue("server","logLevel").upper())
format = "PyWPS [%(asctime)s] %(levelname)s: %(message)s"
if not fileName:
logging.basicConfig(level=logLevel,format=format)
else:
logging.basicConfig(filename=fileName,level=logLevel,format=format)
logFile = open(fileName, "a")
def debug(debug,code="Debug"):
"""Print debug argument to standard error
.. note:: Deprecated from 3.2, use ::
import logging
...
logging.debug("Hallo world")
or similar. See Python module :mod:`logging` for more details
:param debug: debugging text, which should be printed to the
:data:`logFile`
:type debug: string
:param code: text, which will be printed to the
:data:`logFile`
direct after 'PyWPS' and before the debug text
:type code: string.
"""
logging.debug(debug)
#dbg = config.getConfigValue("server","debug")
#if dbg == True or (type(dbg) == type("") and \
# dbg.lower() == "true") or int(dbg) != 0:
# print >>logFile, "PyWPS %s: %s" % (code,debug.__str__()[0:160]),
# if len(debug.__str__()) > 160:
# print >>logFile, "...",
# print >>logFile, "\n"