Skip to content

Commit

Permalink
Persistent storage code tidying (#1199)
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc authored Sep 2, 2024
1 parent 1dc22e1 commit fa6d4e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ System Administrators and DevOps who wish to send a notification now no longer n
* [Configuration Files](#api-configuration-files)
* [File Attachments](#api-file-attachments)
* [Loading Custom Notifications/Hooks](#api-loading-custom-notificationshooks)
* [Persistent Storage](#persistent-storage)
* [More Supported Links and Documentation](#want-to-learn-more)
<!--te-->

Expand Down
54 changes: 27 additions & 27 deletions apprise/persistent_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _ntf_tidy(ntf):
'Persistent temporary file removal failed: %s',
ntf.name)
logger.debug(
'Persistent Storage Exception: %s' % str(e))
'Persistent Storage Exception: %s', str(e))


class CacheObject:
Expand Down Expand Up @@ -195,7 +195,7 @@ def instantiate(content, persistent=True, verify=True):

except (TypeError, KeyError) as e:
logger.trace(f'CacheObject could not be parsed from {content}')
logger.trace('CacheObject exception: %s' % str(e))
logger.trace('CacheObject exception: %s', str(e))
return None

if class_name in ('aware_datetime', 'naive_datetime', 'datetime'):
Expand Down Expand Up @@ -450,7 +450,7 @@ def read(self, key=None, compress=True, expires=False):
IOError) as e:
# We can't access the file or it does not exist
logger.warning('Could not read with persistent key: %s', key)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))

# return none
return None
Expand Down Expand Up @@ -492,7 +492,7 @@ def write(self, data, key=None, compress=True, _recovery=False):
logger.warning(
'Could read() from potential iostream with persistent '
'key: %s', key)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))
raise exception.AppriseDiskIOError(
"Invalid data type {} provided to Persistent Storage"
.format(type(data)))
Expand Down Expand Up @@ -520,7 +520,7 @@ def write(self, data, key=None, compress=True, _recovery=False):
# Permission error of some kind or disk problem...
# There is nothing we can do at this point
logger.warning('Could not write with persistent key: %s', key)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))
return False

# Create a temporary file to write our content into
Expand Down Expand Up @@ -572,7 +572,7 @@ def write(self, data, key=None, compress=True, _recovery=False):
except (OSError, UnicodeEncodeError, IOError, zlib.error) as e:
# We can't access the file or it does not exist
logger.warning('Could not write to persistent key: %s', key)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))

# Tidy our Named Temporary File
_ntf_tidy(ntf)
Expand Down Expand Up @@ -635,7 +635,7 @@ def __move(self, src, dst):
# There is nothing we can do at this point
logger.warning(
'Could not previous persistent data backup: %s', dst_backup)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))
return False

try:
Expand All @@ -654,7 +654,7 @@ def __move(self, src, dst):
logger.warning(
'Could not install persistent content %s -> %s',
dst, os.path.basename(dst_backup))
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))
return False

#
Expand All @@ -670,7 +670,7 @@ def __move(self, src, dst):
logger.warning(
'Could not install persistent content %s -> %s',
src, os.path.basename(dst))
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))
try:
# Restore our old backup (if it exists)
os.rename(dst_backup, dst)
Expand All @@ -686,7 +686,7 @@ def __move(self, src, dst):
# There is nothing we can do at this point
logger.warning(
'Failed to restore original persistent file: %s', dst)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))

return False

Expand Down Expand Up @@ -731,7 +731,7 @@ def open(self, key=None, mode='r', buffering=-1, encoding=None,
except (OSError, IOError, zlib.error) as e:
# We can't access the file or it does not exist
logger.warning('Could not read with persistent key: %s', key)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))
raise exception.AppriseDiskIOError(str(e))

def get(self, key, default=None, lazy=True):
Expand Down Expand Up @@ -799,7 +799,7 @@ def clear(self, *args):
for arg in args:

try:
del self._cache['key']
del self._cache[arg]

# Set our dirty flag (if not set already)
self.__dirty = True
Expand Down Expand Up @@ -902,7 +902,7 @@ def __load_cache(self, _recovery=False):
logger.warning(
'Could not remove persistent cache content: %s',
cache_file)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))
return False
return self.__load_cache(_recovery=True)

