zulip_bots: Enforce default config file schema.

This requires the bot's config section to be named
after the bot. All config entries must be contained
in this section.
This commit is contained in:
derAnfaenger 2017-11-06 15:13:24 +01:00 committed by showell
parent 1a096b317b
commit e05ce661c5

View file

@ -119,10 +119,9 @@ class ExternalBotHandler(object):
else: else:
self._rate_limit.show_error_and_exit() self._rate_limit.show_error_and_exit()
def get_config_info(self, bot_name, section=None, optional=False): def get_config_info(self, bot_name, optional=False):
# type: (str, Optional[str], Optional[bool]) -> Dict[str, Any] # type: (str, Optional[bool]) -> Dict[str, Any]
conf_file_path = os.path.realpath(os.path.join(self._root_dir, bot_name + '.conf')) conf_file_path = os.path.realpath(os.path.join(self._root_dir, bot_name + '.conf'))
section = section or bot_name
config = configparser.ConfigParser() config = configparser.ConfigParser()
try: try:
with open(conf_file_path) as conf: with open(conf_file_path) as conf:
@ -131,7 +130,7 @@ class ExternalBotHandler(object):
if optional: if optional:
return dict() return dict()
raise raise
return dict(config.items(section)) return dict(config.items(bot_name))
def open(self, filepath): def open(self, filepath):
# type: (str) -> IO[str] # type: (str) -> IO[str]