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