improved upgrade_settings and removed default settings from base_config, use readme example for reference

pull/8/head
l3uddz 7 years ago
parent 451e11ea8f
commit 8560b14ad9

@ -28,26 +28,22 @@ base_config = {
},
'filters': {
'shows': {
'blacklisted_genres': ['animation', 'game-show', 'talk-show', 'home-and-garden', 'children', 'reality',
'anime', 'news', 'documentary', 'special-interest'],
'blacklisted_networks': ['twitch', 'youtube', 'nickelodeon', 'hallmark', 'reelzchannel', 'disney',
'cnn', 'cbbc', 'the movie network', 'teletoon', 'cartoon network', 'espn',
'yahoo!',
'fox sports'],
'allowed_countries': ['us', 'gb', 'ca'],
'blacklisted_genres': [],
'blacklisted_networks': [],
'allowed_countries': [],
'blacklisted_min_runtime': 15,
'blacklisted_min_year': 2000,
'blacklisted_max_year': 2019,
'blacklisted_tvdb_ids': [],
},
'movies': {
'blacklisted_genres': ['documentary', 'music', 'animation'],
'blacklisted_genres': [],
'blacklisted_min_runtime': 60,
'blacklisted_min_year': 2000,
'blacklisted_max_year': 2019,
'blacklist_title_keywords': ['untitled', 'barbie'],
'blacklist_title_keywords': [],
'blacklisted_tmdb_ids': [],
'allowed_countries': ['us', 'gb', 'ca']
'allowed_countries': []
}
},
'automatic': {
@ -113,25 +109,39 @@ def load_config():
return AttrConfig(json.load(fp))
def upgrade_settings(defaults, current):
def upgrade_settings(defaults, currents):
upgraded = False
res = current.copy()
for k, v in defaults.items():
def inner_upgrade(default, current, key=None):
sub_upgraded = False
merged = current.copy()
if isinstance(default, dict):
for k, v in default.items():
# missing k
if k not in current:
res[k] = v
upgraded = True
print("Added config option: %s" % k)
if hasattr(v, 'items'):
if k in current:
sub_upgrade, res[k] = upgrade_settings(v, current[k])
if sub_upgrade:
upgraded = True
merged[k] = v
sub_upgraded = True
if not key:
print("Added %r config option: %s" % (str(k), str(v)))
else:
res[k] = v
upgraded = True
return upgraded, AttrConfig(res)
print("Added %r to config option %r: %s" % (str(k), str(key), str(v)))
continue
# iterate children
if isinstance(v, dict) or isinstance(v, list):
did_upgrade, merged[k] = inner_upgrade(default[k], current[k], key=k)
sub_upgraded = did_upgrade if did_upgrade else sub_upgraded
elif isinstance(default, list) and key:
for v in default:
if v not in current:
merged.append(v)
sub_upgraded = True
print("Added to config option %r: %s" % (str(key), str(v)))
continue
return sub_upgraded, merged
upgraded, upgraded_settings = inner_upgrade(defaults, currents)
return upgraded, AttrConfig(upgraded_settings)
############################################################

Loading…
Cancel
Save