Salome HOME
Integration of [CEA 13233] support new xdr.h location
[modules/kernel.git] / bin / salome_utils.py
index 67c352f9902ff905d12bbf78fb38c07083bae56c..80c2adac9fe700dd0ac54f11f299f4892cf62daf 100644 (file)
@@ -1,5 +1,5 @@
 #  -*- coding: iso-8859-1 -*-
-# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -56,10 +56,9 @@ def _try_bool( arg ):
     are supported.
     If <arg> does not represent a boolean, an exception is raised.
     """
-    import types
-    if type( arg ) == bool  :
+    if isinstance(arg, bool)  :
         return arg
-    elif type( arg ) == bytes  :
+    elif isinstance(arg, (str, bytes)):
         v = str( arg ).lower()
         if   v in [ "yes", "y", "true"  ]: return True
         elif v in [ "no",  "n", "false" ]: return False
@@ -148,7 +147,6 @@ def getHostName():
     3. if fails, try HOST environment variable
     4. if fails, return 'unknown' as default host name
     """
-    import os
     try:
         import socket
         host = socket.gethostname()
@@ -158,6 +156,11 @@ def getHostName():
     if not host: host = os.getenv("HOSTNAME")
     if not host: host = os.getenv("HOST")
     if not host: host = "unknown"           # 'unknown' is default host name
+    try:
+        socket.gethostbyname(host)
+    except:
+        host = "localhost"
+    pass
     return host
 
 # ---
@@ -241,7 +244,7 @@ def getTmpDir():
 def generateFileName( dir, prefix = None, suffix = None, extension = None,
                       unique = False, separator = "_", hidden = False, **kwargs ):
     """
-    Generate file name by sepecified parameters. If necessary, file name
+    Generate file name by specified parameters. If necessary, file name
     can be generated to be unique.
 
     Parameters: