Salome HOME
Deal with ref count server side.
[modules/kernel.git] / bin / parseConfigFile.py
index c6f0825956dc8e8c6f2aeedbf368b9b8fed062c2..3054ed1f341eeb2154d3280befda32627afe1970 100644 (file)
@@ -23,6 +23,7 @@ import logging
 import re
 from io import StringIO
 import subprocess
+from salomeContextUtils import SalomeContextException
 
 logging.basicConfig()
 logConfigParser = logging.getLogger(__name__)
@@ -31,6 +32,17 @@ ADD_TO_PREFIX = 'ADD_TO_'
 UNSET_KEYWORD = 'UNSET'
 
 
+def _expandSystemVariables(key, val):
+  expandedVal = os.path.expandvars(val) # expand environment variables
+  # Search for not expanded variables (i.e. non-existing environment variables)
+  pattern = re.compile('\${ ( [^}]* ) }', re.VERBOSE) # string enclosed in ${ and }
+  expandedVal = pattern.sub(r'', expandedVal) # remove matching patterns
+
+  if not "DLIM8VAR" in key: # special case: DISTENE licence key can contain double clons (::)
+    expandedVal = _trimColons(expandedVal)
+  return expandedVal
+#
+
 # :TRICKY: So ugly solution...
 class MultiOptSafeConfigParser(ConfigParser.SafeConfigParser):
   def __init__(self):
@@ -105,7 +117,8 @@ class MultiOptSafeConfigParser(ConfigParser.SafeConfigParser):
               optval = optval.strip()
               # ADD THESE LINES
               splittedComments = optval.split('#')
-              optval = splittedComments[0].strip().strip("'").strip('"')
+              s = _expandSystemVariables(optname, splittedComments[0])
+              optval = s.strip().strip("'").strip('"')
               #if len(splittedComments) > 1:
               #  optval += " #" + " ".join(splittedComments[1:])
               # END OF ADD
@@ -163,7 +176,11 @@ def parseConfigFile(filename, reserved = []):
     logConfigParser.error("No section found in file: %s"%(filename))
     return []
 
-  return __processConfigFile(config, reserved, filename)
+  try:
+    return __processConfigFile(config, reserved, filename)
+  except ConfigParser.InterpolationMissingOptionError, e:
+    msg = "A variable may be undefined in SALOME context file: %s\nParser error is: %s\n"%(filename, e)
+    raise SalomeContextException(msg)
 #
 
 def __processConfigFile(config, reserved = [], filename="UNKNOWN FILENAME"):
@@ -187,13 +204,7 @@ def __processConfigFile(config, reserved = [], filename="UNKNOWN FILENAME"):
       elif key == UNSET_KEYWORD:
         unsetVariables += val.replace(',', ' ').split()
       else:
-        expandedVal = os.path.expandvars(val) # expand environment variables
-        # Search for not expanded variables (i.e. non-existing environment variables)
-        pattern = re.compile('\${ ( [^}]* ) }', re.VERBOSE) # string enclosed in ${ and }
-        expandedVal = pattern.sub(r'', expandedVal) # remove matching patterns
-        # Trim colons
-        if not "DLIM8VAR" in key: # special case: DISTENE licence key can contain double clons (::)
-          expandedVal = _trimColons(expandedVal)
+        expandedVal = _expandSystemVariables(key, val)
 
         if key in reservedKeys:
           shortKey = key[len(ADD_TO_PREFIX):]