Commands:
=========
start Starts a SALOME session (through virtual application)
- shell Initializes SALOME environment, and executes scripts passed
+ context Initializes SALOME context.
+ shell Initializes SALOME context, and executes scripts passed
as command arguments
connect Connects a Python console to the active SALOME session
killall Kill all SALOME running sessions for current user
--config=<file,folder,...>
==========================
- Initialize SALOME environment from a list of context files and/or a list
+ Initialize SALOME context from a list of context files and/or a list
of folders containing context files. The list is comma-separated, whithout
any blank characters.
'''
#
"""
-The SalomeContext class in an API to configure SALOME environment then
+The SalomeContext class in an API to configure SALOME context then
start SALOME using a single python command.
"""
class SalomeContext:
"""
- Initialize environment from a list of configuration files
+ Initialize context from a list of configuration files
identified by their names.
These files should be in appropriate (new .cfg) format.
However you can give old .sh environment files; in this case,
the SalomeContext class will try to automatically convert them
- to .cfg format before setting the environment.
+ to .cfg format before setting the context.
"""
def __init__(self, configFileNames=0):
#it could be None explicitely (if user use multiples setVariable...for standalone)
for filename in configFileNames:
basename, extension = os.path.splitext(filename)
if extension == ".cfg":
- self.__setEnvironmentFromConfigFile(filename, reserved)
+ self.__setContextFromConfigFile(filename, reserved)
elif extension == ".sh":
#new convert procedures, temporary could be use not to be automatically deleted
#temp = tempfile.NamedTemporaryFile(suffix='.cfg', delete=False)
temp = tempfile.NamedTemporaryFile(suffix='.cfg')
try:
convertEnvFileToConfigFile(filename, temp.name, reserved)
- self.__setEnvironmentFromConfigFile(temp.name, reserved)
+ self.__setContextFromConfigFile(temp.name, reserved)
temp.close()
except (ConfigParser.ParsingError, ValueError) as e:
self.getLogger().error("Invalid token found when parsing file: %s\n"%(filename))
def runSalome(self, args):
import os
# Run this module as a script, in order to use appropriate Python interpreter
- # according to current path (initialized from environment files).
+ # according to current path (initialized from context files).
mpi_module_option = "--with-mpi-module="
mpi_module = [x for x in args if x.startswith(mpi_module_option)]
if mpi_module:
availableCommands = {
'start' : '_runAppli',
+ 'context' : '_setContext',
'shell' : '_runSession',
'connect' : '_runConsole',
'killall': '_killAll',
sys.exit(1)
#
- def __setEnvironmentFromConfigFile(self, filename, reserved=None):
+ def __setContextFromConfigFile(self, filename, reserved=None):
if reserved is None:
reserved = []
try:
temp = tempfile.NamedTemporaryFile(suffix='.cfg')
try:
convertEnvFileToConfigFile(sh_file, temp.name, reserved)
- self.__setEnvironmentFromConfigFile(temp.name, reserved)
+ self.__setContextFromConfigFile(temp.name, reserved)
msg += "OK\n"
self.getLogger().warning(msg)
temp.close()
for var in unsetVars:
self.unsetVariable(var)
- # set environment
+ # set context
for reserved in reservedDict:
a = filter(None, reservedDict[reserved]) # remove empty elements
a = [ os.path.realpath(x) for x in a ]
def _runAppli(self, args=None):
if args is None:
args = []
- # Initialize SALOME environment
+ # Initialize SALOME context
sys.argv = ['runSalome'] + args
import setenv
setenv.main(True)
runSalome.runSalome()
#
+ def _setContext(self, args=None):
+ salome_context_set = os.getenv("SALOME_CONTEXT_SET")
+ if salome_context_set:
+ print "***"
+ print "*** SALOME context has already been set."
+ print "*** Enter 'exit' (only once!) to leave SALOME context."
+ print "***"
+ return
+
+ os.environ["SALOME_CONTEXT_SET"] = "yes"
+ print "***"
+ print "*** SALOME context is now set."
+ print "*** Enter 'exit' (only once!) to leave SALOME context."
+ print "***"
+
+ cmd = ["/bin/bash"]
+ proc = subprocess.Popen(cmd, shell=False, close_fds=True)
+ return proc.communicate()
+ #
+
def _runSession(self, args=None):
if args is None:
args = []
def _runConsole(self, args=None):
if args is None:
args = []
- # Initialize SALOME environment
+ # Initialize SALOME context
sys.argv = ['runConsole'] + args
import setenv
setenv.main(True)