]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
getUserName now uses the standard getpass module
authorGilles DAVID <gilles-g.david@edf.fr>
Thu, 3 Jun 2021 14:26:15 +0000 (16:26 +0200)
committerGilles DAVID <gilles-g.david@edf.fr>
Thu, 3 Jun 2021 14:26:15 +0000 (16:26 +0200)
bin/salome_utils.py

index cb0b454ac429404508acafbef15a8d5ac23f8fe5..61aa302033e1b23807942797d8d64aac0372d3f8 100644 (file)
@@ -125,18 +125,21 @@ def getPortFromORBcfg():
 def getUserName():
     """
     Get user name:
-    1. try USER environment variable (USERNAME on windows)
-    2. if fails, try LOGNAME (un*x)
-    3. if fails return 'unknown' as default user name
-    """
-    import os, sys
-    if sys.platform == "win32":
-        return os.getenv("USERNAME", "unknown")
-    else:
-        user = os.getenv("USER")
-        if user:
-            return user
-        return os.getenv("LOGNAME", "unknown")
+    Uses the getpass standard module which test the
+    following variables (in that order):
+    1. LOGNAME
+    2. USER
+    3. LNAME
+    4. USERNAME
+    If none of these variable is set, try with the pwd module
+    if supported.
+    Finally raises an exception if nothing is found.
+    """
+    import getpass
+    try:
+        return getpass.getuser()
+    except Exception:
+        return 'unknown'
 # ---
 
 def getHostName():