From f5fde70f0be74dc0472a7d7dc4d9752b178cd565 Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 28 Sep 2007 12:11:43 +0000 Subject: [PATCH] Fix a long-standing problem with passing wrong values to the --standalone or --embedded parameters. Improve --standalone & -embedded parameters processing (XML and command line) --- bin/envSalome.py | 9 +-- bin/launchConfigureParser.py | 117 ++++++++++++++++++++++++++++------- bin/runSalome | 6 +- bin/setenv.py | 4 +- 4 files changed, 104 insertions(+), 32 deletions(-) diff --git a/bin/envSalome.py b/bin/envSalome.py index 9ea098c10..1d0d61cb6 100755 --- a/bin/envSalome.py +++ b/bin/envSalome.py @@ -29,14 +29,15 @@ sys.path[:0]=[kernel_root+"/bin/salome"] #import runSalome argv = sys.argv[1:] +sys.argv = argv[1:] #sys.argv = [sys.argv[0]] #if len(argv) > 3: # sys.argv += argv[3:] -if len(argv) > 2: - sys.argv = argv[2:] - -args, modules_list, modules_root_dir = setenv.get_config() +#if len(argv) > 2: +# sys.argv = argv[2:] + +#args, modules_list, modules_root_dir = setenv.get_config() #runSalome.set_env(args, modules_list, modules_root_dir) setenv.main(); diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index f28a115be..bfe414300 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -61,6 +61,10 @@ port_nam = "port" salomeappname = "SalomeApp" script_nam = "pyscript" +# possible choices for the "embedded" and "standalone" parameters +embedded_choices = [ "registry", "study", "moduleCatalog", "cppContainer", "SalomeAppEngine" ] +standalone_choices = [ "registry", "study", "moduleCatalog", "cppContainer", "pyContainer", "supervContainer"] + # values of boolean type (must be '0' or '1'). # xml_parser.boolValue() is used for correct setting boolKeys = ( gui_nam, splash_nam, logger_nam, file_nam, xterm_nam, portkill_nam, killall_nam, except_nam, pinter_nam ) @@ -173,6 +177,23 @@ def setVerbose(level): _verbose = level return +# -- + +def process_containers_params( standalone, embedded ): + # 1. filter inappropriate containers names + if standalone is not None: + standalone = filter( lambda x: x in standalone_choices, standalone ) + if embedded is not None: + embedded = filter( lambda x: x in embedded_choices, embedded ) + + # 2. remove containers appearing in 'standalone' parameter from the 'embedded' + # parameter --> i.e. 'standalone' parameter has higher priority + if standalone is not None and embedded is not None: + embedded = filter( lambda x: x not in standalone, embedded ) + + # 3. return corrected parameters values + return standalone, embedded + # ----------------------------------------------------------------------------- ### @@ -190,6 +211,12 @@ class xml_parser: parser = xml.sax.make_parser() parser.setContentHandler(self) parser.parse(fileName) + standalone, embedded = process_containers_params( self.opts.get( standalone_nam ), + self.opts.get( embedded_nam ) ) + if standalone is not None: + self.opts[ standalone_nam ] = standalone + if embedded is not None: + self.opts[ embedded_nam ] = embedded pass def boolValue( self, str ): @@ -253,11 +280,11 @@ class xml_parser: if nam in boolKeys: self.opts[key] = self.boolValue( val ) # assign boolean value: 0 or 1 elif nam in intKeys: - self.opts[key] = self.intValue( val ) # assign integer value + self.opts[key] = self.intValue( val ) # assign integer value elif nam in listKeys: - self.opts[key] = val.split( ',' ) # assign list value: [] + self.opts[key] = filter( lambda a: a.strip(), re.split( "[:;,]", val ) ) # assign list value: [] else: - self.opts[key] = val; + self.opts[key] = val pass pass @@ -292,6 +319,54 @@ booleans = { '1': True , 'yes': True , 'y': True , 'on' : True , 'true' : True , boolean_choices = booleans.keys() +def check_embedded(option, opt, value, parser): + from optparse import OptionValueError + assert value is not None + if parser.values.embedded: + embedded = filter( lambda a: a.strip(), re.split( "[:;,]", parser.values.embedded ) ) + else: + embedded = [] + if parser.values.standalone: + standalone = filter( lambda a: a.strip(), re.split( "[:;,]", parser.values.standalone ) ) + else: + standalone = [] + vals = filter( lambda a: a.strip(), re.split( "[:;,]", value ) ) + for v in vals: + if v not in embedded_choices: + raise OptionValueError( "option %s: invalid choice: %r (choose from %s)" % ( opt, v, ", ".join( map( repr, embedded_choices ) ) ) ) + if v not in embedded: + embedded.append( v ) + if v in standalone: + del standalone[ standalone.index( v ) ] + pass + parser.values.embedded = ",".join( embedded ) + parser.values.standalone = ",".join( standalone ) + pass + +def check_standalone(option, opt, value, parser): + from optparse import OptionValueError + assert value is not None + if parser.values.embedded: + embedded = filter( lambda a: a.strip(), re.split( "[:;,]", parser.values.embedded ) ) + else: + embedded = [] + if parser.values.standalone: + standalone = filter( lambda a: a.strip(), re.split( "[:;,]", parser.values.standalone ) ) + else: + standalone = [] + vals = filter( lambda a: a.strip(), re.split( "[:;,]", value ) ) + for v in vals: + if v not in standalone_choices: + raise OptionValueError( "option %s: invalid choice: %r (choose from %s)" % ( opt, v, ", ".join( map( repr, standalone_choices ) ) ) ) + if v not in standalone: + standalone.append( v ) + if v in embedded: + del embedded[ embedded.index( v ) ] + pass + parser.values.embedded = ",".join( embedded ) + parser.values.standalone = ",".join( standalone ) + pass + def store_boolean (option, opt, value, parser, *args): if isinstance(value, types.StringType): try: @@ -404,26 +479,28 @@ def CreateOptionParser (theAdditionalOptions=[]): # Embedded servers. Default: Like in configuration files. help_str = "CORBA servers to be launched in the Session embedded mode. " - help_str += "Valid values for : registry, study, moduleCatalog, " - help_str += "cppContainer [by default the value from the configuration files is used]" + help_str += "Valid values for : %s " % ", ".join( embedded_choices ) + help_str += "[by default the value from the configuration files is used]" o_e = optparse.Option("-e", "--embedded", metavar="", type="string", - action="append", + action="callback", dest="embedded", + callback=check_embedded, help=help_str) # Standalone servers. Default: Like in configuration files. help_str = "CORBA servers to be launched in the standalone mode (as separate processes). " - help_str += "Valid values for : registry, study, moduleCatalog, " - help_str += "cppContainer, pyContainer, [by default the value from the configuration files is used]" + help_str += "Valid values for : %s " % ", ".join( standalone_choices ) + help_str += "[by default the value from the configuration files is used]" o_s = optparse.Option("-s", "--standalone", metavar="", type="string", - action="append", + action="callback", dest="standalone", + callback=check_standalone, help=help_str) # Kill with port. Default: False. @@ -747,21 +824,19 @@ def get_env(theAdditionalOptions=[], appname="SalomeApp"): # Embedded if cmd_opts.embedded is not None: - args[embedded_nam] = [] - listlist = cmd_opts.embedded - for listi in listlist: - args[embedded_nam] += re.split( "[:;,]", listi) + args[embedded_nam] = filter( lambda a: a.strip(), re.split( "[:;,]", cmd_opts.embedded ) ) # Standalone if cmd_opts.standalone is not None: - args[standalone_nam] = [] - listlist = cmd_opts.standalone - standalone = [] - for listi in listlist: - standalone += re.split( "[:;,]", listi) - for serv in standalone: - if args[embedded_nam].count(serv) <= 0: - args[standalone_nam].append(serv) + args[standalone_nam] = filter( lambda a: a.strip(), re.split( "[:;,]", cmd_opts.standalone ) ) + + # Normalize the '--standalone' and '--embedded' parameters + standalone, embedded = process_containers_params( args.get( standalone_nam ), + args.get( embedded_nam ) ) + if standalone is not None: + args[ standalone_nam ] = standalone + if embedded is not None: + args[ embedded_nam ] = embedded # Kill if cmd_opts.portkill is not None: args[portkill_nam] = cmd_opts.portkill diff --git a/bin/runSalome b/bin/runSalome index 3b364115a..abc4c763b 100755 --- a/bin/runSalome +++ b/bin/runSalome @@ -1,10 +1,6 @@ #!/bin/bash -if [ $# -ne 0 ] ; then - ${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py $* -else - python ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py -fi +${KERNEL_ROOT_DIR}/bin/salome/envSalome.py python ${KERNEL_ROOT_DIR}/bin/salome/runSalome.py $* # ----------------------------------------------------------------------------- # examples: diff --git a/bin/setenv.py b/bin/setenv.py index a30b6d95d..35ac2ad4c 100755 --- a/bin/setenv.py +++ b/bin/setenv.py @@ -145,8 +145,8 @@ def get_config(): modules_list.remove("GUI") pass - if "SUPERV" in modules_list and not 'superv' in args['standalone']: - args['standalone'].append("superv") + if "SUPERV" in modules_list and not 'supervContainer' in args['standalone']: + args['standalone'].append("supervContainer") pass return args, modules_list, modules_root_dir -- 2.39.2