2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
5 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
6 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 # SALOME Container : implementation of container and engine for Kernel
26 # File : SALOME_Container.py
27 # Author : Paul RASCLE, EDF
31 ## @package SALOME_Container
32 # \brief python implementation of container interface for Kernel
40 from omniORB import CORBA, PortableServer
42 import Engines, Engines__POA
43 from SALOME_NamingServicePy import *
44 from SALOME_ComponentPy import *
47 from SALOME_utilities import *
48 from Utils_Identity import getShortHostName
49 from launchConfigureParser import verbose
51 #=============================================================================
53 #define an implementation of the container interface for embedding in Container implemented in C++
55 class SALOME_Container_i:
59 _naming_service = None
61 #-------------------------------------------------------------------------
63 def __init__(self ,containerName, containerIORStr):
64 MESSAGE( "SALOME_Container_i::__init__" )
65 self._orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
66 self._poa = self._orb.resolve_initial_references("RootPOA")
67 self._containerName = containerName
68 if verbose(): print "SALOME_Container.SALOME_Container_i : _containerName ",self._containerName
69 #self._naming_service = SALOME_NamingServicePy_i(self._orb)
70 self._container = self._orb.string_to_object(containerIORStr)
72 #-------------------------------------------------------------------------
74 def import_component(self, componentName):
75 MESSAGE( "SALOME_Container_i::import_component" )
78 if verbose(): print "try import ",componentName
79 __import__(componentName)
80 if verbose(): print "import ",componentName," successful"
82 #can't import python module componentName
83 #try to find it in python path
85 fp, pathname, description = imp.find_module(componentName)
87 #module file found in path
88 ret="Component "+componentName+": Python implementation found but it can't be loaded\n"
89 ret=ret+traceback.format_exc(10)
90 except ImportError,ee:
91 ret="ImplementationNotFound"
93 if verbose():print "error when calling find_module"
94 ret="ImplementationNotFound"
96 ret="Component "+componentName+": Python implementation found but it can't be loaded\n"
97 ret=ret+traceback.format_exc(10)
100 print "import ",componentName," not possible"
103 #-------------------------------------------------------------------------
105 def create_component_instance(self, componentName, instanceName, studyId):
106 MESSAGE( "SALOME_Container_i::create_component_instance" )
110 component=__import__(componentName)
111 factory=getattr(component,componentName)
112 comp_i=factory(self._orb,
119 MESSAGE( "SALOME_Container_i::create_component_instance : OK")
120 comp_o = comp_i._this()
121 comp_iors = self._orb.object_to_string(comp_o)
123 ret=traceback.format_exc(10)
124 traceback.print_exc()
125 MESSAGE( "SALOME_Container_i::create_component_instance : NOT OK")
126 return comp_iors, ret
129 def create_pynode(self,nodeName,code):
131 node=SALOME_PyNode.PyNode_i(nodeName,code,self._poa,self)
132 id_o = self._poa.activate_object(node)
133 comp_o = self._poa.id_to_reference(id_o)
134 comp_iors = self._orb.object_to_string(comp_o)
137 exc_typ,exc_val,exc_fr=sys.exc_info()
138 l=traceback.format_exception(exc_typ,exc_val,exc_fr)
141 def create_pyscriptnode(self,nodeName,code):
143 node=SALOME_PyNode.PyScriptNode_i(nodeName,code,self._poa,self)
144 id_o = self._poa.activate_object(node)
145 comp_o = self._poa.id_to_reference(id_o)
146 comp_iors = self._orb.object_to_string(comp_o)
149 exc_typ,exc_val,exc_fr=sys.exc_info()
150 l=traceback.format_exception(exc_typ,exc_val,exc_fr)