From c1f3544e33bda913bcf38757a2715866afe808ea Mon Sep 17 00:00:00 2001 From: Rohitt Vashishtha Date: Sat, 17 Jun 2017 17:42:58 +0530 Subject: [PATCH] bots: Allow optional config files for bots. --- bots_api/bot_lib.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bots_api/bot_lib.py b/bots_api/bot_lib.py index 35b32e0..65695bb 100644 --- a/bots_api/bot_lib.py +++ b/bots_api/bot_lib.py @@ -100,13 +100,18 @@ class ExternalBotHandler(object): else: self._rate_limit.show_error_and_exit() - def get_config_info(self, bot_name, section=None): - # type: (str, Optional[str]) -> Dict[str, Any] + def get_config_info(self, bot_name, section=None, optional=False): + # type: (str, Optional[str], Optional[bool]) -> Dict[str, Any] conf_file_path = os.path.realpath(os.path.join( our_dir, '..', 'bots', bot_name, bot_name + '.conf')) section = section or bot_name config = configparser.ConfigParser() - config.readfp(open(conf_file_path)) # type: ignore + try: + config.readfp(open(conf_file_path)) # type: ignore + except IOError: + if optional: + return dict() + raise return dict(config.items(section)) class StateHandler(object):