add default values for missing capabilities and user.ui setting to config.jsonc from config.pandora.jsonc, fixes #1604

This commit is contained in:
j 2013-07-06 10:54:58 +00:00
parent 3c539ffc28
commit 662c7ec12a
4 changed files with 45 additions and 14 deletions

View file

@ -39,6 +39,12 @@ def load_config():
except: except:
config = None config = None
with open(settings.DEFAULT_CONFIG) as f:
try:
default = ox.jsonc.load(f)
except:
default = None
if config: if config:
settings.SITENAME = config['site']['name'] settings.SITENAME = config['site']['name']
if getattr(settings, 'SITEURL', False): if getattr(settings, 'SITEURL', False):
@ -56,6 +62,24 @@ def load_config():
for key in config['itemKeys']: for key in config['itemKeys']:
config['keys'][key['id']] = key 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', []) old_formats = getattr(settings, 'CONFIG', {}).get('video', {}).get('formats', [])
formats = config.get('video', {}).get('formats') formats = config.get('video', {}).get('formats')
if set(old_formats) != set(formats): if set(old_formats) != set(formats):
@ -110,20 +134,18 @@ def reloader_thread():
except: except:
INOTIFY = False INOTIFY = False
if INOTIFY: if INOTIFY:
class ConfigChanges: def add_watch():
def __init__(self): name = os.path.realpath(settings.SITE_CONFIG)
name = os.path.realpath(settings.SITE_CONFIG) wm.add_watch(name, pyinotify.IN_CLOSE_WRITE, reload_config)
self.name = name
self.wm = pyinotify.WatchManager() def reload_config(event):
self.reload_config() load_config()
notifier = pyinotify.Notifier(self.wm) add_watch()
notifier.loop()
wm = pyinotify.WatchManager()
def reload_config(self): add_watch()
load_config() notifier = pyinotify.Notifier(wm)
self.wm.add_watch(self.name, pyinotify.IN_CLOSE_WRITE, notifier.loop()
lambda event: self.reload_config())
ConfigChanges()
else: else:
while RUN_RELOADER: while RUN_RELOADER:
try: try:

View file

@ -729,7 +729,9 @@
"level": "guest", "level": "guest",
"newsletter": true, "newsletter": true,
"ui": { "ui": {
"annotationsCalendarSize": 128,
"annotationsFont": "small", "annotationsFont": "small",
"annotationsMapSize": 128,
"annotationsRange": "all", "annotationsRange": "all",
"annotationsSize": 256, "annotationsSize": 256,
"annotationsSort": "position", "annotationsSort": "position",
@ -777,6 +779,8 @@
"sequenceSort": [{"key": "director", "operator": "+"}], "sequenceSort": [{"key": "director", "operator": "+"}],
"showAdvancedEmbedOptions": false, "showAdvancedEmbedOptions": false,
"showAnnotations": true, "showAnnotations": true,
"showAnnotationsCalendar": true,
"showAnnotationsMap": true,
"showBrowser": true, "showBrowser": true,
"showCalendarControls": true, // fixme: should be false "showCalendarControls": true, // fixme: should be false
"showFilters": true, "showFilters": true,

View file

@ -767,7 +767,9 @@
"level": "guest", "level": "guest",
"newsletter": true, "newsletter": true,
"ui": { "ui": {
"annotationsCalendarSize": 128,
"annotationsFont": "small", "annotationsFont": "small",
"annotationsMapSize": 128,
"annotationsRange": "all", "annotationsRange": "all",
"annotationsSize": 256, "annotationsSize": 256,
"annotationsSort": "position", "annotationsSort": "position",
@ -815,6 +817,8 @@
"sequenceSort": [{"key": "director", "operator": "+"}], "sequenceSort": [{"key": "director", "operator": "+"}],
"showAdvancedEmbedOptions": false, "showAdvancedEmbedOptions": false,
"showAnnotations": true, "showAnnotations": true,
"showAnnotationsCalendar": true,
"showAnnotationsMap": true,
"showBrowser": true, "showBrowser": true,
"showCalendarControls": true, // fixme: should be false "showCalendarControls": true, // fixme: should be false
"showFilters": true, "showFilters": true,

View file

@ -181,6 +181,7 @@ XSENDFILE = False
XACCELREDIRECT = False XACCELREDIRECT = False
SITE_CONFIG = join(PROJECT_ROOT, 'config.jsonc') SITE_CONFIG = join(PROJECT_ROOT, 'config.jsonc')
DEFAULT_CONFIG = join(PROJECT_ROOT, 'config.pandora.jsonc')
#used if CONFIG['video']['download'] is set #used if CONFIG['video']['download'] is set
TRACKER_URL="udp://tracker.openbittorrent.com:80" TRACKER_URL="udp://tracker.openbittorrent.com:80"