From 662c7ec12a03e51a5993c0e94a5509476daac2cf Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 6 Jul 2013 10:54:58 +0000 Subject: [PATCH] add default values for missing capabilities and user.ui setting to config.jsonc from config.pandora.jsonc, fixes #1604 --- pandora/app/config.py | 50 ++++++++++++++++++++++--------- pandora/config.0xdb.jsonc | 4 +++ pandora/config.indiancinema.jsonc | 4 +++ pandora/settings.py | 1 + 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/pandora/app/config.py b/pandora/app/config.py index 6a825bfcc..0ad0ad9f4 100644 --- a/pandora/app/config.py +++ b/pandora/app/config.py @@ -39,6 +39,12 @@ def load_config(): except: config = None + with open(settings.DEFAULT_CONFIG) as f: + try: + default = ox.jsonc.load(f) + except: + default = None + if config: settings.SITENAME = config['site']['name'] if getattr(settings, 'SITEURL', False): @@ -56,6 +62,24 @@ def load_config(): for key in config['itemKeys']: config['keys'][key['id']] = key + + #add missing defaults + for section in ('capabilities', 'user.ui', 'user.ui.showFolder'): + parts = map(lambda p: p.replace('\0', '\\.'), section.replace('\\.', '\0').split('.')) + #print 'checking', section + c = config + d = default + while len(parts): + part = parts.pop(0) + if part not in c: + c[part] = {} + c = c[part] + d = d[part] + for key in d: + if key not in c: + print "adding default value for %s.%s" % (section, key), '=', d[key] + c[key] = d[key] + old_formats = getattr(settings, 'CONFIG', {}).get('video', {}).get('formats', []) formats = config.get('video', {}).get('formats') if set(old_formats) != set(formats): @@ -110,20 +134,18 @@ def reloader_thread(): except: INOTIFY = False if INOTIFY: - class ConfigChanges: - def __init__(self): - name = os.path.realpath(settings.SITE_CONFIG) - self.name = name - self.wm = pyinotify.WatchManager() - self.reload_config() - notifier = pyinotify.Notifier(self.wm) - notifier.loop() - - def reload_config(self): - load_config() - self.wm.add_watch(self.name, pyinotify.IN_CLOSE_WRITE, - lambda event: self.reload_config()) - ConfigChanges() + def add_watch(): + name = os.path.realpath(settings.SITE_CONFIG) + wm.add_watch(name, pyinotify.IN_CLOSE_WRITE, reload_config) + + def reload_config(event): + load_config() + add_watch() + + wm = pyinotify.WatchManager() + add_watch() + notifier = pyinotify.Notifier(wm) + notifier.loop() else: while RUN_RELOADER: try: diff --git a/pandora/config.0xdb.jsonc b/pandora/config.0xdb.jsonc index b1ef167eb..b29713ba2 100644 --- a/pandora/config.0xdb.jsonc +++ b/pandora/config.0xdb.jsonc @@ -729,7 +729,9 @@ "level": "guest", "newsletter": true, "ui": { + "annotationsCalendarSize": 128, "annotationsFont": "small", + "annotationsMapSize": 128, "annotationsRange": "all", "annotationsSize": 256, "annotationsSort": "position", @@ -777,6 +779,8 @@ "sequenceSort": [{"key": "director", "operator": "+"}], "showAdvancedEmbedOptions": false, "showAnnotations": true, + "showAnnotationsCalendar": true, + "showAnnotationsMap": true, "showBrowser": true, "showCalendarControls": true, // fixme: should be false "showFilters": true, diff --git a/pandora/config.indiancinema.jsonc b/pandora/config.indiancinema.jsonc index 72fff6b50..df795862f 100644 --- a/pandora/config.indiancinema.jsonc +++ b/pandora/config.indiancinema.jsonc @@ -767,7 +767,9 @@ "level": "guest", "newsletter": true, "ui": { + "annotationsCalendarSize": 128, "annotationsFont": "small", + "annotationsMapSize": 128, "annotationsRange": "all", "annotationsSize": 256, "annotationsSort": "position", @@ -815,6 +817,8 @@ "sequenceSort": [{"key": "director", "operator": "+"}], "showAdvancedEmbedOptions": false, "showAnnotations": true, + "showAnnotationsCalendar": true, + "showAnnotationsMap": true, "showBrowser": true, "showCalendarControls": true, // fixme: should be false "showFilters": true, diff --git a/pandora/settings.py b/pandora/settings.py index 0d324cad0..a8d318068 100644 --- a/pandora/settings.py +++ b/pandora/settings.py @@ -181,6 +181,7 @@ XSENDFILE = False XACCELREDIRECT = False SITE_CONFIG = join(PROJECT_ROOT, 'config.jsonc') +DEFAULT_CONFIG = join(PROJECT_ROOT, 'config.pandora.jsonc') #used if CONFIG['video']['download'] is set TRACKER_URL="udp://tracker.openbittorrent.com:80"