Rename recursive_dict_update's parameters for clarity.

This commit is contained in:
voussoir 2018-02-03 01:10:54 -08:00
parent f266e1c79c
commit dec28b321a
2 changed files with 8 additions and 8 deletions

View file

@ -231,20 +231,20 @@ def read_filebytes(filepath, range_min, range_max, chunk_size=2 ** 20):
yield chunk yield chunk
sent_amount += len(chunk) sent_amount += len(chunk)
def recursive_dict_update(d1, d2): def recursive_dict_update(target, supply):
''' '''
Update d1 using d2, but when the value is a dictionary update the insides Update target using supply, but when the value is a dictionary update the
instead of replacing the dictionary itself. insides instead of replacing the dictionary itself.
''' '''
for (key, value) in d2.items(): for (key, value) in supply.items():
if isinstance(value, dict): if isinstance(value, dict):
existing = d1.get(key, None) existing = target.get(key, None)
if existing is None: if existing is None:
d1[key] = value target[key] = value
else: else:
recursive_dict_update(existing, value) recursive_dict_update(existing, value)
else: else:
d1[key] = value target[key] = value
def recursive_dict_keys(d): def recursive_dict_keys(d):
''' '''

View file

@ -1087,7 +1087,7 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs
my_keys = helpers.recursive_dict_keys(config) my_keys = helpers.recursive_dict_keys(config)
stored_keys = helpers.recursive_dict_keys(user_config) stored_keys = helpers.recursive_dict_keys(user_config)
needs_dump = not my_keys.issubset(stored_keys) needs_dump = not my_keys.issubset(stored_keys)
helpers.recursive_dict_update(config, user_config) helpers.recursive_dict_update(target=config, supply=user_config)
if (not user_config_exists) or needs_dump: if (not user_config_exists) or needs_dump:
with open(self.config_filepath.absolute_path, 'w') as handle: with open(self.config_filepath.absolute_path, 'w') as handle: