def _write_db(self): try: copy_file(self._smm_db, get_file_name(self._smm_db_location, DB_FILE_NAME_BKP)) with open(self._smm_db, 'w+') as outfile: json.dump(self._data, outfile, indent=2, sort_keys=True) except (OSError, IOError): raise OSError('Unable to save data to disk.')
def __init__(self, path=DB_PATH): self._smm_db_location = get_abs_path( path) if path is not None else get_abs_path(DB_DEF_PATH) self._smm_db = get_file_name(self._smm_db_location, DB_FILE_NAME) self._data = None if not check_configuration(self._smm_db): create_db_path(self._smm_db_location) if not is_file(self._smm_db): init_smmdbstore(self._smm_db, INIT_STATE) # by now, db is there self._data = self._load_json(self._smm_db) self._check_data_integrity()