portkill_nam = "portkill"
killall_nam = "killall"
modules_nam = "modules"
-pyModules_nam = "pyModules"
embedded_nam = "embedded"
standalone_nam = "standalone"
containers_nam = "containers"
if match :
return match.group( 1 )
return ''
-
+
+# calculate and return configuration file id in order to unically identify it
+# for example: for 3.1.0a1 the id is 301000101
+def version_id( fname ):
+ vers = fname.split(".")
+ major = int(vers[0])
+ minor = int(vers[1])
+ mr = re.search(r'^([0-9]+)([A-Za-z]?)([0-9]*)',vers[2])
+ release = dev = 0
+ if mr:
+ release = int(mr.group(1))
+ dev1 = dev2 = 0
+ if len(mr.group(2)): dev1 = ord(mr.group(2))
+ if len(mr.group(3)): dev2 = int(mr.group(3))
+ dev = dev1 * 100 + dev2
+ ver = major
+ ver = ver * 100 + minor
+ ver = ver * 100 + release
+ ver = ver * 10000 + dev
+ return ver
+
+# get user configuration file name
+def userFile():
+ v = version()
+ if not v:
+ return "" # not unknown version
+ filename = "%s/.%src.%s" % (os.environ['HOME'], appname, v)
+ if os.path.exists(filename):
+ return filename # user preferences file for the current version exists
+ # initial id
+ id0 = version_id( v )
+ # get all existing user preferences files
+ files = glob.glob( os.environ['HOME'] + "/." + appname + "rc.*" )
+ f2v = {}
+ for file in files:
+ match = re.search( r'\.%src\.([a-zA-Z0-9.]+)$'%appname, file )
+ if match: f2v[file] = match.group(1)
+ last_file = ""
+ last_version = 0
+ for file in f2v:
+ ver = version_id( f2v[file] )
+ if abs(last_version-id0) > abs(ver-id0):
+ last_version = ver
+ last_file = file
+ return last_file
+
# -----------------------------------------------------------------------------
### xml reader for launch configuration file usage
class xml_parser:
def __init__(self, fileName, _opts ):
- print "Processing ",fileName
+ print "Configure parser: processing %s ..." % fileName
self.space = []
self.opts = _opts
self.section = section_to_skip
config_var = appname+'Config'
# set resources variables if not yet set
if os.getenv("GUI_ROOT_DIR"):
- if not os.getenv("SUITRoot"): os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome"
- if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources"
+ if not os.getenv("SUITRoot"):
+ os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome"
+ if not os.getenv(config_var):
+ os.environ[config_var] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources"
pass
else :
if not os.getenv("SUITRoot"):
os.environ["SUITRoot"] = ""
- if not os.getenv("SalomeAppConfig"):
- os.environ["SalomeAppConfig"] = ""
+ if not os.getenv(config_var):
+ os.environ[config_var] = ""
dirs = os.environ[config_var]
dirs = re.split('[;|:]', dirs )
p = xml_parser(filename, _opts)
_opts = p.opts
except:
- print 'Can not read launch configuration file ', filename
+ print "Configure parser: Error : can not read configuration file %s" % filename
continue
# SalomeApprc file in user's catalogue
-filename = os.environ['HOME']+'/.'+appname+'rc.'+version()
+filename = userFile()
try:
p = xml_parser(filename, _opts)
_opts = p.opts
except:
- print 'Can not read launch configuration file ', filename
-
+ print 'Configure parser: Error : can not read user configuration file'
args = _opts
list = []
pass
- #print "source=",source
-
result = {}
i = 0
while i < len(source):
cmd_opts = {}
try:
cmd_opts = options_parser(sys.argv[1:])
- #print "opts=",cmd_opts
kernel_root_dir=os.environ["KERNEL_ROOT_DIR"]
except:
cmd_opts["h"] = 1
opterror=0
for opt in cmd_opts:
if not opt in ("h","g","l","f","x","m","e","s","c","p","k","t","i","r"):
- print "command line error: -", opt
+ print "Configure parser: Error : command line error : -%s" % opt
opterror=1
if opterror == 1:
pass
pass
+# if --modules (-m) command line option is not given
+# try SALOME_MODULES environment variable
+if not cmd_opts.has_key( "m" ) and os.getenv( "SALOME_MODULES" ):
+ args[modules_nam] = re.split( "[:;,]", os.getenv( "SALOME_MODULES" ) )
+ pass
+
# 'terminal' must be processed in the end: to deny any 'gui' options
if 't' in cmd_opts:
args[gui_nam] = 0
pass
-#print "args=",args
+# now modify SalomeAppConfig environment variable
+dirs = re.split('[;|:]', os.environ[config_var] )
+for m in args[modules_nam]:
+ if m not in ["KERNEL", "GUI", ""] and os.getenv("%s_ROOT_DIR"%m):
+ dirs.append( os.getenv("%s_ROOT_DIR"%m) + "/share/salome/resources" )
+os.environ[config_var] = ":".join(dirs)