1 # Copyright (C) 2006-2012 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 getXMLState(self, numid):
50 return self.p.getXMLState(numid)
52 def getInPortValue(self, nodeNumid, portName):
54 return self.p.getInPortValue(nodeNumid, portName)
59 def setInPortValue(self, nodeName, portName, value):
61 return self.p.setInPortValue(nodeName, portName, value)
66 def getOutPortValue(self, nodeNumid, portName):
68 return self.p.getOutPortValue(nodeNumid, portName)
73 def getErrorDetails(self, nodeNumid):
74 return self.p.getNodeErrorDetails(nodeNumid)
76 def getErrorReport(self, nodeNumid):
77 return self.p.getNodeErrorReport(nodeNumid)
79 def getContainerLog(self, nodeNumid):
80 return self.p.getNodeContainerLog(nodeNumid)
82 def shutdownProc(self, level):
83 return self.p.shutdown(level)
85 def getExecutorState(self):
86 return self.e.getExecutorState()
89 numids = self.p.getNumIds()
94 return self.p.getNumIds()
97 return self.p.getIds()
99 def runProc(self,debug, isPyThread, fromscratch):
100 print "**************************Begin schema execution %s**************************" % self.xmlFile
101 self.e.RunPy(self.p,debug, isPyThread, fromscratch)
102 print "**************************End schema execution %s****************************" % self.xmlFile
105 if self.run1 is not None:
106 execState = self.e.getExecutorState()
107 if execState >= pilot.FINISHED:
111 if self.run1 is None:
112 self.run1 = threading.Thread(None, self.runProc, "CORBAExec", (0,1,1))
115 def RunFromState(self, xmlFile):
116 """Start an execution from the state given by the file xmlFile
117 If xmlFile == "", start execution from the current state
119 if self.run1 is not None:
120 execState = self.e.getExecutorState()
121 if execState >= pilot.FINISHED:
128 self.p.exUpdateState();
129 sp = loader.stateParser()
130 sl = loader.stateLoader(sp,self.p)
133 print "IO Error: ", ex
135 except ValueError,ex:
136 print "Caught ValueError Exception:",ex
138 except pilot.Exception,ex:
142 print "Unknown exception!"
145 if self.run1 is None:
146 self.run1 = threading.Thread(None, self.runProc, "CORBAExec", (0,1,0))
149 def RestartFromState(self, xmlFile):
150 """Reset the procedure state to ready state for all nodes in error
151 if xmlFile exists first try to load the state from this file.
154 if self.run1 is not None:
155 execState = self.e.getExecutorState()
156 if execState >= pilot.FINISHED:
163 if os.path.exists(xmlFile):
165 sp = loader.stateParser()
166 sl = loader.stateLoader(sp,self.p)
170 self.p.exUpdateState();
174 if self.run1 is None:
175 self.run1 = threading.Thread(None, self.runProc, "CORBAExec", (0,1,0))
178 def addObserver(self, obs, numid, event):
179 disp = SALOMERuntime.SALOMEDispatcher_getSALOMEDispatcher()
180 disp.addObserver(obs, numid, event)
183 def setExecMode(self, mode):
184 if mode == YACS_ORB.CONTINUE:
185 self.e.setExecMode(0)
187 if mode == YACS_ORB.STEPBYSTEP:
188 self.e.setExecMode(1)
190 if mode == YACS_ORB.STOPBEFORENODES:
191 self.e.setExecMode(2)
195 def setListOfBreakPoints(self, listOfBreakPoints):
196 self.e.setListOfBreakPoints(listOfBreakPoints)
199 def getTasksToLoad(self):
200 return self.e.getTasksToLoad()
202 def setStepsToExecute(self, listToExecute):
203 return self.e.setStepsToExecute(listToExecute)
205 def resumeCurrentBreakPoint(self):
206 return self.e.resumeCurrentBreakPoint()
208 def isNotFinished(self):
209 return self.e.isNotFinished()
211 def stopExecution(self):
212 self.e.stopExecution()
215 def saveState(self, xmlFile):
216 return self.e.saveState(xmlFile)
218 def setStopOnError(self, dumpRequested, xmlFile):
219 self.e.setStopOnError(dumpRequested, xmlFile)
222 def unsetStopOnError(self):
223 self.e.unsetStopOnError()
229 class YACS(YACS_ORB__POA.YACS_Gen,
230 SALOME_ComponentPy.SALOME_ComponentPy_i,
231 SALOME_DriverPy.SALOME_DriverPy_i):
233 To be a SALOME component, this Python class must have the component name
234 (YACS) and inherit the YACS_Gen class build from idl compilation
235 with omniidl and also the class SALOME_ComponentPy_i which defines general
236 SALOME component behaviour.
238 def __init__ ( self, orb, poa, contID, containerName, instanceName,
240 print "YACS.__init__: ", containerName, ';', instanceName
241 SALOME_ComponentPy.SALOME_ComponentPy_i.__init__(self, orb, poa, contID,
242 containerName, instanceName,
244 SALOME_DriverPy.SALOME_DriverPy_i.__init__(self, interfaceName)
246 # --- store a naming service interface instance in _naming_service atribute
247 self._naming_service = SALOME_ComponentPy.SALOME_NamingServicePy_i( self._orb )
249 SALOMERuntime.RuntimeSALOME_setRuntime(1)
250 SALOMERuntime.SALOMEDispatcher_setSALOMEDispatcher()
254 #try to load SALOME module catalogs
255 modul_catalog = self._naming_service.Resolve("/Kernel/ModulCatalog")
256 ior= orb.object_to_string(modul_catalog)
257 cata=r.loadCatalog("session",ior)
262 def LoadProc(self,xmlFile):
264 load an XML graph in a YACS::ENGINE::proc, create a CORBA servant
265 associated to the proc, and return a ref on the servant.
268 procExec_i = proc_i(xmlFile)
269 logger=procExec_i.p.getLogger("parser")
270 if not logger.isEmpty():
271 print "The imported file has errors :"
272 print logger.getStr()
276 print >> sys.stderr ,"IO Error: ", ex
278 except ValueError,ex:
279 print >> sys.stderr ,"Caught ValueError Exception:",ex
281 except pilot.Exception,ex:
282 print >> sys.stderr ,ex.what()
285 traceback.print_exc()
287 procExec_o = procExec_i._this()
290 def convertSupervFile(self,xmlFile):
292 load a SUPERV xml graph, convert it and return the new filename.
295 r = pilot.getRuntime()
296 lo = salomeloader.SalomeLoader()
297 e = pilot.ExecutorSwig()
299 s = pilot.SchemaSave(p)
300 hnd, convertedFile = tempfile.mkstemp(".xml","yacs_","/tmp")
301 s.save(convertedFile)