From: prascle Date: Fri, 12 Nov 2004 13:05:23 +0000 (+0000) Subject: PR: new python function getShortHostName() in Utils_Identity.py, based on socket... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2a9dfb2c5032dc3bfd0c6ac614be64703112f79d;p=modules%2Fyacs.git PR: new python function getShortHostName() in Utils_Identity.py, based on socket.gethotname(), to avoid use of HOSTNAME variable, not allways defined. bin/runSalome.py src/Container/SALOME_ComponentPy.py src/Container/SALOME_ContainerPy.py src/LifeCycleCORBA/LifeCycleCORBA.py src/MPILifeCycleCORBA/MPILifeCycleCORBA.py src/TestContainer/TestComponentPy.py src/Utils/Utils_Identity.py --- diff --git a/bin/runSalome.py b/bin/runSalome.py index 1274e9a45..3ef483331 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -502,15 +502,15 @@ def startSalome(args, modules_list, modules_root_dir): import SALOME session=clt.waitNS("/Kernel/Session",SALOME.Session) + from Utils_Identity import getShortHostName + if os.getenv("HOSTNAME") == None: if os.getenv("HOST") == None: - os.environ["HOSTNAME"]="localhost" + os.environ["HOSTNAME"]=getShortHostName() else: os.environ["HOSTNAME"]=os.getenv("HOST") - theComputer = os.getenv("HOSTNAME") - computerSplitName = theComputer.split('.') - theComputer = computerSplitName[0] + theComputer = getShortHostName() # # Lancement Container C++ local, diff --git a/src/Container/SALOME_ComponentPy.py b/src/Container/SALOME_ComponentPy.py index 37b00188e..10a47c978 100755 --- a/src/Container/SALOME_ComponentPy.py +++ b/src/Container/SALOME_ComponentPy.py @@ -74,8 +74,8 @@ class SALOME_ComponentPy_i (Engines__POA.Component): self._Executed = 0 naming_service = SALOME_NamingServicePy_i(self._orb) - myMachine=string.split(os.getenv( "HOSTNAME" ),'.') - Component_path = "/Containers/" + myMachine[0] + "/" + self._containerName + "/" + self._interfaceName + myMachine=getShortHostName() + Component_path = "/Containers/" + myMachine + "/" + self._containerName + "/" + self._interfaceName MESSAGE( 'SALOME_ComponentPy_i Register' + str( Component_path ) ) naming_service.Register(self._this(), Component_path) diff --git a/src/Container/SALOME_ContainerPy.py b/src/Container/SALOME_ContainerPy.py index d3d54ae13..417599eb9 100755 --- a/src/Container/SALOME_ContainerPy.py +++ b/src/Container/SALOME_ContainerPy.py @@ -40,6 +40,7 @@ from SALOME_NamingServicePy import * from SALOME_ComponentPy import * from SALOME_utilities import * +from Utils_Identity import getShortHostName #============================================================================= @@ -58,10 +59,10 @@ class SALOME_ContainerPy_i (Engines__POA.Container): self._poa = poa self._containerName = containerName - myMachine=string.split(os.getenv( "HOSTNAME" ),'.') + myMachine=getShortHostName() naming_service = SALOME_NamingServicePy_i(self._orb) self._naming_service = naming_service - Container_path = "/Containers/" + myMachine[0] + "/" + self._containerName + Container_path = "/Containers/" + myMachine + "/" + self._containerName MESSAGE( str(Container_path) ) naming_service.Register(self._this(), Container_path) @@ -69,8 +70,8 @@ class SALOME_ContainerPy_i (Engines__POA.Container): def start_impl(self, ContainerName): MESSAGE( "SALOME_ContainerPy_i::start_impl " + str(ContainerName) ) - myMachine=string.split(os.getenv( "HOSTNAME" ),'.') - theContainer = "/Containers/" + myMachine[0] + "/" + ContainerName + myMachine=getShortHostName() + theContainer = "/Containers/" + myMachine + "/" + ContainerName try: obj = self._naming_service.Resolve(theContainer) except : diff --git a/src/LifeCycleCORBA/LifeCycleCORBA.py b/src/LifeCycleCORBA/LifeCycleCORBA.py index 448491864..273916dd4 100644 --- a/src/LifeCycleCORBA/LifeCycleCORBA.py +++ b/src/LifeCycleCORBA/LifeCycleCORBA.py @@ -36,6 +36,7 @@ import Engines import SALOME_ModuleCatalog from SALOME_utilities import * +from Utils_Identity import getShortHostName class LifeCycleCORBA: _orb = None @@ -87,9 +88,9 @@ class LifeCycleCORBA: theComputer = "" theContainer = containerName if theComputer == "" : - theComputer = os.getenv("HOSTNAME") + theComputer = getShortHostName() if theComputer == "localhost" : - theComputer = os.getenv("HOSTNAME") + theComputer = getShortHostName() computerSplitName = theComputer.split('.') theComputer = computerSplitName[0] MESSAGE( theComputer + theContainer ) @@ -134,8 +135,8 @@ class LifeCycleCORBA: aContainer = self.FindContainer( theComputer + "/" + theContainer ) if aContainer is None : if (theContainer == "FactoryServer") | (theContainer == "FactoryServerPy") : - myMachine=string.split(os.getenv( "HOSTNAME" ),'.') - if theComputer == myMachine[0] : + myMachine=getShortHostName() + if theComputer == myMachine : rshstr = "" else : rshstr = "rsh -n " + theComputer + " " diff --git a/src/MPILifeCycleCORBA/MPILifeCycleCORBA.py b/src/MPILifeCycleCORBA/MPILifeCycleCORBA.py index eb255d862..0b26acfb0 100644 --- a/src/MPILifeCycleCORBA/MPILifeCycleCORBA.py +++ b/src/MPILifeCycleCORBA/MPILifeCycleCORBA.py @@ -8,6 +8,7 @@ #============================================================================== from LifeCycleCORBA import * +from Utils_Identity import getShortHostName class MPILifeCycleCORBA(LifeCycleCORBA): #------------------------------------------------------------------------- @@ -24,7 +25,7 @@ class MPILifeCycleCORBA(LifeCycleCORBA): aMPIContainer = self.FindContainer( theComputer + "/" + theMPIContainer ) if aMPIContainer is None : if (theMPIContainerRoot == "MPIFactoryServer") | (theMPIContainerRoot == "MPIFactoryServerPy") : - if theComputer == os.getenv("HOSTNAME") : + if theComputer == getShortHostName() : rshstr = "" else : rshstr = "rsh -n " + theComputer + " " diff --git a/src/TestContainer/TestComponentPy.py b/src/TestContainer/TestComponentPy.py index 2dacf6dbb..b6c248463 100755 --- a/src/TestContainer/TestComponentPy.py +++ b/src/TestContainer/TestComponentPy.py @@ -34,6 +34,7 @@ import string from omniORB import CORBA import CosNaming import Engines +from Utils_Identity import getShortHostName #initialise the ORB @@ -48,8 +49,7 @@ if rootContext is None: sys.exit(1) #resolve the name /Containers.dir/FactoryServerPy.object -myMachine=string.split(os.getenv( "HOSTNAME" ),'.') -machineName= myMachine[0] +machineName= getShortHostName() containerName = "FactoryServerPy" name = [CosNaming.NameComponent("Containers","dir"), CosNaming.NameComponent(machineName,"dir"), diff --git a/src/Utils/Utils_Identity.py b/src/Utils/Utils_Identity.py index 42dac4f3a..4f4cc4520 100644 --- a/src/Utils/Utils_Identity.py +++ b/src/Utils/Utils_Identity.py @@ -33,12 +33,23 @@ import os import socket import pwd import time +import string + +def getShortHostName(): + """ + gives Hostname without domain extension. + SALOME naming service needs short Hostnames (without domain extension). + HOSTNAME is not allways defined in environment, + socket.gethostname() gives short or complete Hostname, depending on + defined aliases. + """ + return string.split(socket.gethostname(),'.')[0] class Identity: def __init__(self,name): self._name = name self._pid = os.getpid() - self._machine = os.getenv( "HOSTNAME" ) + self._machine = socket.gethostname() self._adip = socket.gethostbyname(self._machine) # IP adress self._uid = os.getuid() list = pwd.getpwuid(self._uid)