summaryrefslogtreecommitdiff
path: root/jfr_playoff/settings.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-07-31 20:45:13 +0200
committeremkael <emkael@tlen.pl>2017-07-31 20:45:13 +0200
commitbd5fd6a6596dd7625019c6c0f0ff043597cda837 (patch)
tree809a4ae96291a50fbf87e9dded7c946591163297 /jfr_playoff/settings.py
parent85d798ae2eeab73062303f1561c58f23e84d29da (diff)
Renaming module to avoid ambiguity
Diffstat (limited to 'jfr_playoff/settings.py')
-rw-r--r--jfr_playoff/settings.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/jfr_playoff/settings.py b/jfr_playoff/settings.py
new file mode 100644
index 0000000..dd7399d
--- /dev/null
+++ b/jfr_playoff/settings.py
@@ -0,0 +1,31 @@
+import glob, json, os, readline, sys
+
+def complete_filename(text, state):
+ return (glob.glob(text+'*')+[None])[state]
+
+class PlayoffSettings:
+
+ def __init__(self):
+ self.interactive = False
+ if len(sys.argv) > 1:
+ settings_file = sys.argv[1]
+ else:
+ self.interactive = True
+ 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 = json.load(open(settings_file))
+
+ def has_section(self, key):
+ return key in self.settings
+
+ def get(self, *keys):
+ section = self.settings
+ for key in keys:
+ section = section[key]
+ return section