def tearDown(self):
pass
#
- def appli(self, args=[]):
+ def appli(self, args=None):
+ if args is None:
+ args = []
try:
self.SALOME.main(self.SALOME_appli_args + args)
except SystemExit, e:
logging.error(e)
pass
#
- def session(self, args=[]):
+ def session(self, args=None):
+ if args is None:
+ args = []
try:
self.SALOME.main(self.SALOME_shell_args + args)
except SystemExit, e:
def tearDown(self):
self.removeLogFile()
#
- def session(self, args=[]):
+ def session(self, args=None):
+ if args is None:
+ args = []
try:
self.SALOME.main(self.SALOME_args + args)
except SystemExit, e:
import sys
import logging
-def getLogger(args=[]):
+def getLogger(args=None):
+ if args is None:
+ args = []
outfileOptionPrefix = "outfile="
outfileArgs = [ str(x) for x in args if str(x).startswith(outfileOptionPrefix) ]
allFiles = [ x.replace(outfileOptionPrefix, '') for x in outfileArgs ]
for attribute in args:
setattr(parser.values, attribute, value)
-def CreateOptionParser (theAdditionalOptions=[]):
+def CreateOptionParser (theAdditionalOptions=None):
+ if theAdditionalOptions is None:
+ theAdditionalOptions = []
# GUI/Terminal. Default: GUI
help_str = "Launch without GUI (in the terminal mode)."
o_t = optparse.Option("-t",
args = {}
#def get_env():
#args = []
-def get_env(theAdditionalOptions=[], appname=salomeappname, cfgname=salomecfgname):
+def get_env(theAdditionalOptions=None, appname=salomeappname, cfgname=salomecfgname):
###
# Collect launch configuration files:
# - The environment variable "<appname>Config" (SalomeAppConfig) which can
# specified in configuration file(s)
###
+ if theAdditionalOptions is None:
+ theAdditionalOptions = []
+
global args
config_var = appname+'Config'
separator = ";"
# check KERNEL_ROOT_DIR
- try:
- kernel_root_dir=os.environ["KERNEL_ROOT_DIR"]
- except:
+ kernel_root_dir = os.environ.get("KERNEL_ROOT_DIR", None)
+ if kernel_root_dir is None:
print """
For each SALOME module, the environment variable <moduleN>_ROOT_DIR must be set.
KERNEL_ROOT_DIR is mandatory.
"""
sys.exit(1)
- pass
############################
# parse command line options
# set default values for options which are NOT set in config files
for aKey in listKeys:
if not args.has_key( aKey ):
- args[aKey]=[]
+ args[aKey] = []
for aKey in boolKeys:
if not args.has_key( aKey ):
- args[aKey]=0
+ args[aKey] = 0
if args[file_nam]:
afile=args[file_nam]
- args[file_nam]=[afile]
+ args[file_nam] = [afile]
args[appname_nam] = appname
# Input: filename, and a list of reserved keywords (environment variables)
# Output: a list of pairs (variable, value), and a dictionary associating a list of user-defined values to each reserved keywords
# Note: Does not support duplicate keys in a same section
-def parseConfigFile(filename, reserved = []):
+def parseConfigFile(filename, reserved = None):
+ if reserved is None:
+ reserved = []
config = MultiOptSafeConfigParser()
config.optionxform = str # case sensitive
raise SalomeContextException(msg)
#
-def __processConfigFile(config, reserved = [], filename="UNKNOWN FILENAME"):
+def __processConfigFile(config, reserved = None, filename="UNKNOWN FILENAME"):
# :TODO: may detect duplicated variables in the same section (raise a warning)
# or even duplicate sections
+ if reserved is None:
+ reserved = []
unsetVariables = []
outputVariables = []
# Get raw items for each section, and make some processing for environment variables management
# - virtually add a section to configuration file
# - process shell keywords (if, then...)
class EnvFileConverter(object):
- def __init__(self, fp, section_name, reserved = [], outputFile=None):
+ def __init__(self, fp, section_name, reserved = None, outputFile=None):
+ if reserved is None:
+ reserved = []
self.fp = fp
self.sechead = '[' + section_name + ']\n'
self.reserved = reserved
self.outputFile = outputFile
- self.allParsedVariableNames=[]
+ self.allParsedVariableNames = []
# exclude line that begin with:
self.exclude = [ 'if', 'then', 'else', 'fi', '#', 'echo', 'exit' ]
self.exclude.append('$gconfTool') # QUICK FIX :TODO: provide method to extend this variable
#
# Convert .sh environment file to configuration file format
-def convertEnvFileToConfigFile(envFilename, configFilename, reserved=[]):
+def convertEnvFileToConfigFile(envFilename, configFilename, reserved=None):
+ if reserved is None:
+ reserved = []
logConfigParser.debug('convert env file %s to %s'%(envFilename, configFilename))
fileContents = open(envFilename, 'r').read()
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-def __prompt(environment = None, commands=[], message = "Connecting to SALOME"):
+def __prompt(environment = None, commands=None, message = "Connecting to SALOME"):
if environment is None:
environment = globals().copy()
environment.update(locals())
+ if commands is None:
+ commands = []
import code
import rlcompleter
return shell.interact
#
-def connect(args=[]):
+def connect(args=None):
+ if args is None:
+ args = []
p = __prompt(commands=["import salomeConsole"])
p()
#
return self.epilog
#
-def configureSession(args=[]):
+def configureSession(args=None):
+ if args is None:
+ args = []
usage = "Usage: %prog [options] [command]"
epilog = """\n
If the command is not given a shell is opened; else execute the given command.
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")
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:
sys.path[:0] = os.getenv('PYTHONPATH','').split(':')
#
- 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)
return runSession.runSession(command)
#
- 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])
#
# Return an array of dictionaries {script_name: [list_of_its_args]}
-def getScriptsAndArgs(args=[], searchPathList=None):
+def getScriptsAndArgs(args=None, searchPathList=None):
+ if args is None:
+ args = []
if searchPathList is None:
searchPathList = sys.path
# Formatting scripts and args as a Bash-like command-line:
# script1.py [args] ; script2.py [args] ; ...
-def formatScriptsAndArgs(scriptArgs=[]):
+def formatScriptsAndArgs(scriptArgs=None):
+ if scriptArgs is None:
+ scriptArgs = []
commands = []
for sc_dict in scriptArgs:
for script, sc_args in sc_dict.items(): # single entry
_session = None
-def startSession(modules=[]):
+def startSession(modules=None):
+ if modules is None:
+ modules = []
global _session
if _session: return
from searchFreePort import searchFreePort
\section salome_api The API
An API named \c SalomeContext, written in Python, allows for the construction of SALOME execution context and for application start. Each launcher creates a \c SalomeContext object, and optionally gives it a list of configuration files to describe the context:
\code
-SalomeContext.__init__(configFileNames=[])
+SalomeContext.__init__(configFileNames=None)
\endcode
A launcher can also directly call the API functions to define, suppress or extend (add information) an environment variable:
#-------------------------------------------------------------------------
def importData(self, studyId, dataContainer, options):
- return [] # no implmenetation by default
+ return [] # no implementation by default
#-------------------------------------------------------------------------
def getModifiedData(self, studyId):
- return [] # no implmenetation by default
+ return [] # no implementation by default
pass # end of SALOME_ComponentPy_i
a dictionary which can lookup value by key, or keys by value
"""
## items can be a list of pair_lists or a dictionary
- def __init__(self, items=[]):
+ def __init__(self, items=None):
"""items can be a list of pair_lists or a dictionary"""
+ if items is None:
+ items = []
dict.__init__(self, items)
## find the key(s) as a list given a value
its name. Other attributes are reserved for future use.
"""
- def __init__(self, name, dimension = [], minValue = None, maxValue = None,
+ def __init__(self, name, dimension = None, minValue = None, maxValue = None,
initialValue = None):
+ if dimension is None:
+ dimension = []
self.name = name
# Reserved for future use
"""
- def __init__(self, inputVarList = [], outputVarList = [],
+ def __init__(self, inputVarList = None, outputVarList = None,
refEntry = None):
+ if inputVarList is None:
+ inputVarList = []
+ if outputVarList is None:
+ outputVarList = []
self.inputVarList = inputVarList
self.outputVarList = outputVarList
self.refEntry = refEntry
__date__ ="$21 mai 2010 18:00:23$"
-def findFiles(rootpath, excludes=[]):
+def findFiles(rootpath, excludes=None):
"""
This looks after files recursively from the specified rootpath,
but without visiting directories whose basename is in the list
if not os.path.exists(rootpath):
raise RuntimeError("the path %s does not exists"%rootpath)
+ if excludes is None:
+ excludes = []
exclude_options=""
for excludepath in excludes:
exclude_options+="-e %s "%excludepath
Engines.ContainerParameters.__init__(self,container_name, mode, workingdir, nb_proc, isMPI, parallelLib,resource_params)
class ResourceParameters (Engines.ResourceParameters):
- def __init__(self, name="", hostname="", OS="", componentList=[],
+ def __init__(self, name="", hostname="", OS="", componentList=None,
nb_proc=0, mem_mb=0, cpu_clock=0, nb_node=0, nb_proc_per_node=0,
- policy="", resList=[], can_launch_batch_jobs = False, can_run_containers = False):
+ policy="", resList=None, can_launch_batch_jobs = False, can_run_containers = False):
+ if componentList is None:
+ componentList = []
+ if resList is None:
+ resList = []
Engines.ResourceParameters.__init__(self, name, hostname, can_launch_batch_jobs, can_run_containers,
OS, componentList, nb_proc, mem_mb, cpu_clock, nb_node,
nb_proc_per_node, policy, resList)
class JobParameters (Engines.JobParameters):
- def __init__(self, job_name="", job_type="", job_file="", env_file="", in_files=[], out_files=[],
+ def __init__(self, job_name="", job_type="", job_file="", env_file="", in_files=None, out_files=None,
work_directory="", local_directory="", result_directory="", maximum_duration="",
resource_required=None, queue="", exclusive = False, mem_per_cpu = 0,
- specific_parameters=[], launcher_file = "", launcher_args = ""):
+ specific_parameters=None, launcher_file = "", launcher_args = ""):
+ if in_files is None:
+ in_files = []
+ if out_files is None:
+ out_files = []
+ if specific_parameters is None:
+ specific_parameters = []
Engines.JobParameters.__init__(self, job_name, job_type, job_file, env_file, in_files, out_files,
work_directory, local_directory, result_directory, maximum_duration,
resource_required, queue, exclusive, mem_per_cpu,
specific_parameters, launcher_file, launcher_args)
class ResourceDefinition(Engines.ResourceDefinition):
- def __init__(self, name="", hostname="", protocol="rsh", username="", applipath="", componentList=[],
+ def __init__(self, name="", hostname="", protocol="rsh", username="", applipath="", componentList=None,
mode="interactive", OS="", mem_mb=1, cpu_clock=1, nb_node=1, nb_proc_per_node=1,
batch="", mpiImpl="", iprotocol="rsh", type = "single_machine",
can_launch_batch_jobs = False, can_run_containers = False, working_directory = ""):
+ if componentList is None:
+ componentList = []
Engines.ResourceDefinition.__init__(self, name, hostname, type, protocol, username, applipath,
componentList, OS, mem_mb, cpu_clock, nb_node, nb_proc_per_node,
batch, mpiImpl, iprotocol, can_launch_batch_jobs,