X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=bin%2FparseConfigFile.py;h=8dd21189f503699cf8dfeb19684368826df8c46d;hb=e4488c5a0468729a713071c7080b400a4465dab9;hp=8085055610ba597526bd8b324b7c253918cb659a;hpb=08f917e721f569bc071a0e8ccc9ba4e8262c1eb2;p=modules%2Fkernel.git diff --git a/bin/parseConfigFile.py b/bin/parseConfigFile.py index 808505561..8dd21189f 100644 --- a/bin/parseConfigFile.py +++ b/bin/parseConfigFile.py @@ -138,10 +138,10 @@ def parseConfigFile(filename, reserved = []): logConfigParser.error("No section found in file: %s"%(filename)) return [] - return _processConfigFile(config, reserved) + return __processConfigFile(config, reserved, filename) # -def _processConfigFile(config, reserved = []): +def __processConfigFile(config, reserved = [], filename="UNKNOWN FILENAME"): # :TODO: may detect duplicated variables in the same section (raise a warning) # or even duplicate sections @@ -208,7 +208,8 @@ class EnvFileConverter(object): self.outputFile = outputFile self.allParsedVariableNames=[] # exclude line that begin with: - self.exclude = [ 'if', 'then', 'fi', '#', 'echo' ] + self.exclude = [ 'if', 'then', 'else', 'fi', '#', 'echo' ] + self.exclude.append('$gconfTool') # QUICK FIX :TODO: provide method to extend this variable # discard the following keywords if at the beginning of line: self.discard = [ 'export' ] # the following keywords imply a special processing if at the beginning of line: @@ -250,12 +251,38 @@ class EnvFileConverter(object): value = self._purgeValue(value, k) line = ADD_TO_PREFIX + k + ": " + value # Update list of variable names + # :TODO: define excludeBlock variable (similar to exclude) and provide method to extend it + if "cleandup()" in line: + print "WARNING: parseConfigFile.py: skip cleandup and look for '# PRODUCT environment'" + while True: + line = self.fp.readline() + if "# PRODUCT environment" in line: + print "WARNING: parseConfigFile.py: '# PRODUCT environment' found" + break + while "clean " in line[0:6]: #skip clean calls with ending ";" crash + line = self.fp.readline() + # Extract variable=value if "=" in line: - variable, value = line.split('=') + try: + variable, value = line.split('=') + except: #avoid error for complicated sh line xx=`...=...`, but warning + print "WARNING: parseConfigFile.py: line with multiples '=' character are hazardous: '"+line+"'" + variable, value = line.split('=',1) + pass + + # Self-extending variables that are not in reserved keywords + # Example: FOO=something:${FOO} + # In this case, remove the ${FOO} in value + if variable in value: + value = self._purgeValue(value, variable) + line = "%s=%s"%(variable,value) + self.allParsedVariableNames.append(variable) - # Self-extending variables that are not in reserved keywords - # Example: FOO=something:${FOO} - # :TODO: + # End of extraction + + if not line: + return line + # # replace "${FOO}" and "$FOO" and ${FOO} and $FOO by %(FOO)s if FOO is # defined in current file (i.e. it is not an external environment variable) @@ -263,10 +290,16 @@ class EnvFileConverter(object): key = r'\$\{?'+k+'\}?' pattern = re.compile(key, re.VERBOSE) line = pattern.sub(r'%('+k+')s', line) - # Remove quotes - pattern = re.compile(r'\"', re.VERBOSE) - line = pattern.sub(r'', line) + # Remove quotes (if line does not contain whitespaces) + try: + variable, value = line.split('=', 1) + except ValueError: + variable, value = line.split(':', 1) + if not ' ' in value.strip(): + pattern = re.compile(r'\"', re.VERBOSE) + line = pattern.sub(r'', line) # + # Replace `shell_command` by its result def myrep(obj): obj = re.sub('`', r'', obj.group(0)) # remove quotes @@ -294,9 +327,8 @@ class EnvFileConverter(object): # # Convert .sh environment file to configuration file format -def convertEnvFileToConfigFile(envFilename, configFilename): - #reserved=['PATH', 'LD_LIBRARY_PATH', 'PYTHONPATH'] - reserved=['PATH', 'LD_LIBRARY_PATH', 'PYTHONPATH', 'MANPATH', 'R_LIBS', 'PV_PLUGIN_PATH'] +def convertEnvFileToConfigFile(envFilename, configFilename, reserved=[]): + logConfigParser.debug('convert env file %s to %s'%(envFilename, configFilename)) fileContents = open(envFilename, 'r').read() pattern = re.compile('\n[\n]+', re.VERBOSE) # multiple '\n'