X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FContainer%2FSALOME_ContainerPy.py;h=2e3d893eb2254b589e1ce25e6c8394bcbf140309;hb=c8077bb518e7a34771973b25d2fb977a87bf847b;hp=6eb0110bc471762dc0282d4da2be41711739f845;hpb=e6bfea36374791cd31c274a2f97df90dc60ddaf3;p=modules%2Fkernel.git diff --git a/src/Container/SALOME_ContainerPy.py b/src/Container/SALOME_ContainerPy.py index 6eb0110bc..2e3d893eb 100755 --- a/src/Container/SALOME_ContainerPy.py +++ b/src/Container/SALOME_ContainerPy.py @@ -1,37 +1,35 @@ #! /usr/bin/env python +# Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE # -# SALOME Container : implementation of container and engine for Kernel +# 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. # -# Copyright (C) 2003 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 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 -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# 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 # +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # +# SALOME Container : implementation of container and engine for Kernel # File : SALOME_ContainerPy.py # Author : Paul RASCLE, EDF # Module : SALOME # $Header$ - +# import os import sys import string -import omnipatch # PAL10310 + from omniORB import CORBA, PortableServer import SALOMEDS import Engines, Engines__POA @@ -40,10 +38,11 @@ from SALOME_ComponentPy import * from SALOME_utilities import * from Utils_Identity import getShortHostName +from launchConfigureParser import verbose #============================================================================= -#define an implementation of the container interface +#define an implementation of the container interface for the container implemented in Python class SALOME_ContainerPy_i (Engines__POA.Container): _orb = None @@ -59,9 +58,8 @@ class SALOME_ContainerPy_i (Engines__POA.Container): self._poa = poa myMachine=getShortHostName() Container_path = "/Containers/" + myMachine + "/" + containerName - #self._containerName = containerName self._containerName = Container_path - print "container name ",self._containerName + if verbose(): print "container name ",self._containerName naming_service = SALOME_NamingServicePy_i(self._orb) self._naming_service = naming_service @@ -140,10 +138,10 @@ class SALOME_ContainerPy_i (Engines__POA.Container): self._numInstance = self._numInstance +1 instanceName = nameToRegister + "_inst_" + `self._numInstance` - component=__import__(componentName) - factory=getattr(component,componentName) - comp_i=factory(self._orb, self._poa, self._this(), self._containerName, - instanceName, nameToRegister) + component=__import__(componentName) + factory=getattr(component,componentName) + comp_i=factory(self._orb, self._poa, self._this(), self._containerName, + instanceName, nameToRegister) MESSAGE( "SALOME_ContainerPy_i::instance : component created") comp_o = comp_i._this() @@ -170,9 +168,9 @@ class SALOME_ContainerPy_i (Engines__POA.Container): MESSAGE( "SALOME_Container_i::import_component" ) ret=0 try: - print "try import ",componentName - __import__(componentName) - print "import ",componentName," successful" + if verbose(): print "try import ",componentName + module=__import__(componentName) + if verbose(): print "import ",componentName," successful" ret=1 except: import traceback @@ -187,24 +185,6 @@ class SALOME_ContainerPy_i (Engines__POA.Container): ret = 0 instanceName = componentName + "_inst_" + `self._numInstance` interfaceName = componentName - #the_command = "import " + componentName + "\n" - #the_command = the_command + "comp_i = " + componentName + "." + componentName - #the_command = the_command + "(self._orb, self._poa, self._this(), self._containerName, instanceName, interfaceName)\n" - #MESSAGE( "SALOME_ContainerPy_i::load_component_Library :" + str (the_command) ) - #exec the_command - #comp_o = comp_i._this() - #if comp_o is not None: - # ret = 1 - #else: - # --- try to import Python component - # retImpl = self.import_component(componentName) - # if retImpl == 1: - #import is possible - # ret = 1 - # else: - #import isn't possible - # ret = 0 - #return ret return self.import_component(componentName) #------------------------------------------------------------------------- @@ -303,31 +283,44 @@ class SALOME_ContainerPy_i (Engines__POA.Container): #------------------------------------------------------------------------- def Shutdown(self): + self._naming_service.Destroy_Name(self._containerName); + self._naming_service.Destroy_FullDirectory(self._containerName); self._orb.shutdown(0) pass -#============================================================================= - -#initialise the ORB and find the root POA -orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) -poa = orb.resolve_initial_references("RootPOA") - -#create an instance of SALOME_ContainerPy_i and a Container reference -#containerName = "FactoryServerPy" -MESSAGE( str(sys.argv) ) -containerName = sys.argv[1] -cpy_i = SALOME_ContainerPy_i(orb, poa, containerName) -cpy_o = cpy_i._this() - -#activate the POA -poaManager = poa._get_the_POAManager() -poaManager.activate() - -#Block for ever -orb.run() - - - - + def _get_logfilename(self): + return self._logfilename + def _set_logfilename(self,logfilename): + self._logfilename=logfilename + def _get_workingdir(self): + return os.getcwd() +#============================================================================= +if __name__ == "__main__": + # change the stdout buffering to line buffering (same as C++ cout buffering) + sys.stdout=os.fdopen(1,"w",1) + #initialise the ORB and find the root POA + if verbose():print "Starting ",sys.argv[1] + orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) + poa = orb.resolve_initial_references("RootPOA") + if verbose():print "ORB and POA initialized" + + #create an instance of SALOME_ContainerPy_i and a Container reference + #containerName = "FactoryServerPy" + MESSAGE( str(sys.argv) ) + containerName = sys.argv[1] + cpy_i = SALOME_ContainerPy_i(orb, poa, containerName) + if verbose():print "SALOME_ContainerPy_i instance created ",cpy_i + cpy_o = cpy_i._this() + if verbose():print "SALOME_ContainerPy_i instance activated ",cpy_o + sys.stdout.flush() + sys.stderr.flush() + + #activate the POA + poaManager = poa._get_the_POAManager() + poaManager.activate() + + #Block for ever + orb.run() + if verbose():print "SALOME_ContainerPy_i shutdown"