diff options
author | emkael <emkael@tlen.pl> | 2018-01-26 23:37:43 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2018-01-26 23:37:43 +0100 |
commit | bbc0d27a0bf7d4592e83c834863fba6eabff0b12 (patch) | |
tree | 2ae9ed81bee96e46481d9b328af42f21f35768e9 | |
parent | 5b2f14b41d7b6a79754ddcb1052cf770e76921f7 (diff) |
Ability to merge config from remote URLs
Closes #2
-rw-r--r-- | jfr_playoff/settings.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/jfr_playoff/settings.py b/jfr_playoff/settings.py index ba03d72..a40fd9b 100644 --- a/jfr_playoff/settings.py +++ b/jfr_playoff/settings.py @@ -2,6 +2,7 @@ import glob import json import readline import sys +import urllib def complete_filename(text, state): @@ -20,6 +21,21 @@ class PlayoffSettings(object): else: self.interactive = True + def __merge_config(self, base_config, + new_config=None, remote_url=None, + overwrite=True): + try: + remote_config = new_config if new_config is not None else \ + json.loads(urllib.urlopen( + remote_url).read().decode('utf-8-sig')) + for key, value in remote_config.iteritems(): + if (key not in base_config) or overwrite: + base_config[key] = value + except e: + print 'WARNING: unable to fetch remote config %s: %s' % ( + url, str(e)) + return base_config + def load(self): if self.settings_file is None: readline.set_completer_delims(' \t\n;') @@ -31,6 +47,14 @@ class PlayoffSettings(object): if self.settings is None: self.settings = json.loads( open(unicode(self.settings_file)).read().decode('utf-8-sig')) + if self.has_section('remotes'): + remote_config = {} + for remote in self.get('remotes'): + remote_config = self.__merge_config( + remote_config, remote_url=remote) + self.settings = self.__merge_config( + self.settings, new_config=remote_config, + overwrite=False) def has_section(self, key): self.load() |