Expand All @@ -918,7 +918,7 @@ def __load_cache(self, _recovery=False):
logger.warning(
'Could not load persistent cache for namespace %s',
os.path.basename(self.__base_path))
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))
return False

# Ensure our dirty flag is set to False
Expand All @@ -938,7 +938,7 @@ def __prepare(self, flush=True):
logger.debug(
'Could not create persistent store directory %s',
self.__base_path)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))

# Mode changed back to MEMORY
self.__mode = PersistentStoreMode.MEMORY
Expand All @@ -952,7 +952,7 @@ def __prepare(self, flush=True):
logger.debug(
'Could not create persistent store directory %s',
self.__temp_path)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))

# Mode changed back to MEMORY
self.__mode = PersistentStoreMode.MEMORY
Expand All @@ -965,7 +965,7 @@ def __prepare(self, flush=True):
logger.debug(
'Could not create persistent store directory %s',
self.__data_path)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))

# Mode changed back to MEMORY
self.__mode = PersistentStoreMode.MEMORY
Expand Down Expand Up @@ -1012,7 +1012,7 @@ def flush(self, force=False, _recovery=False):
except (OSError, IOError) as e:
# We can't access the file or it does not exist
logger.debug('Could not update file timestamp: %s', path)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))

if not force and self.__dirty is False:
# Nothing further to do
Expand Down Expand Up @@ -1052,7 +1052,7 @@ def flush(self, force=False, _recovery=False):
logger.warning(
'Could not remove persistent cache backup: %s',
backup_file)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))
return False

try:
Expand All @@ -1070,7 +1070,7 @@ def flush(self, force=False, _recovery=False):
logger.warning(
'Could not remove stale persistent cache file: %s',
cache_file)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))
return False
return True

Expand Down Expand Up @@ -1107,7 +1107,7 @@ def flush(self, force=False, _recovery=False):
logger.error(
'Persistent temporary directory inaccessible: %s',
self.__temp_path)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))

# Tidy our Named Temporary File
_ntf_tidy(ntf)
Expand All @@ -1130,7 +1130,7 @@ def flush(self, force=False, _recovery=False):
logger.error(
'Persistent temporary file can not be written to '
'due to bad input data: %s', ntf.name)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))

# Tidy our Named Temporary File
_ntf_tidy(ntf)
Expand All @@ -1142,7 +1142,7 @@ def flush(self, force=False, _recovery=False):
logger.error(
'Persistent temporary file inaccessible: %s',
ntf.name)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))

# Tidy our Named Temporary File
_ntf_tidy(ntf)
Expand Down Expand Up @@ -1263,7 +1263,7 @@ def is_namespace(x):
logger.error(
'Disk Scan detetcted inaccessible path: %s', path)
logger.debug(
'Persistent Storage Exception: %s' % str(e))
'Persistent Storage Exception: %s', str(e))
return []

return namespaces
Expand Down Expand Up @@ -1346,7 +1346,7 @@ def disk_prune(path, namespace=None, expires=None, action=False):
'Disk Prune (ns=%s, clean=%s) detetcted inaccessible '
'file: %s', namespace, 'yes' if action else 'no', file)
logger.debug(
'Persistent Storage Exception: %s' % str(e))
'Persistent Storage Exception: %s', str(e))

# No longer worth doing a directory sweep
dir_sweep = False
Expand Down Expand Up @@ -1389,7 +1389,7 @@ def disk_prune(path, namespace=None, expires=None, action=False):
'yes' if action else 'no', file)

logger.debug(
'Persistent Storage Exception: %s' % str(e))
'Persistent Storage Exception: %s', str(e))

# No longer worth doing a directory sweep
dir_sweep = False
Expand Down Expand Up @@ -1643,7 +1643,7 @@ def delete(self, *args, all=None, temp=None, cache=None, validate=True):
has_error = True
logger.error(
'Failed to remove persistent file: %s', ppath)
logger.debug('Persistent Storage Exception: %s' % str(e))
logger.debug('Persistent Storage Exception: %s', str(e))

# Reset our reference variables
self.__cache_size = None
Expand Down

0 comments on commit fa6d4e6

Please sign in to comment.