From dfeb67c3e06c5f1ff9ad430cfa80868527936148 Mon Sep 17 00:00:00 2001 From: aguerre Date: Wed, 30 Oct 2013 10:29:52 +0000 Subject: [PATCH] Check over OMNIORB_USER_PATH. Test configuration file existence. --- bin/appliskel/salome | 30 +++++++++++------------------- bin/runSalome.py | 23 ++++++++++------------- bin/salomeLauncherUtils.py | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 55 insertions(+), 36 deletions(-) diff --git a/bin/appliskel/salome b/bin/appliskel/salome index 0f402bf7d..d12155b33 100755 --- a/bin/appliskel/salome +++ b/bin/appliskel/salome @@ -17,14 +17,15 @@ def __initialize(): os.environ['APPLI'] = appliPath # needed to convert .sh environment files os.environ['ABSOLUTE_APPLI_PATH'] = absoluteAppliPath - # define folder to store omniorb config (initially in virtual application folder) - #omniorbUserPath = os.path.join(homePath, ".salomeConfig/USERS") - omniorbUserPath = os.path.join(homePath, appliPath, "USERS") - os.environ['OMNIORB_USER_PATH'] = omniorbUserPath - if not os.path.exists(omniorbUserPath): - os.makedirs(omniorbUserPath) - sys.path[:0] = [absoluteAppliPath+'/bin/salome'] + + # define folder to store omniorb config (initially in virtual application folder) + try: + from salomeLauncherUtils import setOmniOrbUserPath + setOmniOrbUserPath() + except Exception, e: + print e + sys.exit(1) # End of preliminary work def main(args): @@ -36,21 +37,12 @@ def main(args): usage() sys.exit(0) - from salomeLauncherUtils import getConfigFileNames - configFileNames, args = getConfigFileNames(args) - - # WHY? Incorrect/Inexisting files are supposed to be ignored by SalomeRunner. - # Might simply need bug fix; please provide test case. - error=False - for aFile in configFileNames: - if not os.path.isfile(aFile): - print "ERROR: inexisting file: "+aFile - error=True - if error: + configFileNames, args, unexisting = getConfigFileNames(args, checkExistence=True) + if len(unexisting) > 0: + print "ERROR: unexisting configuration file(s): " + ', '.join(unexisting) sys.exit(1) - # Create a SalomeRunner which parses configFileNames to initialize environment try: from salomeRunner import SalomeRunner, SalomeRunnerException diff --git a/bin/runSalome.py b/bin/runSalome.py index 676489e1f..e92309a7b 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -32,7 +32,6 @@ import setenv from launchConfigureParser import verbose from server import process_id, Server import json -from salomeLauncherUtils import formatScriptsAndArgs import subprocess # ----------------------------------------------------------------------------- @@ -677,7 +676,7 @@ def startSalome(args, modules_list, modules_root_dir): import readline except ImportError: pass - + # siman session paramenters and checkout processing if simanStudyName(args): print '**********************************************' @@ -698,7 +697,7 @@ def startSalome(args, modules_list, modules_root_dir): mySession = obj._narrow(SALOME.Session) mySession.emitMessage("simanCheckoutDone " + simanStudyName(args)) print '**********************************************' - + return clt # ----------------------------------------------------------------------------- @@ -779,6 +778,7 @@ def useSalome(args, modules_list, modules_root_dir): if not args['gui'] or not args['session_gui']: toimport = args['pyscript'] + from salomeLauncherUtils import formatScriptsAndArgs command = formatScriptsAndArgs(toimport) if command: proc = subprocess.Popen(command, shell=True) @@ -830,16 +830,13 @@ def no_main(): def main(): """Salome launch as a main application""" - ### TEMP >>> ### - if not os.getenv("OMNIORB_USER_PATH"): - homePath = os.path.realpath(os.path.expanduser('~')) - #defaultOmniorbUserPath = os.path.join(homePath, ".salomeConfig/USERS") - defaultOmniorbUserPath = homePath - if os.getenv("APPLI"): - defaultOmniorbUserPath = os.path.join(homePath, os.getenv("APPLI"), "USERS") - os.environ["OMNIORB_USER_PATH"] = defaultOmniorbUserPath - pass - ### <<< TEMP ### + # define folder to store omniorb config (initially in virtual application folder) + try: + from salomeLauncherUtils import setOmniOrbUserPath + setOmniOrbUserPath() + except Exception, e: + print e + sys.exit(1) from salome_utils import getHostName print "runSalome running on %s" % getHostName() diff --git a/bin/salomeLauncherUtils.py b/bin/salomeLauncherUtils.py index 5a59bb178..a3696dec6 100644 --- a/bin/salomeLauncherUtils.py +++ b/bin/salomeLauncherUtils.py @@ -32,7 +32,7 @@ def __getConfigFileNamesDefault(): return __listDirectory(envdDir) # -def getConfigFileNames(args): +def getConfigFileNames(args, checkExistence=False): # special case: configuration files are provided by user # Search for command-line argument(s) --config=file1,file2,..., filen # Search for command-line argument(s) --config=dir1,dir2,..., dirn @@ -40,12 +40,13 @@ def getConfigFileNames(args): configArgs = [ str(x) for x in args if str(x).startswith(configOptionPrefix) ] if len(configArgs) == 0: - return __getConfigFileNamesDefault(), args + return __getConfigFileNamesDefault(), args, [] args = [ x for x in args if not x.startswith(configOptionPrefix) ] allLists = [ x.replace(configOptionPrefix, '') for x in configArgs ] configFileNames = [] + unexisting = [] for currentList in allLists: elements = currentList.split(',') for elt in elements: @@ -53,9 +54,12 @@ def getConfigFileNames(args): if os.path.isdir(elt): configFileNames += __listDirectory(elt) else: - configFileNames += [elt] + if checkExistence and not os.path.isfile(elt): + unexisting += [elt] + else: + configFileNames += [elt] - return configFileNames, args + return configFileNames, args, unexisting # # Return an array of dictionaries {script_name: [list_of_its_args]} @@ -114,3 +118,29 @@ def formatScriptsAndArgs(scriptArgs=[]): command = "; ".join(["%s"%x for x in commands]) return command # + +# Ensure OMNIORB_USER_PATH is defined. This variable refers to a the folder in which +# SALOME will write omniOrb configuration files. +# If OMNIORB_USER_PATH is already set, only checks write access to associated directory ; +# an exception is raised if check fails. It allows users for choosing a specific folder. +# Else the function sets OMNIORB_USER_PATH this way: +# - If APPLI environment variable is set, OMNIORB_USER_PATH is set to ${APPLI}/USERS. +# The function does not check USERS folder existence or wrute access. This folder +# must exist ; this is the case if SALOME virtual application has been create using +# appli_gen.py script. +# - Else OMNIORB_USER_PATH is set to user home directory. +def setOmniOrbUserPath(): + omniorbUserPath = os.getenv("OMNIORB_USER_PATH") + if omniorbUserPath: + if not os.access(omniorbUserPath, os.W_OK): + raise Exception("Unable to get write access to directory: %s"%omniorbUserPath) + pass + else: + homePath = os.path.realpath(os.path.expanduser('~')) + #defaultOmniorbUserPath = os.path.join(homePath, ".salomeConfig/USERS") + defaultOmniorbUserPath = homePath + if os.getenv("APPLI"): + defaultOmniorbUserPath = os.path.join(homePath, os.getenv("APPLI"), "USERS") + pass + os.environ["OMNIORB_USER_PATH"] = defaultOmniorbUserPath +# -- 2.39.2