diff options
author | emkael <emkael@tlen.pl> | 2017-10-02 23:48:02 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2017-10-02 23:48:02 +0200 |
commit | 19caef32a560a4a797fba4ab2fa93bc2b410039b (patch) | |
tree | 6b965e9e3320305517929d4792ec1948c51ec2a4 /jfr_playoff/settings.py | |
parent | 86654dee683d9a2cda00a528b006433cebeebf26 (diff) | |
parent | 40d09a61727d3c960a816def07fb319853a90116 (diff) |
Merge branch 'refactor'
Diffstat (limited to 'jfr_playoff/settings.py')
-rw-r--r-- | jfr_playoff/settings.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/jfr_playoff/settings.py b/jfr_playoff/settings.py new file mode 100644 index 0000000..da92458 --- /dev/null +++ b/jfr_playoff/settings.py @@ -0,0 +1,41 @@ +import glob +import json +import readline +import sys + + +def complete_filename(text, state): + return (glob.glob(text+'*')+[None])[state] + + +class PlayoffSettings(object): + + def __init__(self): + self.settings = None + self.interactive = False + self.settings_file = None + if len(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) + self.settings_file = raw_input('JSON settings file: ') + + if self.settings is None: + 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] + return section |