comparison Options.py @ 2:10f1d7de9bc3

New module for reading configurations.
author Tom Fredrik Blenning Klaussen <bfg@blenning.no>
date Sun, 16 Sep 2012 21:29:22 +0200
parents
children
comparison
equal deleted inserted replaced
1:a1224150b8f6 2:10f1d7de9bc3
1 #!/usr/bin/env python -O
2
3 import xml.dom.minidom, sys, re
4
5 class Config:
6 def __init__(self, path):
7 self.document = xml.dom.minidom.parse(path)
8
9 @staticmethod
10 def getOption(node, option, match):
11 for potentialMatch in node.childNodes:
12 if potentialMatch.nodeName == "option":
13 if potentialMatch.hasAttribute('match'):
14 matchstr = potentialMatch.getAttribute('match')
15 try:
16 prog = re.compile(matchstr)
17 except:
18 raise xml.dom.SyntaxErr(matchstr
19 +
20 " is not a valid value for attribute match")
21 if prog.match(match):
22 res = Config.getOption(potentialMatch, option, match)
23 if not res:
24 res = potentialMatch.getAttribute('cxxflags')
25 return res
26 return None
27
28 def getCxxflags(self, name):
29 value = self.getOption(self.document.childNodes[0], 'Cxxflags', name)
30 if not value:
31 raise xml.dom.NotFoundErr()
32 return value