From 437666456efe3d3088838855989bc9f876531d98 Mon Sep 17 00:00:00 2001 From: emkael Date: Tue, 1 Aug 2017 01:35:43 +0200 Subject: Error handling in interactive mode does not abort key input confirmation --- jfr_playoff/settings.py | 15 +++++++++------ playoff.py | 23 ++++++++++++++--------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/jfr_playoff/settings.py b/jfr_playoff/settings.py index dd7399d..d81d8a8 100644 --- a/jfr_playoff/settings.py +++ b/jfr_playoff/settings.py @@ -7,24 +7,27 @@ class PlayoffSettings: def __init__(self): self.interactive = False + self.settings_file = None if len(sys.argv) > 1: - settings_file = sys.argv[1] + self.settings_file = sys.argv[1] else: self.interactive = True + + def load(self): + if self.settings_file is None: readline.set_completer_delims(' \t\n;') readline.parse_and_bind("tab: complete") readline.set_completer(complete_filename) - settings_file = raw_input('JSON settings file: ') - - if not os.path.exists(settings_file): - raise IOError('Settings file %s not found' % settings_file) + self.settings_file = raw_input('JSON settings file: ') - self.settings = json.load(open(settings_file)) + self.settings = json.load(open(self.settings_file)) def has_section(self, key): + self.load() return key in self.settings def get(self, *keys): + self.load() section = self.settings for key in keys: section = section[key] diff --git a/playoff.py b/playoff.py index b04cade..59038f8 100644 --- a/playoff.py +++ b/playoff.py @@ -1,20 +1,25 @@ +import traceback from jfr_playoff.settings import PlayoffSettings from jfr_playoff.generator import PlayoffGenerator from jfr_playoff.filemanager import PlayoffFileManager def main(): - s = PlayoffSettings() - generator = PlayoffGenerator(s) - content = generator.generate_content() + try: + s = PlayoffSettings() - file_manager = PlayoffFileManager(s) - file_manager.write_content(content) - file_manager.copy_scripts() - file_manager.send_files() + generator = PlayoffGenerator(s) + content = generator.generate_content() - if s.interactive: - raw_input('Press any key to continue...') + file_manager = PlayoffFileManager(s) + file_manager.write_content(content) + file_manager.copy_scripts() + file_manager.send_files() + except: + print traceback.format_exc() + finally: + if s.interactive: + raw_input('Press any key to continue...') if __name__ == '__main__': main() -- cgit v1.2.3