-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpsstart.py
136 lines (100 loc) · 3.79 KB
/
wpsstart.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
import sys, ast, getopt, WPSClient.WPSClient as WPSClient
# from locale import str
import logging
# from iguess_db_credentials import logFileName
def configLogging(logfile, loglevel):
'''
Set up the logging file
'''
format = "[%(asctime)s] %(levelname)s: %(message)s"
logging.basicConfig(filename=logfile, level=loglevel, format=format)
# Configure logging
#configLogging(logFileName, "INFO")
argv = sys.argv[1:]
#logging.info("Processing command: " + " ".join(argv))
# Code modeled on http://stackoverflow.com/questions/7605631/passing-a-list-to-python-from-command-line
arg_dict = { }
# Params (and the types) we expect IMPORTANT: make sure each starts with a different letter!!!
switches = { 'url':str, 'procname':str, 'inputs':list, 'outputs':dict}
singles = '' . join([x[0] + ':' for x in switches])
long_form = [x + '=' for x in switches]
d = {}
for x in switches:
d[x[0] + ':'] = '--' + x
# Command line example
# --url="http://localhost/cgi-bin/pywps.cgi" --procname="test_rand_map" --inputs="[('delay', '500')]" --outnames="[('rand', 'True'),('region', 'True')]" --titles="['LdS.RandomRast','LdS.RegionRast']"
try:
opts, args = getopt.getopt(argv, singles, long_form)
except getopt.GetoptError, e:
# logging.error("Bad arg: " + e.msg)
sys.exit(2)
for opt, arg in opts:
if opt[1] + ':' in d: # opt -> :names
o = d[opt[1] + ':'][2:] # o -> names
elif opt in d.values():
o = opt[2:]
else: o = ''
if o and arg:
if switches[o] == tuple or switches[o] == list or switches[o] == dict:
arg_dict[o] = ast.literal_eval(arg)
else:
arg_dict[o] = arg
if not o:
# logging.error("Invalid options!\n")
sys.exit(2)
#Error: bad arg for names... [dem] is not a <type 'list'>!
if not isinstance(arg_dict[o], switches[o]):
# logging.error(str(opt) + " " + str(arg) + "\nError: bad arg for " + o + "... " + str(arg_dict[o]) + " is not a " + str(switches[o]) + "!")
sys.exit(2)
# Now that we have our args sorted out, let's try to launch the WPSClient
iniCli = WPSClient.WPSClient()
# Basic test with literal inputs
#iniCli.init(
# "http://services.iguess.tudor.lu/cgi-bin/pywps.cgi?",
# "test_rand_map",
# ["delay"],
# ["1"],
# ["rand", "region", "num"])
# Test with a remote GML resource
#iniCli.init(
# "http://services.iguess.tudor.lu/cgi-bin/pywps.cgi?",
# "buffer",
# ["size","data"],
# ["5","http://services.iguess.tudor.lu/pywps/sampleData/testLines4326.gml"],
# ["buffer"])
# Test with a WFS resource
iniCli.init(
# Process Server address
arg_dict['url'] + '?',
# Process name
arg_dict['procname'],
# Inputs
arg_dict['inputs'],
# Output names
arg_dict['outputs'])
try:
url = iniCli.sendRequest()
except Exception, e: # iniCli encountered an error
sys.stdout.write("ERR:" + str(e))
sys.exit()
# iniCli is happy!
#logging.info("Launching process: " + url)
sys.stdout.write("OK:" + url)
# if(url == None): # iniCli encountered an error
# sys.stdout.write("ERR:" + iniCli.lastLogMessage)
# else: # iniCli is happy!
# logging.info("Launching process: " + url + "\n")
# sys.stdout.write("OK:" + url) # This is the line that our rails code will be looking for!
# iniCli = None
# if(url == None):
# print "Sorry something went wrong."
# else:
# statCli = WPSClient.WPSClient()
# statCli.initFromURL(url)
# while not statCli.checkStatus():
# print "Waiting..."
# time.sleep(10)
# # Needed because PyWPS deletes CRS information from the outputs
# # Maybe it should be a parameter to the constructor?
# statCli.epsg = "28992"
# statCli.generateMapFile()