1
2
3
4
5
6
7
8
9 """
10 This is the documentation for the Python API bindings for the SAGA C++
11 reference implementation (U{http://www.saga-project.org}). They provide a thin
12 Python wrapper on top of the native SAGA C++ API. This allows you to use SAGA
13 and all of its middleware adaptors from within your Python code.
14
15 B{Here's a simple example how to submit a job using SAGA and Python}::
16 import saga
17
18 try:
19 # create an "echo 'hello, world' job"
20 jd = saga.job.description()
21 jd.set_attribute("Executable", "/bin/echo")
22 jd.set_vector_attribute("Arguments", ["Hello, World!"])
23 jd.set_attribute("Interactive", "True")
24
25 # connect to the local job service
26 js = saga.job.service("fork://localhost");
27
28 # submit the job
29 job = js.create_job(jd)
30 job.run()
31
32 # wait for the job to complete
33 job.wait(-1)
34
35 # print the job's output
36 output = job.get_stdout()
37 print output.read()
38
39 except saga.exception, e:
40 print "ERROR: "
41 for err in e.get_all_messages():
42 print err
43
44
45 Unfortunately, the bindings are mostly auto-generated from the C++ code, that's
46 why the documentation is rather minimalistic. If you're looking for more
47 details on a specific class or method, you should refer to the C++ API
48 documentation which can be found here:
49 U{http://www.saga-project.org/documentation/python}
50 """
51
52
53 import sys
54
55 required_ver_maj = str(2)
56 required_ver_min = str(7)
57 required_ver_sub = str(1)
58
59 python_version = str(sys.version[0:5])
60 python_ver_maj = str(sys.version[0:1])
61 python_ver_min = str(sys.version[2:3])
62 python_ver_sub = str(sys.version[4:5])
63
64 if (python_ver_maj != required_ver_maj or
65 python_ver_min != required_ver_min or
66 python_ver_sub != required_ver_sub):
67 sys.stderr.write("ERROR: The SAGA Python modules were compiled for "
68 "Python "+required_ver_maj+"."+required_ver_min+"."+required_ver_sub+
69 " but you are using them with Python "+python_version+".\n")
70 exit(1)
71
72 from _engine import *
73
74
75
76 import os
77 SAGA_LOG = 0
78 try:
79 SAGA_LOG = long(os.getenv("SAGA_VERBOSE", "0"))
80 except:
81 pass
82
83
84 try:
85 import saga.name_space
86 if (SAGA_LOG != 0):
87 print "Successfully loaded Python namespace package bindings"
88 except:
89 if (SAGA_LOG != 0):
90 print "Failed loading Python namespace package bindings"
91
92
93 try:
94 import saga.filesystem
95 if (SAGA_LOG != 0):
96 print "Successfully loaded Python filesystem package bindings"
97 except:
98 if (SAGA_LOG != 0):
99 print "Failed loading Python filesystem package bindings"
100
101
102 try:
103 import saga.advert
104 if (SAGA_LOG != 0):
105 print "Successfully loaded Python advert package bindings"
106 except:
107 if (SAGA_LOG != 0):
108 print "Failed loading Python advert package bindings"
109
110
111 try:
112 import saga.job
113 if (SAGA_LOG != 0):
114 print "Successfully loaded Python job package bindings"
115 except:
116 if (SAGA_LOG != 0):
117 print "Failed loading Python job package bindings"
118
119
120 try:
121 import saga.replica
122 if (SAGA_LOG != 0):
123 print "Successfully loaded Python replica package bindings"
124 except:
125 if (SAGA_LOG != 0):
126 print "Failed loading Python replica package bindings"
127
128
129 try:
130 import saga.cpr
131 if (SAGA_LOG != 0):
132 print "Successfully loaded Python cpr package bindings"
133 except:
134 if (SAGA_LOG != 0):
135 print "Failed loading Python cpr package bindings"
136
137
138 try:
139 import saga.sd
140 if (SAGA_LOG != 0):
141 print "Successfully loaded Python sd package bindings"
142 except:
143 if (SAGA_LOG != 0):
144 print "Failed loading Python sd package bindings"
145
146
147 try:
148 import saga.stream
149 if (SAGA_LOG != 0):
150 print "Successfully loaded Python stream package bindings"
151 except:
152 if (SAGA_LOG != 0):
153 print "Failed loading Python stream package bindings"
154
155
156
157
162
165
168
171
174
177
180
183
190
191 _engine.exception = exception
192 _engine._exception.py_err_class = exception
193
194
196
197 _engine.not_implemented = not_implemented
198 _engine._not_implemented.py_err_class = not_implemented
199
200
202
203 _engine.parameter_exception = parameter_exception
204 _engine._parameter_exception.py_err_class = parameter_exception
205
206
208
209 _engine.incorrect_url = incorrect_url
210 _engine._incorrect_url.py_err_class = incorrect_url
211
212
214
215 _engine.bad_parameter = bad_parameter
216 _engine._bad_parameter.py_err_class = bad_parameter
217
218
220
221 _engine.state_exception = state_exception
222 _engine._state_exception.py_err_class = state_exception
223
224
226
227 _engine.already_exists = already_exists
228 _engine._already_exists.py_err_class = already_exists
229
230
232
233 _engine.does_not_exist = does_not_exist
234 _engine._does_not_exist.py_err_class = does_not_exist
235
236
238
239 _engine.incorrect_state = incorrect_state
240 _engine._incorrect_state.py_err_class = incorrect_state
241
242
243 -class timeout(state_exception): pass
244
245 _engine.timeout = timeout
246 _engine._timeout.py_err_class = timeout
247
248
250
251 _engine.security_exception = security_exception
252 _engine._security_exception.py_err_class = security_exception
253
254
256
257 _engine.permission_denied = permission_denied
258 _engine._permission_denied.py_err_class = permission_denied
259
260
262
263 _engine.authorization_failed = authorization_failed
264 _engine._authorization_failed.py_err_class = authorization_failed
265
266
268
269 _engine.authentication_failed = authentication_failed
270 _engine._authentication_failed.py_err_class = authentication_failed
271
272
274
275 _engine.no_success = no_success
276 _engine._no_success.py_err_class = no_success
277