1 # Copyright (C) 2006-2013 CEA/DEN, EDF R&D
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 import SALOME_ComponentPy
24 import SALOME_DriverPy
36 class proc_i(YACS_ORB__POA.ProcExec):
37 def __init__(self, xmlFile):
38 self.l = loader.YACSLoader()
39 self.e = pilot.ExecutorSwig()
40 self.e.setExecMode(1) # YACS::STEPBYSTEP
42 self.p = self.l.load(xmlFile)
46 def getNodeState(self,numid):
47 return self.p.getNodeState(numid)
49 def getNodeProgress(self,numid):
50 return self.p.getNodeProgress(numid)
52 def getXMLState(self, numid):
53 return self.p.getXMLState(numid)
55 def getInPortValue(self, nodeNumid, portName):
57 return self.p.getInPortValue(nodeNumid, portName)
62 def setInPortValue(self, nodeName, portName, value):
64 return self.p.setInPortValue(nodeName, portName, value)
69 def getOutPortValue(self, nodeNumid, portName):
71 return self.p.getOutPortValue(nodeNumid, portName)
76 def getErrorDetails(self, nodeNumid):
77 return self.p.getNodeErrorDetails(nodeNumid)
79 def getErrorReport(self, nodeNumid):
80 return self.p.getNodeErrorReport(nodeNumid)
82 def getContainerLog(self, nodeNumid):
83 return self.p.getNodeContainerLog(nodeNumid)
85 def shutdownProc(self, level):
86 return self.p.shutdown(level)
88 def getExecutorState(self):
89 return self.e.getExecutorState()
92 numids = self.p.getNumIds()
97 return self.p.getNumIds()
100 return self.p.getIds()
102 def runProc(self,debug, isPyThread, fromscratch):
103 print "**************************Begin schema execution %s**************************" % self.xmlFile
104 self.e.RunPy(self.p,debug, isPyThread, fromscratch)
105 print "**************************End schema execution %s****************************" % self.xmlFile
108 if self.run1 is not None:
109 execState = self.e.getExecutorState()
110 if execState >= pilot.FINISHED:
114 if self.run1 is None:
115 self.run1 = threading.Thread(None, self.runProc, "CORBAExec", (0,1,1))
118 def RunFromState(self, xmlFile):
119 """Start an execution from the state given by the file xmlFile
120 If xmlFile == "", start execution from the current state
122 if self.run1 is not None:
123 execState = self.e.getExecutorState()
124 if execState >= pilot.FINISHED:
131 self.p.exUpdateState();
132 sp = loader.stateParser()
133 sl = loader.stateLoader(sp,self.p)
136 print "IO Error: ", ex
138 except ValueError,ex:
139 print "Caught ValueError Exception:",ex
141 except pilot.Exception,ex:
145 print "Unknown exception!"
148 if self.run1 is None:
149 self.run1 = threading.Thread(None, self.runProc, "CORBAExec", (0,1,0))
152 def RestartFromState(self, xmlFile):
153 """Reset the procedure state to ready state for all nodes in error
154 if xmlFile exists first try to load the state from this file.
157 if self.run1 is not None:
158 execState = self.e.getExecutorState()
159 if execState >= pilot.FINISHED:
166 if os.path.exists(xmlFile):
168 sp = loader.stateParser()
169 sl = loader.stateLoader(sp,self.p)
173 self.p.exUpdateState();
177 if self.run1 is None:
178 self.run1 = threading.Thread(None, self.runProc, "CORBAExec", (0,1,0))
181 def addObserver(self, obs, numid, event):
182 disp = SALOMERuntime.SALOMEDispatcher_getSALOMEDispatcher()
183 disp.addObserver(obs, numid, event)
186 def setExecMode(self, mode):
187 if mode == YACS_ORB.CONTINUE:
188 self.e.setExecMode(0)
190 if mode == YACS_ORB.STEPBYSTEP:
191 self.e.setExecMode(1)
193 if mode == YACS_ORB.STOPBEFORENODES:
194 self.e.setExecMode(2)
198 def setListOfBreakPoints(self, listOfBreakPoints):
199 self.e.setListOfBreakPoints(listOfBreakPoints)
202 def getTasksToLoad(self):
203 return self.e.getTasksToLoad()
205 def setStepsToExecute(self, listToExecute):
206 return self.e.setStepsToExecute(listToExecute)
208 def resumeCurrentBreakPoint(self):
209 return self.e.resumeCurrentBreakPoint()
211 def isNotFinished(self):
212 return self.e.isNotFinished()
214 def stopExecution(self):
215 self.e.stopExecution()
218 def saveState(self, xmlFile):
219 return self.e.saveState(xmlFile)
221 def setStopOnError(self, dumpRequested, xmlFile):
222 self.e.setStopOnError(dumpRequested, xmlFile)
225 def unsetStopOnError(self):
226 self.e.unsetStopOnError()
232 class YACS(YACS_ORB__POA.YACS_Gen,
233 SALOME_ComponentPy.SALOME_ComponentPy_i,
234 SALOME_DriverPy.SALOME_DriverPy_i):
236 To be a SALOME component, this Python class must have the component name
237 (YACS) and inherit the YACS_Gen class build from idl compilation
238 with omniidl and also the class SALOME_ComponentPy_i which defines general
239 SALOME component behaviour.
241 def __init__ ( self, orb, poa, contID, containerName, instanceName,
243 print "YACS.__init__: ", containerName, ';', instanceName
244 SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa, contID,
245 containerName, instanceName,
247 SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName)
249 # --- store a naming service interface instance in _naming_service atribute
250 self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
252 SALOMERuntime.RuntimeSALOME_setRuntime(1)
253 SALOMERuntime.SALOMEDispatcher_setSALOMEDispatcher()
257 #try to load SALOME module catalogs
258 modul_catalog = self._naming_service.Resolve("/Kernel/ModulCatalog")
259 ior= orb.object_to_string(modul_catalog)
260 cata=r.loadCatalog("session",ior)
266 Get version information.
268 def getVersion( self ):
270 rt = SALOMERuntime.getSALOMERuntime()
271 version = rt.getVersion()
277 def LoadProc(self,xmlFile):
279 load an XML graph in a YACS::ENGINE::proc, create a CORBA servant
280 associated to the proc, and return a ref on the servant.
283 procExec_i = proc_i(xmlFile)
284 logger=procExec_i.p.getLogger("parser")
285 if not logger.isEmpty():
286 print "The imported file has errors :"
287 print logger.getStr()
291 print >> sys.stderr ,"IO Error: ", ex
293 except ValueError,ex:
294 print >> sys.stderr ,"Caught ValueError Exception:",ex
296 except pilot.Exception,ex:
297 print >> sys.stderr ,ex.what()
300 traceback.print_exc()
302 procExec_o = procExec_i._this()
305 def convertSupervFile(self,xmlFile):
307 load a SUPERV xml graph, convert it and return the new filename.
310 r = pilot.getRuntime()
311 lo = salomeloader.SalomeLoader()
312 e = pilot.ExecutorSwig()
314 s = pilot.SchemaSave(p)
315 hnd, convertedFile = tempfile.mkstemp(".xml","yacs_","/tmp")
316 s.save(convertedFile)