ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/BetterConfigParser.py
Revision: 1.1
Committed: Wed Jun 6 21:21:32 2012 UTC (12 years, 11 months ago) by nmohr
Content type: text/x-python
Branch: MAIN
CVS Tags: hcpApproval, HCP_unblinding, hcpPreApp, hcpPreAppFreeze, ICHEP8TeV, ichep8TeV
Log Message:
Add config parser with replace

File Contents

# User Rev Content
1 nmohr 1.1 import re,ConfigParser
2    
3     class BetterConfigParser(ConfigParser.SafeConfigParser):
4    
5     def get(self, section, option):
6     result = ConfigParser.SafeConfigParser.get(self, section, option, raw=True)
7     result = self.__replaceSectionwideTemplates(result)
8     return result
9    
10     def optionxform(self, optionstr):
11     '''
12     enable case sensitive options in .ini files
13     '''
14     return optionstr
15    
16     def __replaceSectionwideTemplates(self, data):
17     '''
18     replace <section|option> with get(section,option) recursivly
19     '''
20     result = data
21     findExpression = re.compile("((.*)\<!(.*)\|(.*)\!>(.*))*")
22     groups = findExpression.search(data).groups()
23     if not groups == (None, None, None, None, None): # expression not matched
24     result = self.__replaceSectionwideTemplates(groups[1])
25     result += self.get(groups[2], groups[3])
26     result += self.__replaceSectionwideTemplates(groups[4])
27     return result