Package saga
[frames] | no frames]

Source Code for Package saga

  1  #  Copyright (c) 2005-2009 Hartmut Kaiser 
  2  #  
  3  #  Distributed under the Boost Software License, Version 1.0. (See accompanying 
  4  #  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 
  5   
  6  # This file must be located inside a directory named SAGA which in turn should  
  7  # be located in a directory listed in your PYTHON_PATH 
  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 *         # import all classes from SAGA.engine 
 73   
 74  ############################################################################### 
 75  # try to load all the different packages, one at a time, and ignoring any errors 
 76  import os 
 77  SAGA_LOG = 0 
 78  try: 
 79      SAGA_LOG = long(os.getenv("SAGA_VERBOSE", "0")) 
 80  except: 
 81      pass 
 82   
 83  # load namespace package 
 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  # load filesystem package 
 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  # load advert package 
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  # load job package 
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  # load replica package 
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  # load cpr package 
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  # load sd package 
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  # load stream package 
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  # define classes needed for proper exception translation 
157  ############################################################################### 
158 -class exception(Exception):
159 - def __init__(self, error):
160 Exception.__init__(self) 161 self._pimpl = error
162
163 - def __str__(self):
164 return self._pimpl.get_message()
165
166 - def get_full_message(self):
167 return self._pimpl.get_full_message()
168
169 - def get_message(self):
170 return self._pimpl.get_message()
171
172 - def get_error(self):
173 return self._pimpl.get_error()
174
175 - def get_object(self):
176 return self._pimpl.get_object()
177
178 - def get_all_exceptions(self):
179 return self._pimpl.get_all_exceptions()
180
181 - def get_all_messages(self):
182 return self._pimpl.get_all_messages()
183
184 - def __getattribute__(self, attr):
185 my_pimpl = super(exception, self).__getattribute__("_pimpl") 186 try: 187 return getattr(my_pimpl, attr) 188 except AttributeError: 189 return super(exception, self).__getattribute__(attr)
190 191 _engine.exception = exception 192 _engine._exception.py_err_class = exception 193 194 ###############################################################################
195 -class not_implemented(exception): pass
196 197 _engine.not_implemented = not_implemented 198 _engine._not_implemented.py_err_class = not_implemented 199 200 ###############################################################################
201 -class parameter_exception(exception): pass
202 203 _engine.parameter_exception = parameter_exception 204 _engine._parameter_exception.py_err_class = parameter_exception 205 206 ###############################################################################
207 -class incorrect_url(parameter_exception): pass
208 209 _engine.incorrect_url = incorrect_url 210 _engine._incorrect_url.py_err_class = incorrect_url 211 212 ###############################################################################
213 -class bad_parameter(parameter_exception): pass
214 215 _engine.bad_parameter = bad_parameter 216 _engine._bad_parameter.py_err_class = bad_parameter 217 218 ###############################################################################
219 -class state_exception(exception): pass
220 221 _engine.state_exception = state_exception 222 _engine._state_exception.py_err_class = state_exception 223 224 ###############################################################################
225 -class already_exists(state_exception): pass
226 227 _engine.already_exists = already_exists 228 _engine._already_exists.py_err_class = already_exists 229 230 ###############################################################################
231 -class does_not_exist(state_exception): pass
232 233 _engine.does_not_exist = does_not_exist 234 _engine._does_not_exist.py_err_class = does_not_exist 235 236 ###############################################################################
237 -class incorrect_state(state_exception): pass
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 ###############################################################################
249 -class security_exception(exception): pass
250 251 _engine.security_exception = security_exception 252 _engine._security_exception.py_err_class = security_exception 253 254 ###############################################################################
255 -class permission_denied(security_exception): pass
256 257 _engine.permission_denied = permission_denied 258 _engine._permission_denied.py_err_class = permission_denied 259 260 ###############################################################################
261 -class authorization_failed(security_exception): pass
262 263 _engine.authorization_failed = authorization_failed 264 _engine._authorization_failed.py_err_class = authorization_failed 265 266 ###############################################################################
267 -class authentication_failed(security_exception): pass
268 269 _engine.authentication_failed = authentication_failed 270 _engine._authentication_failed.py_err_class = authentication_failed 271 272 ###############################################################################
273 -class no_success(exception): pass
274 275 _engine.no_success = no_success 276 _engine._no_success.py_err_class = no_success 277