]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
PR: new python function getShortHostName() in Utils_Identity.py, based on socket...
authorprascle <prascle>
Fri, 12 Nov 2004 13:05:23 +0000 (13:05 +0000)
committerprascle <prascle>
Fri, 12 Nov 2004 13:05:23 +0000 (13:05 +0000)
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

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

index 1274e9a4530a388ba25c31ec90f2396f77698fb5..3ef4833318b9998ba587cff70c000105ac4625f7 100755 (executable)
@@ -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,
index 37b00188e33929a05f71da349789e5c2b56a0fc8..10a47c9781447c770817d9f1e470bdaa38fff828 100755 (executable)
@@ -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)
 
index d3d54ae13a63b18b32476673dfd928bd0ee50b96..417599eb98239f851e815c623d3e94ab777f72d2 100755 (executable)
@@ -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 :
index 448491864e96b1ee4a1ca18ac4ba94b9a90cfc7f..273916dd4d9b48e37ddfd76561c27c5e396c8120 100644 (file)
@@ -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 + " "
index eb255d862607c425a68c495a164bb1062f29a798..0b26acfb0cb5bc4cf1ac3238f470d6c45f4d5cdb 100644 (file)
@@ -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 + " "
index 2dacf6dbbd5e886165a12cbda5abebbef970e5d8..b6c2484631b151d525e25ecd96dcd7dd083f7e21 100755 (executable)
@@ -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"),
index 42dac4f3a7ea14b7848f4e26b159492f62e3048b..4f4cc4520cf7d2febefa83ab9acaefad102dba09 100644 (file)
@@ -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)