Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Helper object to identify configuration parameters so we can easily overwrite
them via command line magic or via the steering file
"""
from pprint import pprint
class ConfigHelper( object ):
"""Base class for configuration helper"""
def __init__( self ):
pass
def getOptions(self):
finalVars = {}
# get all direct members not starting with underscore
allVars = vars(self)
for var,val in allVars.iteritems():
if not var.startswith('_'):
finalVars[var] = (val,'')
# now get things defined with @property
props = [(p, getattr(type(self),p)) for p in dir(type(self)) if isinstance(getattr(type(self),p),property)]
for propName, prop in props:
finalVars[propName] = (getattr(self, propName), prop.__doc__)
return finalVars
def printOptions( self ):
"""print all paramters"""
return pprint(self.getOptions())
def setOption( self, name, val ):
""" set the attribute name to val """
setattr(self, name, val)
@staticmethod
def listifyString( stringVal, sep=" "):
"""returns a list from a string separated by sep"""
if isinstance( stringVal, list ):
return stringVal
else:
return stringVal.split(sep)