properly update the config-dictionary

When using 2 or more config files, the values of the second would
improperly overwrite nested dictionaries of the first one.
The new method properly combines these nested dictionaries as well.
pull/40/head
Mike Fährmann 7 years ago
parent ae2d61e5b3
commit 004456d5d5
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88

@ -12,6 +12,7 @@ import sys
import json
import os.path
import logging
from . import util
log = logging.getLogger("config")
@ -57,7 +58,10 @@ def load(*files, format="json", strict=False):
path = os.path.expanduser(os.path.expandvars(conf))
with open(path) as file:
confdict = parsefunc(file)
_config.update(confdict)
if not _config:
_config.update(confdict)
else:
util.combine_dict(_config, confdict)
except FileNotFoundError:
if strict:
log.error("Configuration file '%s' not found", path)

@ -311,7 +311,7 @@ class DeviantartJournalExtractor(DeviantartExtractor):
r"/(?:journal|blog)/?(?:\?catpath=/)?$"]
test = [
("http://shimoda7.deviantart.com/journal/", {
"url": "f7960ae06e774d6931c61ad309c95a10710658b2",
"url": "b1a3460e7da0f34c8f6c286a3b5428fd4d3bc64b",
"keyword": "6444966c703e63470a5fdd8f460993b68955c32c",
}),
("http://shimoda7.deviantart.com/journal/?catpath=/", None),

@ -80,6 +80,15 @@ def bdecode(data, alphabet="0123456789"):
return num
def combine_dict(a, b):
"""Recursively combine the contents of b into a"""
for key, value in b.items():
if key in a and isinstance(value, dict) and isinstance(a[key], dict):
combine_dict(a[key], value)
else:
a[key] = value
def code_to_language(code, default=None):
"""Map an ISO 639-1 language code to its actual name"""
return CODES.get((code or "").lower(), default)

Loading…
Cancel
Save