Need other files not in CVS to work (work in progress).
runNS.sh \
launchConfigureParser.py \
salome.launch \
+envSalome.py \
+salomeConsole.py \
showNS.py
# copy header files in common directory
# -----------------------------------------------------------------------------
-### searching for launch configuration file : $HOME/.$(application_name)/$(application_name).launch
-
-appname = None
-dirname = None
-filename = None
-for bindir in glob.glob(os.environ["KERNEL_ROOT_DIR"]+"/bin/*"):
- appname = string.split(bindir, "/").pop()
- print 'Application name: "'+appname+'"'
- # find version number
- versnb = ""
- try:
- file = open(os.environ["KERNEL_ROOT_DIR"]+"/bin/"+appname+"/VERSION", "r")
- s = file.read()
- l = string.split(s, ":")
- vl = string.split(l[1], " ")
- i = 0
- while len(versnb) == 0:
- versnb = vl[i]
- i += 1
- pass
- versnb = string.split(versnb, "\n")[0]
- print "Version ",versnb
- except:
- pass
- # end find version number
- dirname = os.environ["HOME"]+"/."+appname+"_"+versnb
- filename = dirname+"/"+appname+".launch"
- if not os.path.exists(filename) and \
- not os.path.exists(os.environ["KERNEL_ROOT_DIR"]+"/bin/"+appname+"/"+appname+".launch"):
- filename = None
- else:
- break
- pass
-if not appname:
- print "Can not find application name"
- if not os.have_key("KERNEL_ROOT_DIR"):
- print "KERNEL_ROOT_DIR environment variable must be set"
- pass
- sys.exit(1);
-elif not filename or not os.path.exists(filename):
- filename = dirname+"/"+appname+".launch"
- #filename = os.environ["HOME"]+"/."+appname+"/"+appname+".launch"
- print "Launch configuration file does not exist. Create default:",filename
- os.system("mkdir -p "+dirname)
- #os.system("mkdir -p "+os.environ["HOME"]+"/."+appname)
- os.system("cp -f "+os.environ["KERNEL_ROOT_DIR"]+"/bin/"+appname+"/"+appname+".launch "+filename)
- pass
+### searching for launch configuration file : $HOME/applipath()/salome.launch
+
+appname="salome"
+import Utils_Identity
+versnb=Utils_Identity.version()
+dirname = os.path.join(os.environ["HOME"],Utils_Identity.getapplipath())
+filename=os.path.join(dirname,"salome.launch")
+
+if not os.path.exists(filename):
+ print "Launch configuration file does not exist. Create default:",filename
+ os.system("mkdir -p "+dirname)
+ os.system("cp -f "+os.environ["KERNEL_ROOT_DIR"]+"/bin/salome/salome.launch "+filename)
### get options from launch configuration file
print """USAGE: runSalome.py [options]
[command line options] :
--help or -h : print this help
- --gui or -g : lancement du GUI
+ --gui or -g : launching with GUI
--terminal -t : launching without gui (to deny --gui)
- --logger or -l : redirection des messages via CORBA
- --file=filename or -l=filename: redirection des messages dans un fichier
- --xterm or -x : les serveurs ouvrent une fenêtre xterm et les messages sont affichés dans cette fenêtre
- --modules=module1,module2,... : où modulen est le nom d'un module Salome à charger dans le catalogue
+ --logger or -l : redirect messages in a CORBA collector
+ --file=filename or -f=filename: redirect messages in a log file
+ --xterm or -x : execute servers in xterm console (messages appear in xterm windows)
+ --modules=module1,module2,... : salome module list (modulen is the name of Salome module to load)
or -m=module1,module2,...
--embedded=registry,study,moduleCatalog,cppContainer
or -e=registry,study,moduleCatalog,cppContainer
- : serveurs CORBA embarqués (par defaut: registry,study,moduleCatalog,cppContainer)
- : (logger,pyContainer,supervContainer ne peuvent pas être embarqués
+ : embedded CORBA servers (default: registry,study,moduleCatalog,cppContainer)
+ : (logger,pyContainer,supervContainer can't be embedded
--standalone=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer
or -s=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer
- : executables serveurs CORBA indépendants (par défaut: pyContainer,supervContainer)
- --containers=cpp,python,superv: (obsolete) lancement des containers cpp, python et de supervision
- or -c=cpp,python,superv : = on prend les defauts de -e et -s
+ : standalone CORBA servers (default: pyContainer,supervContainer)
+ --containers=cpp,python,superv: (obsolete) launching of containers cpp, python and supervision
+ or -c=cpp,python,superv : = get default from -e and -s
--portkill or -p : kill the salome with current port
--killall or -k : kill salome
- La variable d'environnement <modulen>_ROOT_DIR doit etre préalablement
- positionnée (modulen doit etre en majuscule).
- KERNEL_ROOT_DIR est obligatoire.
+ For each Salome module, the environment variable <modulen>_ROOT_DIR must be set.
+ The module name (<modulen>) must be uppercase.
+ KERNEL_ROOT_DIR is mandatory.
"""
sys.exit(1)
pass
os.environ["SALOME_trace"]="local"
if args['file']:
- os.environ["SALOME_trace"]=args['file'][0]
+ os.environ["SALOME_trace"]=args['file'][0]
if args['logger']:
os.environ["SALOME_trace"]="with_logger"
locdir=os.environ['PWD']
self.modules_root_dir=modules_root_dir
myLogName = os.environ["LOGNAME"]
self.CMD=['notifd','-c',
- self.modules_root_dir["KERNEL"]
- +'/share/salome/resources/channel.cfg',
+ self.modules_root_dir["KERNEL"] +'/share/salome/resources/channel.cfg',
'-DFactoryIORFileName=/tmp/'+myLogName+'_rdifact.ior',
- '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior']
+ '-DChannelIORFileName=/tmp/'+myLogName+'_rdichan.ior',
+ '-DReportLogFile=/tmp/'+myLogName+'_notifd.report',
+ '-DDebugLogFile=/tmp/'+myLogName+'_notifd.debug',
+ ]
#
# -----------------------------------------------------------------------------
try:
clt = startSalome(args, modules_list, modules_root_dir)
except:
+ import traceback
+ traceback.print_exc()
print
print
print "--- erreur au lancement Salome ---"
# -----------------------------------------------------------------------------
if __name__ == "__main__":
+ import user
clt,args = main()
*/
Component load_impl(in string nameToRegister, in string componentName);
+/*!
+ Loads into the container a new component, registers it and starts it's CORBA servant.
+ \param nameToRegister Name used to register in Naming Service, the component instance
+ \param componentName Name of the %component
+ \return a new instance of the component or the registered component if already registered or Nil if not possible
+*/
+ Component instance(in string nameToRegister, in string componentName);
+
/*!
Stops the component servant, and deletes all related objects
\param component_i Component to be removed
char* Engines_Container_i::getHostName() {
return((char*)(GetHostname().c_str()));
}
+
+/*
+ * Create one instance of componentName component and register it
+ * as nameToRegister in naming service
+ */
+Engines::Component_ptr Engines_Container_i::instance( const char* nameToRegister,
+ const char* componentName ) {
+
+ _numInstanceMutex.lock() ; // lock on the instance number
+ BEGIN_OF( "Container_i::instance " << componentName ) ;
+
+ string _nameToRegister = nameToRegister;
+ string component_registerName = _containerName + "/" + _nameToRegister;
+
+ Engines::Component_var iobject = Engines::Component::_nil() ;
+
+ try {
+ CORBA::Object_var obj = _NS->Resolve( component_registerName.c_str() ) ;
+ if (! CORBA::is_nil( obj ) ) {
+ MESSAGE( "Container_i::instance " << component_registerName.c_str() << " already registered" ) ;
+ iobject = Engines::Component::_narrow( obj ) ;
+ }
+ else{
+ string _compo_name = componentName;
+ string _impl_name = "lib" + _compo_name + "Engine.so";
+ SCRUTE(_impl_name);
+
+ void* handle;
+ handle = dlopen( _impl_name.c_str() , RTLD_LAZY ) ;
+
+ if ( handle ) {
+ string factory_name = _compo_name + "Engine_factory";
+ SCRUTE(factory_name) ;
+
+ typedef PortableServer::ObjectId * (*FACTORY_FUNCTION)
+ (CORBA::ORB_ptr,
+ PortableServer::POA_ptr,
+ PortableServer::ObjectId *,
+ const char *,
+ const char *) ;
+ FACTORY_FUNCTION Component_factory = (FACTORY_FUNCTION) dlsym(handle, factory_name.c_str());
+
+ char *error ;
+ if ( (error = dlerror() ) == NULL) {
+ // Instanciate required CORBA object
+ _numInstance++ ;
+ char _aNumI[12];
+ sprintf( _aNumI , "%d" , _numInstance ) ;
+ string instanceName = _compo_name + "_inst_" + _aNumI ;
+ SCRUTE(instanceName);
+
+ PortableServer::ObjectId * id ;
+ id = (Component_factory) ( _orb, _poa, _id, instanceName.c_str() ,
+ _nameToRegister.c_str() ) ;
+ // get reference from id
+ obj = _poa->id_to_reference(*id);
+ iobject = Engines::Component::_narrow( obj ) ;
+
+ // register the engine under the name containerName.dir/nameToRegister.object
+ _NS->Register( iobject , component_registerName.c_str() ) ;
+ MESSAGE( "Container_i::instance " << component_registerName.c_str() << " registered" ) ;
+ handle_map[instanceName] = handle;
+ }
+ else{
+ INFOS("Can't resolve symbol: " + factory_name);
+ SCRUTE(error);
+ }
+ }
+ else{
+ INFOS("Can't load shared library : " << _impl_name);
+ INFOS("error dlopen: " << dlerror());
+ }
+ }
+ }
+ catch (...) {
+ INFOS( "Container_i::instance exception caught" ) ;
+ }
+ END_OF("Container_i::instance");
+ _numInstanceMutex.unlock() ;
+ return Engines::Component::_duplicate(iobject);
+}
+
# (if not, incomplete import done by SALOME module: no load of SALOMEDS_attributes)
import SALOMEDS
import Engines, Engines__POA
+reload(Engines)
+reload(Engines__POA)
from SALOME_NamingServicePy import *
from SALOME_ComponentPy import *
#-------------------------------------------------------------------------
+ def instance(self, nameToRegister, componentName):
+ MESSAGE( "SALOME_ContainerPy_i::instance " + str(nameToRegister) + ' ' + str(componentName) )
+ 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)
+
+ MESSAGE( "SALOME_ContainerPy_i::instance : component created")
+ comp_o = comp_i._this()
+ return comp_o
+
+ #-------------------------------------------------------------------------
+
def load_impl(self, nameToRegister, componentName):
MESSAGE( "SALOME_ContainerPy_i::load_impl " + str(nameToRegister) + ' ' + str(componentName) )
self._numInstance = self._numInstance +1
def remove_impl(self, component):
MESSAGE( "SALOME_ContainerPy_i::remove_impl" )
+ return None
#-------------------------------------------------------------------------
def finalize_removal(self):
MESSAGE( "SALOME_ContainerPy_i::finalize_removal" )
+ return None
#-------------------------------------------------------------------------
def ping(self):
MESSAGE( "SALOME_ContainerPy_i::ping" )
+ return None
#-------------------------------------------------------------------------
def _get_name(self):
MESSAGE( "SALOME_ContainerPy_i::_get_name" )
+ return self._containerName
#-------------------------------------------------------------------------
Engines::Component_ptr load_impl(const char* nameToRegister,
const char* componentName);
+ Engines::Component_ptr instance(const char* nameToRegister,
+ const char* componentName);
+
//! Unload component from current container
void remove_impl(Engines::Component_ptr component_i);
void finalize_removal();
from SALOME_utilities import *
from Utils_Identity import getShortHostName
+import Utils_Identity
+import Launchers
class LifeCycleCORBA:
_orb = None
except:
theComputer = ""
theContainer = containerName
- if theComputer == "" :
- theComputer = getShortHostName()
- if theComputer == "localhost" :
+
+ if theComputer in ("","localhost") :
theComputer = getShortHostName()
- computerSplitName = theComputer.split('.')
- theComputer = computerSplitName[0]
+
MESSAGE( theComputer + theContainer )
return theComputer,theContainer
#-------------------------------------------------------------------------
+ def setLauncher(self,name):
+ """Change default launcher to the launcher identified by name
+
+ See module Launchers.py
+ """
+ Launchers.setLauncher(name)
+
+ #-------------------------------------------------------------------------
+
+ def StartContainer(self, theComputer , theContainer ):
+ """Start a container on theComputer machine with theContainer name
+ """
+ # Get the Naming Service address
+ #
+ addr=self._orb.object_to_string(self._rootContext)
+ #
+ # If container name contains "Py" launch a Python Container
+ #
+ if theContainer.find('Py') == -1 :
+ CMD=['SALOME_Container',theContainer,'-ORBInitRef','NameService='+addr]
+ else:
+ CMD=['SALOME_ContainerPy.py',theContainer,'-ORBInitRef','NameService='+addr]
+ if theComputer in ("","localhost"):
+ theComputer=getShortHostName()
+ #
+ # Get the appropriate launcher and ask to launch
+ #
+ Launchers.getLauncher(theComputer).launch(theComputer,CMD)
+ #
+ # Wait until the container is registered in Naming Service
+ #
+ count =5
+ aContainer=None
+ while aContainer is None and count > 0:
+ time.sleep(1)
+ count = count - 1
+ MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theContainer )
+ aContainer = self.FindContainer( theComputer + "/" + theContainer )
+ return aContainer
+
+ #-------------------------------------------------------------------------
+
def FindOrStartContainer(self, theComputer , theContainer ):
- MESSAGE( "FindOrStartContainer" + theComputer + theContainer )
+ """Find or Start a container on theComputer machine with theContainer name
+ """
+ MESSAGE( "FindOrStartContainer: " + theComputer + theContainer )
aContainer = self.FindContainer( theComputer + "/" + theContainer )
if aContainer is None :
- if (theContainer == "FactoryServer") | (theContainer == "FactoryServerPy") :
- myMachine=getShortHostName()
- if theComputer == myMachine :
- rshstr = ""
- else :
- rshstr = "rsh -n " + theComputer + " "
- path = self.ComputerPath( theComputer )
-## if path != "" :
-## rshstr = rshstr + path + "/../bin/"
-## else :
-## rshstr = rshstr + os.getenv( "KERNEL_ROOT_DIR" ) + "/bin/"
- if theContainer == "FactoryServer" :
- rshstr = rshstr + path + "SALOME_Container "
- else :
- rshstr = rshstr + path + "SALOME_ContainerPy.py '"
- rshstr = rshstr + theContainer + " -"
- omniORBcfg = os.getenv( "OMNIORB_CONFIG" )
- file = os.open( omniORBcfg , os.O_RDONLY )
- ORBInitRef = os.read(file,132)
- if ORBInitRef[len(ORBInitRef)-1] == '\n' :
- ORBInitRef,bsn = ORBInitRef.split('\n')
- os.close( file )
- rshstr = rshstr + ORBInitRef
- if theContainer == "FactoryServerPy" :
- rshstr = rshstr + "'"
- rshstr = rshstr + " > /tmp/" + theContainer + "_"
- rshstr = rshstr + theComputer
- rshstr = rshstr + ".log 2>&1 &"
- os.system( rshstr )
- MESSAGE( "FindOrStartContainer" + rshstr + " done" )
- else :
- if theContainer.find('Py') == -1 :
- aContainer = self.FindContainer( theComputer + "/" + "FactoryServer" )
- else :
- aContainer = self.FindContainer( theComputer + "/" + "FactoryServerPy" )
- aContainer = aContainer.start_impl( theContainer )
-
- count = 21
- while aContainer is None :
- time.sleep(1)
- count = count - 1
- MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theContainer )
- aContainer = self.FindContainer( theComputer + "/" + theContainer )
- if count == 0 :
- return aContainer
-
- return aContainer
- #os.system("rsh -n dm2s0017 /export/home/KERNEL_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515")
-
+ aContainer= self.StartContainer(theComputer , theContainer )
+ return aContainer
+
#-------------------------------------------------------------------------
def FindOrLoadComponent(self, containerName, componentName):
EXPORT_HEADERS = SALOME_LifeCycleCORBA.hxx
-EXPORT_PYSCRIPTS = LifeCycleCORBA.py
+EXPORT_PYSCRIPTS = LifeCycleCORBA.py Launchers.py
# Libraries targets
self._tc_start = time.time()
self._cstart = time.ctime(self._tc_start)
self._cdir = os.getcwd()
+
+def getapplipath():
+ """
+ Gives short application path (the complete path is $HOME/$APPLI)
+ """
+ return os.environ.get("APPLI",".salome_"+versnb)
+
+try:
+ file = open(os.path.join(os.environ["KERNEL_ROOT_DIR"],"bin","salome","VERSION"), "r")
+ s = file.readline()
+ versnb = string.strip(string.split(s, ":")[1])
+ dirname=".salome_"+versnb
+except:
+ versnb = ""
+ dirname=".salome"
+
+def version():
+ """
+ Gives salome version number
+ """
+ return versnb