-# Copyright (C) 2013-2014 CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2013-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
import platform
from salomeContextUtils import SalomeContextException
-from salomeContextUtils import getScriptsAndArgs, formatScriptsAndArgs
def usage():
#exeName = os.path.splitext(os.path.basename(__file__))[0]
msg = '''\
-Usage: salome [command] [options] [--config=file1,...,filen]
+Usage: salome [command] [options] [--config=<file,folder,...>]
Commands:
- start Launches SALOME virtual application [DEFAULT]
- shell Executes a script under SALOME application environment
+=========
+ start Starts a SALOME session (through virtual application)
+ shell Initializes SALOME environment, and executes scripts passed
+ as command arguments
connect Connects a Python console to the active SALOME session
- killall Kill all SALOME running sessions
+ killall Kill all SALOME running sessions for current user
info Display some information about SALOME
help Show this message
- coffee Yes! SALOME can also make coffee!!"
+ coffee Yes! SALOME can also make coffee!!
-Use salome start --help or salome shell --help
-to show help on start and shell commands.
+If no command is given, default to start.
+
+Command options:
+================
+ Use salome <command> --help to show help on command ; available for start
+ and shell commands.
+
+--config=<file,folder,...>
+==========================
+ Initialize SALOME environment from a list of context files and/or a list
+ of folders containing context files. The list is comma-separated, whithout
+ any blank characters.
'''
print msg
the SalomeContext class will try to automatically convert them
to .cfg format before setting the environment.
"""
- def __init__(self, configFileNames=[]):
+ def __init__(self, configFileNames=0):
#it could be None explicitely (if user use multiples setVariable...for standalone)
- if configFileNames==None:
+ if configFileNames is None:
return
-
+ configFileNames = configFileNames or []
if len(configFileNames) == 0:
raise SalomeContextException("No configuration files given")
def runSalome(self, args):
# Run this module as a script, in order to use appropriate Python interpreter
# according to current path (initialized from environment files).
- kill = False
- for e in args:
- if "--shutdown-server" in e:
- kill = True
- args.remove(e)
+# kill = False
+# for e in args:
+# if "--shutdown-server" in e:
+# kill = True
+# args.remove(e)
+ import os
absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
- proc = subprocess.Popen(['python', os.path.join(absoluteAppliPath,"bin","salome","salomeContext.py"), pickle.dumps(self), pickle.dumps(args)], shell=False, close_fds=True)
+ env_copy = os.environ.copy()
+ proc = subprocess.Popen(['python', os.path.join(absoluteAppliPath,"bin","salome","salomeContext.py"), pickle.dumps(self), pickle.dumps(args)], shell=False, close_fds=True, env=env_copy)
msg = proc.communicate()
- if kill:
- self._killAll(args)
+ # if kill:
+ # self._killAll(args)
return msg, proc.returncode
#
See usage for details on commands.
"""
def _startSalome(self, args):
+ try:
+ import os
+ absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH')
+ import sys
+ path = os.path.realpath(os.path.join(absoluteAppliPath, "bin", "salome"))
+ if not path in sys.path:
+ sys.path[:0] = [path]
+ except:
+ pass
+
command, options = self.__parseArguments(args)
sys.argv = options
sys.exit(1)
#
- def __setEnvironmentFromConfigFile(self, filename, reserved=[]):
+ def __setEnvironmentFromConfigFile(self, filename, reserved=None):
+ if reserved is None:
+ reserved = []
try:
unsetVars, configVars, reservedDict = parseConfigFile(filename, reserved)
except SalomeContextException, e:
# set environment
for reserved in reservedDict:
a = filter(None, reservedDict[reserved]) # remove empty elements
- reformattedVals = ':'.join(a)
+ a = [ os.path.realpath(x) for x in a ]
+ reformattedVals = os.pathsep.join(a)
self.addToVariable(reserved, reformattedVals)
pass
self.setVariable(key, val, overwrite=True)
pass
- sys.path[:0] = os.getenv('PYTHONPATH','').split(':')
+ pythonpath = os.getenv('PYTHONPATH','').split(os.pathsep)
+ pythonpath = [ os.path.realpath(x) for x in pythonpath ]
+ sys.path[:0] = pythonpath
#
- def _runAppli(self, args=[]):
+ def _runAppli(self, args=None):
+ if args is None:
+ args = []
# Initialize SALOME environment
sys.argv = ['runSalome'] + args
import setenv
runSalome.runSalome()
#
- def _runSession(self, args=[]):
+ def _runSession(self, args=None):
+ if args is None:
+ args = []
sys.argv = ['runSession'] + args
import runSession
- runSession.configureSession(args)
+ params, args = runSession.configureSession(args)
+ sys.argv = ['runSession'] + args
import setenv
setenv.main(True)
- scriptArgs = getScriptsAndArgs(args)
- command = formatScriptsAndArgs(scriptArgs)
- if command:
- sep = ";"
- if sys.platform == "win32":
- sep= "&"
- command = command.split(sep)
- outmsg = []
- errmsg = []
- for cmd in command:
- save_cmd = cmd
- cmd = cmd.strip().split(' ')
- #proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- proc = subprocess.Popen(cmd)
- (stdoutdata, stderrdata) = proc.communicate()
- if stdoutdata:
- outmsg.append(stdoutdata)
- if stderrdata:
- errmsg.append(stderrdata)
-
- if proc.returncode != 0:
- errmsg.append("Error raised when executing command: %s\n"%save_cmd)
- if outmsg:
- sys.stdout.write("".join(outmsg))
- if errmsg:
- sys.stderr.write("".join(errmsg))
- sys.exit(proc.returncode)
-
- return ("".join(outmsg), "".join(errmsg))
- else:
- absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','')
- cmd = ["/bin/bash", "--rcfile", absoluteAppliPath + "/.bashrc" ]
- proc = subprocess.Popen(cmd, shell=False, close_fds=True)
- return proc.communicate()
+ return runSession.runSession(params, args)
#
- def _runConsole(self, args=[]):
+ def _runConsole(self, args=None):
+ if args is None:
+ args = []
# Initialize SALOME environment
sys.argv = ['runConsole'] + args
import setenv
return proc.communicate()
#
- def _killAll(self, args=[]):
+ def _killAll(self, args=None):
+ if args is None:
+ args = []
try:
import PortManager # mandatory
from multiprocessing import Process
#
- def _showInfo(self, args=[]):
+ def _showInfo(self, args=None):
print "Running with python", platform.python_version()
self._runAppli(["--version"])
#
- def _usage(self, unused=[]):
+ def _usage(self, unused=None):
usage()
#
- def _makeCoffee(self, args=[]):
+ def _makeCoffee(self, args=None):
print " ("
print " ) ("
print " ___...(-------)-....___"
return self._logger
#
-import pickle
if __name__ == "__main__":
if len(sys.argv) == 3:
context = pickle.loads(sys.argv[1])