X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=bin%2Fsalome_utils.py;h=090332386cefc093952de6142052c13314f0ebe4;hb=9484eae0407296e960cb8468cf279bd87a65a41e;hp=dc79fb1c6774fe1976c214eb52726ad7d8f180b6;hpb=9749fc1db72bd80e278405114b05ffc69b5031da;p=modules%2Fkernel.git diff --git a/bin/salome_utils.py b/bin/salome_utils.py index dc79fb1c6..090332386 100644 --- a/bin/salome_utils.py +++ b/bin/salome_utils.py @@ -1,10 +1,10 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2007-2015 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 # License as published by the Free Software Foundation; either -# version 2.1 of the License. +# version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -39,6 +39,7 @@ __all__ = [ 'getShortHostName', 'getAppName', 'getPortNumber', + 'getLogDir', 'getTmpDir', 'getHomeDir', 'generateFileName', @@ -71,7 +72,7 @@ def getORBcfgInfo(): """ Get omniORB current configuration. Returns a list of three values: [ orb_version, host_name, port_number ]. - + The information is retrieved from the omniORB configuration file defined by the OMNIORB_CONFIG environment variable. If omniORB configuration file can not be accessed, a list of three empty @@ -125,12 +126,18 @@ def getPortFromORBcfg(): def getUserName(): """ Get user name: - 1. try USER environment variable - 2. if fails, return 'unknown' as default 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 - return os.getenv( "USER", "unknown" ) # 'unknown' is 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") # --- def getHostName(): @@ -168,7 +175,7 @@ def getShortHostName(): except: pass return "unknown" # 'unknown' is default host name - + # --- def getAppName(): @@ -208,41 +215,27 @@ def getHomeDir(): """ Get home directory. """ - import os, sys - if sys.platform == "win32": - # for Windows the home directory is detected in the following way: - # 1. try USERPROFILE env variable - # 2. try combination of HOMEDRIVE and HOMEPATH env variables - # 3. try HOME env variable - # TODO: on Windows, also GetUserProfileDirectoryW() system function might be used - dir = os.getenv("USERPROFILE") - if not dir and os.getenv("HOMEDRIVE") and os.getenv("HOMEPATH"): - dir = os.path.join(os.getenv("HOMEDRIVE"), os.getenv("HOMEPATH")) - if not dir: - dir = os.getenv("HOME") - pass - else: - # for Linux: use HOME variable - dir = os.getenv("HOME") - pass - return dir + import os + return os.path.realpath(os.path.expanduser('~')) +# --- + +def getLogDir(): + """ + Get directory to be used for the log files. + """ + import os + return os.path.join(getTmpDir(), "logs", getUserName()) # --- def getTmpDir(): """ Get directory to be used for the temporary files. """ - import os, sys - if sys.platform == "win32": - # for Windows: temporarily using home directory for tmp files; - # to be replaced with TEMP environment variable later... - dir = os.getenv("HOME") - else: - # for Linux: use /tmp/logs/{user} folder - dir = os.path.join( '/tmp', 'logs', getUserName() ) - pass - return dir - + import os, tempfile + f = tempfile.NamedTemporaryFile() + tmpdir = os.path.dirname(f.name) + f.close() + return tmpdir # --- def generateFileName( dir, prefix = None, suffix = None, extension = None, @@ -481,6 +474,7 @@ def verbose(): pass # return _verbose +# -- def setVerbose(level): """ @@ -489,4 +483,4 @@ def setVerbose(level): global _verbose _verbose = level return - +# --