From: Gilles DAVID Date: Thu, 3 Jun 2021 14:26:15 +0000 (+0200) Subject: getUserName now uses the standard getpass module X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=427a91cc50ebccbfa98c4b95c1a380dc6c6cab89;p=modules%2Fkernel.git getUserName now uses the standard getpass module --- diff --git a/bin/salome_utils.py b/bin/salome_utils.py index cb0b454ac..61aa30203 100644 --- a/bin/salome_utils.py +++ b/bin/salome_utils.py @@ -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():