]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Merge branch 'agr/connect'
authorCédric Aguerre <cedric.aguerre@edf.fr>
Fri, 5 Jun 2015 12:36:59 +0000 (14:36 +0200)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Fri, 5 Jun 2015 12:36:59 +0000 (14:36 +0200)
CMakeLists.txt
bin/appliskel/.salome-completion.sh
bin/appliskel/salome
bin/salomeContextUtils.py.in
src/ResourcesManager/ResourcesManager.cxx

index 7b85d3c255ef845627b7a23230924e8a9f2b1f14..403a9329919d8209e2e9f9c484dca4159f2648fd 100755 (executable)
@@ -34,7 +34,7 @@ SET(${PROJECT_NAME_UC}_MINOR_VERSION 6)
 SET(${PROJECT_NAME_UC}_PATCH_VERSION 0)
 SET(${PROJECT_NAME_UC}_VERSION
   ${${PROJECT_NAME_UC}_MAJOR_VERSION}.${${PROJECT_NAME_UC}_MINOR_VERSION}.${${PROJECT_NAME_UC}_PATCH_VERSION})
-SET(${PROJECT_NAME_UC}_VERSION_DEV 0)
+SET(${PROJECT_NAME_UC}_VERSION_DEV 1)
 
 # Our own set of macros:
 LIST(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/salome_adm/cmake_files")
index 9725b6f608f024886fe8903060449806dac79d7d..5d21670c74d542845d029556ed2575ddf78dadc5 100644 (file)
@@ -71,10 +71,10 @@ _salome()
         if [[ "$cur" == -* ]]; then
             case $command in
                 start)
-                    options='-t --terminal -g --gui -d --show-desktop= -o --hide-desktop -b --batch -l --logger -f --log-file= -r --resources= -x --xterm -m --modules= -e --embedded= -s --standalone= -p --portkill -k --killall -i --interp= -z --splash= -c --catch-exceptions= --print-port --nosave-config --pinter --ns-port-log= --test= --play= --gdb-session --ddd-session --valgrind-session -w --shutdown-servers= --foreground= --wake-up-session --server-launch-mode= --port= --siman --siman-study= --siman-scenario= --siman-user= --version -h --help --with-mpi-module='
+                    options='-t --terminal -g --gui -d --show-desktop= -o --hide-desktop -b --batch -l --logger -f --log-file= -r --resources= -x --xterm -m --modules= -e --embedded= -s --standalone= -p --portkill -k --killall -i --interp= -z --splash= -c --catch-exceptions= --print-port --nosave-config --pinter --ns-port-log= --test= --play= --gdb-session --ddd-session --valgrind-session -w --shutdown-servers= --foreground= --wake-up-session --server-launch-mode= --port= --siman --siman-study= --siman-scenario= --siman-user= --version -h --help --with-mpi-module= --config= --extra_env='
                     ;;
                 shell)
-                    options='-h --help -p --port= -m --machine= -d --directory= -u --user= --with-mpi-module='
+                    options='-h --help -p --port= -m --machine= -d --directory= -u --user= --with-mpi-module= --config= --extra_env='
                     ;;
                 info)
                     options='-h --help -p --ports -v --version'
index 1bcae77fa2d19aecd706a525e147ba81925521f1..df7e2fbe22cd069a2001c898e8ab114866013b64 100755 (executable)
@@ -35,9 +35,10 @@ def main(args):
     sys.exit(0)
 
   from salomeContextUtils import getConfigFileNames
-  configFileNames, args, unexisting = getConfigFileNames(args, checkExistence=True)
+  configFileNames, extraEnv, args, unexisting = getConfigFileNames(args, checkExistence=True)
+
   if len(unexisting) > 0:
-    print "ERROR: unexisting configuration file(s): " + ', '.join(unexisting)
+    print "ERROR: unexisting configuration/environment file(s): " + ', '.join(unexisting)
     sys.exit(1)
 
   # Create a SalomeContext which parses configFileNames to initialize environment
@@ -52,6 +53,10 @@ def main(args):
     # context.addToPythonPath('mypythonpath')
     # context.setVariable('myvarname', 'value')
 
+    if extraEnv:
+      for key,val in extraEnv.items():
+        context.addToVariable(key,val)
+
     # Start SALOME, parsing command line arguments
     (out, err), returncode = context.runSalome(args)
     if out:
index dcd9854e59abde031bb092a8699dbde9be2092eb..3f3158116ca36e9606a1497ec7b27c27f81f68f5 100644 (file)
@@ -61,18 +61,14 @@ def __getConfigFileNamesDefault():
   return __listDirectory(envdDir)
 #
 
-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
-  configOptionPrefix = "--config="
-  configArgs = [ str(x) for x in args if str(x).startswith(configOptionPrefix) ]
+def __getEnvironmentFileNames(args, optionPrefix, checkExistence):
+  # special case: extra configuration/environment files are provided by user
+  # Search for command-line argument(s) <optionPrefix>=file1,file2,..., filen
+  # Search for command-line argument(s) <optionPrefix>=dir1,dir2,..., dirn
+  configArgs = [ str(x) for x in args if str(x).startswith(optionPrefix) ]
 
