Package dimer :: Module config
[hide private]
[frames] | no frames]

Source Code for Module dimer.config

 1  ''' 
 2  module that provides configuration file functionality  
 3  ''' 
 4   
 5   
 6   
 7  import logging, abc 
 8  from ConfigParser import SafeConfigParser 
 9   
10   
11  logging.getLogger(__name__) 
12  log = logging.getLogger() 
13 14 15 -class Configurable( object ):
16 """abstract class with factory method from a config file 17 18 to subclass, need to define 19 20 _types: types for properties 21 _section: section on the confifg file""" 22 23 __metaclass__ = abc.ABCMeta 24
25 - def __init__(self, path):
26 self.cfg = SafeConfigParser() 27 if not len(self.cfg.read([path])): 28 raise ValueError("cannot load %s" % path) 29 log.info("loaded settings from %s", path) 30 self._config_check()
31
32 - def getAttr(self, attr):
33 return self.cfg.get(self._section, attr)
34
35 - def setAttr(self, attr, val):
36 return self.cfg.set(self._section, attr, val)
37 38 @abc.abstractmethod
39 - def _config_check(self):
40 "check as much as you can that values of params make sense" 41 42 raise NotImplemented
43