- return int(self._get_parameter(section, param))
- except ValueError:
- raise ParseError("[%s.%s] not an int" % (section, param))
-
- def _get_bool_parameter(self, section, param):
- result = self._get_parameter(section, param)
- if str(result).lower() == 'true':
- return True
- if str(result).lower() == 'false':
- return False
-
- raise ParseError(
- "[%s.%s : %s] not a boolean" % (section, param, result))
-
- @staticmethod
- def parse(config_location=None):
- obj = APIConfig()
-
- if config_location is None:
- config_location = obj._default_config_location
-
- obj._parser = ConfigParser.SafeConfigParser()
- obj._parser.read(config_location)
- if not obj._parser:
- raise ParseError("%s not found" % config_location)
-
- # Linking attributes to keys from file with their sections
- obj.mongo_url = obj._get_parameter("mongo", "url")
- obj.mongo_dbname = obj._get_parameter("mongo", "dbname")
-
- obj.api_port = obj._get_int_parameter("api", "port")
- obj.api_debug_on = obj._get_bool_parameter("api", "debug")
- obj.api_authenticate_on = obj._get_bool_parameter("api",
- "authenticate")