#! /usr/bin/env python
# -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
#
-# Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License.
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
+
# File : SALOME_PyNode.py
# Author : Christian CAREMOLI, EDF
# Module : SALOME
# $Header$
#
-
import sys,traceback,string
import linecache
import cPickle
def Register(self):
self.cnt+=1
- def Destroy(self):
+ def UnRegister(self):
self.cnt-=1
if self.cnt <= 0:
oid=self.poa.servant_to_id(self)
self.poa.deactivate_object(oid)
+ def Destroy(self):
+ print "WARNING SALOME::GenericObj::Destroy() function is obsolete! Use UnRegister() instead."
+ self.UnRegister()
+
class PyNode_i (Engines__POA.PyNode,Generic):
"""The implementation of the PyNode CORBA IDL"""
- def __init__(self, nodeName,code,poa):
+ def __init__(self, nodeName,code,poa,my_container):
"""Initialize the node : compilation in the local context"""
Generic.__init__(self,poa)
self.nodeName=nodeName
self.code=code
+ self.my_container=my_container._container
linecache.cache[nodeName]=0,None,string.split(code,'\n'),nodeName
ccode=compile(code,nodeName,'exec')
self.context={}
+ self.context["my_container"] = self.my_container
exec ccode in self.context
- def execute(self,funcName,argsin):
+ def execute(self,funcName,argsin):
"""Execute the function funcName found in local context with pickled args (argsin)"""
try:
argsin,kws=cPickle.loads(argsin)
l=traceback.format_exception(exc_typ,exc_val,exc_fr)
raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"PyNode: %s, function: %s" % (self.nodeName,funcName),0))
+class PyScriptNode_i (Engines__POA.PyScriptNode,Generic):
+ """The implementation of the PyScriptNode CORBA IDL that executes a script"""
+ def __init__(self, nodeName,code,poa,my_container):
+ """Initialize the node : compilation in the local context"""
+ Generic.__init__(self,poa)
+ self.nodeName=nodeName
+ self.code=code
+ self.my_container=my_container._container
+ linecache.cache[nodeName]=0,None,string.split(code,'\n'),nodeName
+ self.ccode=compile(code,nodeName,'exec')
+ self.context={}
+ self.context["my_container"] = self.my_container
+
+ def execute(self,outargsname,argsin):
+ """Execute the script stored in attribute ccode with pickled args (argsin)"""
+ try:
+ argsname,kws=cPickle.loads(argsin)
+ self.context.update(kws)
+ exec self.ccode in self.context
+ argsout=[]
+ for arg in outargsname:
+ if not self.context.has_key(arg):
+ raise KeyError("There is no variable %s in context" % arg)
+ argsout.append(self.context[arg])
+ argsout=cPickle.dumps(tuple(argsout),-1)
+ return argsout
+ except:
+ exc_typ,exc_val,exc_fr=sys.exc_info()
+ l=traceback.format_exception(exc_typ,exc_val,exc_fr)
+ raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"PyScriptNode: %s, outargsname: %s" % (self.nodeName,outargsname),0))