From 87886a0a13101a8547bff7b2b1baf1da09e4db69 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sat, 17 Mar 2018 17:07:30 -0700 Subject: [PATCH] Unprivatize PDB._load_config and _save_config. --- etiquette/photodb.py | 50 ++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/etiquette/photodb.py b/etiquette/photodb.py index 937d9f8..5b7e454 100644 --- a/etiquette/photodb.py +++ b/etiquette/photodb.py @@ -1132,7 +1132,7 @@ class PhotoDB( # CONFIG self.config_filepath = self.data_directory.with_child(constants.DEFAULT_CONFIGNAME) - self.config = self._load_config() + self.config = self.load_config() self.log.setLevel(self.config['log_level']) # OTHER @@ -1173,30 +1173,6 @@ class PhotoDB( cur.execute(statement) self.sql.commit() - def _load_config(self): - config = copy.deepcopy(constants.DEFAULT_CONFIGURATION) - user_config_exists = self.config_filepath.is_file - needs_dump = False - if user_config_exists: - with open(self.config_filepath.absolute_path, 'r') as handle: - user_config = json.load(handle) - my_keys = helpers.recursive_dict_keys(config) - stored_keys = helpers.recursive_dict_keys(user_config) - needs_dump = not my_keys.issubset(stored_keys) - helpers.recursive_dict_update(target=config, supply=user_config) - else: - needs_dump = True - - if needs_dump: - self._save_config() - - self.config = config - return config - - def _save_config(self): - with open(self.config_filepath.absolute_path, 'w') as handle: - handle.write(json.dumps(self.config, indent=4, sort_keys=True)) - def __del__(self): self.close() @@ -1474,6 +1450,30 @@ class PhotoDB( thing = thing_map['class'](self, db_row=thing) yield thing + def load_config(self): + config = copy.deepcopy(constants.DEFAULT_CONFIGURATION) + user_config_exists = self.config_filepath.is_file + needs_dump = False + if user_config_exists: + with open(self.config_filepath.absolute_path, 'r') as handle: + user_config = json.load(handle) + my_keys = helpers.recursive_dict_keys(config) + stored_keys = helpers.recursive_dict_keys(user_config) + needs_dump = not my_keys.issubset(stored_keys) + helpers.recursive_dict_update(target=config, supply=user_config) + else: + needs_dump = True + + if needs_dump: + self.save_config() + + self.config = config + return config + + def save_config(self): + with open(self.config_filepath.absolute_path, 'w') as handle: + handle.write(json.dumps(self.config, indent=4, sort_keys=True)) + _THING_CLASSES = { 'album':