-  if len(configArgs) == 0:
-    return __getConfigFileNamesDefault(), args, []
-
-  args = [ x for x in args if not x.startswith(configOptionPrefix) ]
-  allLists = [ x.replace(configOptionPrefix, '') for x in configArgs ]
+  args = [ x for x in args if not x.startswith(optionPrefix) ]
+  allLists = [ x.replace(optionPrefix, '') for x in configArgs ]
 
   configFileNames = []
   unexisting = []
@@ -91,6 +87,105 @@ def getConfigFileNames(args, checkExistence=False):
   return configFileNames, args, unexisting
 #
 
+def __validate_pair(ob):
+  try:
+    if not (len(ob) == 2):
+      #print "Unexpected result:", ob
+      raise ValueError
+  except:
+    return False
+  return True
+#
+def __get_environment_from_batch_command(env_cmd, initial=None):
+  """
+  Take a command (either a single command or list of arguments)
+  and return the environment created after running that command.
+  Note that if the command must be a batch file or .cmd file, or the
+  changes to the environment will not be captured.
+
+  If initial is supplied, it is used as the initial environment passed
+  to the child process.
+  """
+  #if not isinstance(env_cmd, (list, tuple)):
+  #    env_cmd = [env_cmd]
+  # construct the command that will alter the environment
+  #env_cmd = subprocess.list2cmdline(env_cmd)
+  # create a tag so we can tell in the output when the proc is done
+  tag = 'Done running command'
+  # construct a command to do accomplish this
+  cmd = '{env_cmd} && echo "{tag}"'.format(**vars())
+
+  # launch the process
+  proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, env=initial, shell=True)
+  # parse the output sent to stdout
+  lines = proc.stdout
+  # consume whatever output occurs until the tag is reached
+  #consume(itertools.takewhile(lambda l: tag not in l, lines))
+  # define a way to handle each KEY=VALUE line
+  handle_line = lambda l: l.rstrip().split('=',1)
+  # parse key/values into pairs
+  #pairs = map(handle_line, lines)
+  pairs = []
+  cpt = 0
+  while True:
+    line = lines.readline()
+    cpt = cpt+1
+    if tag in line or cpt > 1000:
+      break
+    if line:
+      pairs.append(line.rstrip().split('=',1))
+  # make sure the pairs are valid
+  valid_pairs = filter(__validate_pair, pairs)
+  # construct a dictionary of the pairs
+  result = dict(valid_pairs)
+  # let the process finish
+  proc.communicate()
+  return result
+#
+def __subtract(ref, dic):
+  result = {}
+  for key,val in ref.items():
+    if not dic.has_key(key):
+      result[key] = val
+    else:
+      # compare values types
+      if (type(dic[key]) != type(val)):
+        result[key] = val
+      else:
+        # compare values
+        if isinstance(val, basestring):
+          tolist1 = dic[key].split(os.pathsep)
+          tolist2 = val.split(os.pathsep)
+          diff = list(set(tolist2)-set(tolist1))
+          if diff:
+            result[key] = os.pathsep.join(diff)
+        else:
+          result[key] = val
+
+  return result
+#
+
+def getConfigFileNames(args, checkExistence=False):
+  configOptionPrefix = "--config="
+  configArgs = [ str(x) for x in args if str(x).startswith(configOptionPrefix) ]
+  if len(configArgs) == 0:
+    configFileNames, unexist1 = __getConfigFileNamesDefault(), []
+  else:
+    # get configuration filenames
+    configFileNames, args, unexist1 = __getEnvironmentFileNames(args, configOptionPrefix, checkExistence)
+
+  # get extra environment
+  extraEnvFileNames, args, unexist2 = __getEnvironmentFileNames(args, "--extra_env=", checkExistence)
+  before = __get_environment_from_batch_command("env")
+  after = {}
+  for filename in extraEnvFileNames:
+    after.update(__get_environment_from_batch_command(filename))
+    pass
+
+  extraEnv = __subtract(after,before)
+  return configFileNames, extraEnv, args, unexist1+unexist2
+#
+
 def __getScriptPath(scriptName, searchPathList):
   scriptName = os.path.expanduser(scriptName)
   if os.path.isabs(scriptName):
index 484b856b7f1b3655e554d9517ec16eb96c365bb2..ba27107b4257e04fe47893d323757728c18d95bf 100644 (file)
@@ -603,7 +603,12 @@ void ResourcesManager_cpp::AddDefaultResourceInCatalog()
   {
     resource.AppliPath = string(getenv("HOME")) + "/" + getenv("APPLI");
   }
-  resource.working_directory = "/tmp/salome_localres_workdir";
+  string tmpdir = "/tmp";
+  if (getenv("TMPDIR") != NULL)
+    tmpdir = getenv("TMPDIR");
+  resource.working_directory = tmpdir + "/salome_localres_workdir";
+  if (getenv("USER") != NULL)
+    resource.working_directory += string("_") + getenv("USER");
   resource.can_launch_batch_jobs = true;
   resource.can_run_containers = true;
   _resourcesList[resource.Name] = resource;