-def get_config(config_filename=None):
- if config_filename is None:
- config_filename = find_config_file()
- ml_conf = SafeConfigParser()
- ml_conf.read(config_filename)
- return ml_conf
+ def getint(self, section, option, default=0):
+ try:
+ return self.config.getint(section, option)
+ except (NoSectionError, NoOptionError):
+ return default
+ # Do not catch ValueError here, it must be propagated
+
+ def getlist(self, section, option, default=None, sep=None):
+ value = self.get(section, option)
+ if not value:
+ if default is None:
+ return []
+ return default
+ return value.split(sep)
+
+ def getpath(self, section, option, default=os.path.curdir):
+ path = self.get(section, option, default=default)
+ return os.path.expanduser(os.path.expandvars(path))
+
+
+def get_config(config_path=None):
+ global _ml_config
+ if _ml_config is None:
+ _ml_config = RawConfigParser()
+ if config_path is None:
+ config_path = find_config_file()
+ if config_path is not None:
+ _ml_config.read(config_path)
+ _ml_config = ConfigWrapper(_ml_config)
+ return _ml_config