Salome HOME
[tuleap29134] : fix for runSalomeOld.py the defaut SSL mode in -t context
[modules/kernel.git] / bin / salome_utils.py
index 33fc6320ab91424db678545cd680cf3e4b2f2f7d..346db515ac7948fe4706e8ec5382752b72624d0b 100644 (file)
@@ -116,8 +116,14 @@ def getUserName():
 
     :return user name
     """
-    return os.getenv('USERNAME', 'unknown') if sys.platform == 'win32' \
-        else os.getenv('USER', os.getenv('LOGNAME', 'unknown'))
+    if sys.platform == 'win32':
+        username = os.getenv('USERNAME')
+    else:
+        username = os.getenv('USER', os.getenv('LOGNAME'))
+    if username is None:
+        import getpass
+        username = getpass.getuser()
+    return username
 
 # ---
 
@@ -170,6 +176,9 @@ def getAppName():
     """
     return os.getenv('APPNAME', 'SALOME') # 'SALOME' is default user name
 
+def getPid():
+    return os.getpid()
+
 # ---
 
 def getPortNumber(use_default=True):
@@ -246,6 +255,7 @@ def generateFileName(path, prefix=None, suffix=None, extension=None,
     - with_hostname : use host name:
     - with_port : use port number:
     - with_app      : use application name:
+    - with_pid      : use current pid
 
     Any of these keyword arguments can accept either explicit string value,
     or `True` to automatically deduce value from current configuration.
@@ -270,6 +280,7 @@ def generateFileName(path, prefix=None, suffix=None, extension=None,
     _with_kwarg('with_hostname', getShortHostName)
     _with_kwarg('with_port', getPortNumber)
     _with_kwarg('with_app', getAppName)
+    _with_kwarg('with_pid', getPid)
     _with_str(suffix)
 
     # raise an exception if file name is empty