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:
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:

View file

@ -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,

View file

@ -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,

View file

@ -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"