1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
4 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
5 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 # SALOME Container : implementation of container and engine for Kernel
25 # File : SALOME_Container.py
26 # Author : Paul RASCLE, EDF
30 ## @package SALOME_Container
31 # \brief python implementation of container interface for Kernel
38 from omniORB import CORBA, PortableServer
40 import Engines, Engines__POA
41 from SALOME_NamingServicePy import *
42 from SALOME_ComponentPy import *
45 from SALOME_utilities import *
46 from Utils_Identity import getShortHostName
47 from launchConfigureParser import verbose
49 #=============================================================================
51 #define an implementation of the container interface for embedding in Container implemented in C++
53 class SALOME_Container_i:
57 _naming_service = None
59 #-------------------------------------------------------------------------
61 def __init__(self ,containerName, containerIORStr):
62 MESSAGE( "SALOME_Container_i::__init__" )
63 self._orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
64 self._poa = self._orb.resolve_initial_references("RootPOA")
65 self._containerName = containerName
66 if verbose(): print("SALOME_Container.SALOME_Container_i : _containerName ",self._containerName)
67 #self._naming_service = SALOME_NamingServicePy_i(self._orb)
68 self._container = self._orb.string_to_object(containerIORStr)
70 #-------------------------------------------------------------------------
72 def import_component(self, componentName):
73 MESSAGE( "SALOME_Container_i::import_component" )
76 if verbose(): print("try import ",componentName)
77 __import__(componentName)
78 if verbose(): print("import ",componentName," successful")
79 except ImportError as e:
80 #can't import python module componentName
81 #try to find it in python path
83 fp, pathname, description = imp.find_module(componentName)
85 #module file found in path
86 ret="Component "+componentName+": Python implementation found but it can't be loaded\n"
87 ret=ret+traceback.format_exc(10)
88 except ImportError as ee:
89 ret="ImplementationNotFound"
91 if verbose():print("error when calling find_module")
92 ret="ImplementationNotFound"
94 ret="Component "+componentName+": Python implementation found but it can't be loaded\n"
95 ret=ret+traceback.format_exc(10)
98 print("import ",componentName," not possible")
101 #-------------------------------------------------------------------------
103 def create_component_instance(self, componentName, instanceName):
104 MESSAGE( "SALOME_Container_i::create_component_instance" )
108 component=__import__(componentName)
109 factory=getattr(component,componentName)
110 comp_i=factory(self._orb,
117 MESSAGE( "SALOME_Container_i::create_component_instance : OK")
118 comp_o = comp_i._this()
119 comp_iors = self._orb.object_to_string(comp_o)
121 ret=traceback.format_exc(10)
122 traceback.print_exc()
123 MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK")
124 return comp_iors, ret
127 def create_pynode(self,nodeName,code):
129 node=SALOME_PyNode.PyNode_i(nodeName,code,self._poa,self)
130 id_o = self._poa.activate_object(node)
131 comp_o = self._poa.id_to_reference(id_o)
132 comp_iors = self._orb.object_to_string(comp_o)
135 exc_typ,exc_val,exc_fr=sys.exc_info()
136 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
139 def create_pyscriptnode(self,nodeName,code):
141 node=SALOME_PyNode.PyScriptNode_i(nodeName,code,self._poa,self)
142 id_o = self._poa.activate_object(node)
143 comp_o = self._poa.id_to_reference(id_o)
144 comp_iors = self._orb.object_to_string(comp_o)
147 exc_typ,exc_val,exc_fr=sys.exc_info()
148 l=traceback.format_exception(exc_typ,exc_val,exc_fr)