From: Cédric Aguerre Date: Mon, 24 Nov 2014 13:40:35 +0000 (+0100) Subject: remove hard-coded paths X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=40a7ae371afba3f6875baeb16805bcf8927d4ea4;p=modules%2Fyacs.git remove hard-coded paths remove hard-coded paths --- diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index e6dcf5d37..b1dcaab42 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -61,7 +61,7 @@ def getPiDict(port,appname='salome',full=True,hidden=True,hostname=None): except: pass - from salome_utils import generateFileName, getTmpDir + from salome_utils import generateFileName, getLogDir dir = "" if not hostname: hostname = os.getenv("NSHOST") @@ -72,7 +72,7 @@ def getPiDict(port,appname='salome',full=True,hidden=True,hostname=None): if hidden: # new-style dot-prefixed pidict files # are in the system-dependant temporary diretory - dir = getTmpDir() + dir = getLogDir() else: # old-style non-dot-prefixed pidict files # are in the user's home directory @@ -197,7 +197,7 @@ def shutdownMyPort(port, cleanup=True): try: import time from omniORB import CORBA - + from LifeCycleCORBA import LifeCycleCORBA # shutdown all orb = CORBA.ORB_init([''], CORBA.ORB_ID) @@ -223,15 +223,8 @@ def __killMyPort(port, filedict): try: with open(filedict, 'r') as fpid: # - from salome_utils import generateFileName - if sys.platform == "win32": - username = os.getenv( "USERNAME" ) - tmpdir = 'c:\tmp' - else: - username = os.getenv('USER') - tmpdir = '/tmp' - path = os.path.join(tmpdir, 'logs', username) - fpidomniNames = generateFileName(path, + from salome_utils import generateFileName, getLogDir + fpidomniNames = generateFileName(getLogDir(), prefix="", suffix="Pid_omniNames", extension="log", @@ -378,7 +371,7 @@ def killMyPort(port): time.sleep(3) # wait a little, then kill processes (should be done if shutdown procedure hangs up) try: - import PortManager + import PortManager # do not remove! Test for PortManager availability! filedict = getPiDict(port) #filedict = __guessPiDictFilename(port) import glob diff --git a/bin/nameserver.py b/bin/nameserver.py index 56c100269..ad302db2d 100755 --- a/bin/nameserver.py +++ b/bin/nameserver.py @@ -31,39 +31,20 @@ from launchConfigureParser import verbose # ----------------------------------------------------------------------------- class NamingServer(Server): - XTERM = "" - USER = os.getenv('USER') - if USER is None: - USER = 'anonymous' + #XTERM = "" + #USER = os.getenv('USER') + #if USER is None: + # USER = 'anonymous' #os.system("mkdir -m 777 -p /tmp/logs") - LOGDIR = "/tmp/logs/" + USER + #LOGDIR = "/tmp/logs/" + USER def initNSArgs(self): - if sys.platform == "win32": - # temporarily using home directory for Namning Service logs - # to be replaced with TEMP later... - os.environ["BaseDir"]=os.environ["HOME"] - else: - os.environ["BaseDir"]="/tmp" - - try: - os.mkdir(os.environ["BaseDir"] + "/logs") - os.chmod(os.environ["BaseDir"] + "/logs", 0777) - except: - #print "Can't create " + os.environ["BaseDir"] + "/logs" - pass - - upath = os.environ["BaseDir"] + "/logs/"; - if sys.platform == "win32": - upath += os.environ["Username"]; - else: - upath += os.environ["USER"]; - + from salome_utils import getLogDir + upath = getLogDir() try: - os.mkdir(upath) + os.makedirs(upath, mode=0777) except: - #print "Can't create " + upath - pass + pass if verbose(): print "Name Service... ", #hname=os.environ["HOST"] #commands.getoutput("hostname") @@ -87,14 +68,14 @@ class NamingServer(Server): # it is cleaner on linux and it is a fix for salome since it is impossible to # remove the log files if the corresponding omniNames has not been killed. # \end{E.A.} - - upath += "/omniNames_%s"%(aPort) + + upath = os.path.join(upath, "omniNames_%s"%(aPort)) try: os.mkdir(upath) except: #print "Can't create " + upath pass - + #os.system("touch " + upath + "/dummy") for fname in os.listdir(upath): try: @@ -134,7 +115,7 @@ class NamingServer(Server): # Others Containers are started with start_impl method of FactoryServer Container. # For using rsh it is necessary to have in the ${HOME} directory a .rhosts file # Warning : on RedHat the file /etc/hosts contains by default a line like : -# 127.0.0.1 bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost +# 127.0.0.1 bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost # (bordolex is the station name). omniNames on bordolex will be accessible from other # computers only if the computer name is removed on that line like : # 127.0.0.1 bordolex.paris1.matra-dtv.fr localhost.localdomain localhost diff --git a/bin/runSalome.py b/bin/runSalome.py index 0c64fbcd9..da1c56946 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -223,10 +223,8 @@ class LoggerServer(Server): def __init__(self,args): self.args=args self.initArgs() - from salome_utils import generateFileName - if sys.platform == "win32": dirpath = os.environ["HOME"] - else: dirpath = "/tmp" - logfile = generateFileName( dirpath, + from salome_utils import generateFileName, getLogDir + logfile = generateFileName( getLogDir(), prefix="logger", extension="log", with_username=True, @@ -489,8 +487,10 @@ def startSalome(args, modules_list, modules_root_dir): # set siman python path before the session server launching to import scripts inside python console if simanStudyName(args): # MPV: use os.environ here because session server is launched in separated process and sys.path is missed in this case - os.environ["PYTHONPATH"] = "/tmp/SimanSalome/" + args['siman_study'] + "/" + \ - args['siman_scenario'] + "/" + args['siman_user'] + os.pathsep + os.environ["PYTHONPATH"]; + from salome_utils import getTmpDir + ppath = os.path.join(getTmpDir, "SimanSalome", args['siman_study'], + args['siman_scenario'], args['siman_user']) + os.environ["PYTHONPATH"] = ppath + os.pathsep + os.environ["PYTHONPATH"] # Launch Session Server (to show splash ASAP) # @@ -771,11 +771,8 @@ def registerEnv(args, modules_list, modules_root_dir): Register args, modules_list, modules_root_dir in a file for further use, when SALOME is launched embedded in an other application. """ - if sys.platform == "win32": - fileEnv = os.getenv('TEMP') - else: - fileEnv = '/tmp/' - + from salome_utils import getTmpDir + fileEnv = getTmpDir() fileEnv += os.getenv('USER') + "_" + str(args['port']) \ + '_' + args['appname'].upper() + '_env' fenv=open(fileEnv,'w') diff --git a/bin/salome_utils.py b/bin/salome_utils.py index f20f67276..43ffaba7c 100644 --- a/bin/salome_utils.py +++ b/bin/salome_utils.py @@ -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,14 @@ def getPortFromORBcfg(): def getUserName(): """ Get user name: - 1. try USER environment variable + 1. try USER environment variable (USERNAME on windows) 2. 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: + return os.getenv("USER", "unknown") # --- def getHostName(): @@ -168,7 +171,7 @@ def getShortHostName(): except: pass return "unknown" # 'unknown' is default host name - + # --- def getAppName(): @@ -212,21 +215,23 @@ def getHomeDir(): 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, @@ -465,6 +470,7 @@ def verbose(): pass # return _verbose +# -- def setVerbose(level): """ @@ -473,4 +479,4 @@ def setVerbose(level): global _verbose _verbose = level return - +# -- diff --git a/bin/setenv.py b/bin/setenv.py index cb5c8d8d0..e302fd1dd 100755 --- a/bin/setenv.py +++ b/bin/setenv.py @@ -81,12 +81,12 @@ def get_lib_dir(): def get_config(silent=False): """ Get list of modules, paths. - + Read args from launch configure xml file and command line options. Check variables _ROOT_DIR and set list of used modules. - Return args, modules_list, modules_root_dir + Return args, modules_list, modules_root_dir """ - + # read args from launch configure xml file and command line options #*** Test additional option @@ -150,14 +150,14 @@ def get_config(silent=False): def set_env(args, modules_list, modules_root_dir, silent=False): """Add to the PATH-variables modules specific paths""" - + import os - from salome_utils import getTmpDir, generateFileName, makeTmpDir, getPortNumber + from salome_utils import getLogDir, generateFileName, makeTmpDir, getPortNumber # create temporary directory for environment files needed by modules from the list port = getPortNumber(False) if port: - tmp_dir = getTmpDir() + tmp_dir = getLogDir() env_dir = generateFileName(tmp_dir, prefix="env", with_port=True) makeTmpDir(env_dir) pass @@ -167,8 +167,8 @@ def set_env(args, modules_list, modules_root_dir, silent=False): if os.getenv('SALOME_BATCH') == None: os.putenv('SALOME_BATCH','0') if args["gui"] : - modules_list = modules_list[:] + ["GUI"] - modules_list = modules_list[:] + ["KERNEL"] + modules_list = modules_list[:] + ["GUI"] + modules_list = modules_list[:] + ["KERNEL"] for module in modules_list : if modules_root_dir.has_key(module): module_root_dir = modules_root_dir[module] @@ -224,9 +224,9 @@ def set_env(args, modules_list, modules_root_dir, silent=False): os.environ["SALOMEPATH"]=";".join(modules_root_dir_list) else: os.environ["SALOMEPATH"]=":".join(modules_root_dir_list) - + # set trace environment variable - + if not os.environ.has_key("SALOME_trace"): os.environ["SALOME_trace"]="local" if args['file']: