1
0
mirror of https://github.com/craigerl/aprsd.git synced 2026-08-16 16:43:52 -04:00

Compare commits

...

3 Commits

Author SHA1 Message Date
hemna 0d5b7166b3 Updated Changelog 2021-11-02 11:47:40 -04:00
hemna cefb581bb8 Be more careful picking data to/from disk
This patch ensures that the pickle file is opened and closed correctly
as well as trapping for any exceptions that might occur while loading
a pickle file.
2021-11-02 08:52:59 -04:00
hemna d2e8fe660f Updated Changelog 2021-10-25 11:33:15 -04:00
2 changed files with 28 additions and 6 deletions
+13
View File
@@ -1,9 +1,22 @@
CHANGES
=======
v2.4.2
------
* Be more careful picking data to/from disk
* Updated Changelog
v2.4.1
------
* Ensure plugins are last to be loaded
* Fixed email connecting to smtp server
v2.4.0
------
* Updated Changelog for 2.4.0 release
* Converted MsgTrack to ObjectStoreMixin
* Fixed unit tests
* Make sure SeenList update has a from in packet
+15 -6
View File
@@ -70,7 +70,8 @@ class ObjectStoreMixin:
"""Save any queued to disk?"""
if len(self) > 0:
LOG.info(f"{self.__class__.__name__}::Saving {len(self)} entries to disk at {self._save_location()}")
pickle.dump(self._dump(), open(self._save_filename(), "wb+"))
with open(self._save_filename(), "wb+") as fp:
pickle.dump(self._dump(), fp)
else:
LOG.debug(
"{} Nothing to save, flushing old save file '{}'".format(
@@ -82,11 +83,19 @@ class ObjectStoreMixin:
def load(self):
if os.path.exists(self._save_filename()):
raw = pickle.load(open(self._save_filename(), "rb"))
if raw:
self.data = raw
LOG.debug(f"{self.__class__.__name__}::Loaded {len(self)} entries from disk.")
LOG.debug(f"{self.data}")
try:
with open(self._save_filename(), "rb") as fp:
raw = pickle.load(fp)
if raw:
self.data = raw
LOG.debug(
f"{self.__class__.__name__}::Loaded {len(self)} entries from disk.",
)
LOG.debug(f"{self.data}")
except pickle.UnpicklingError as ex:
LOG.error(f"Failed to UnPickle {self._save_filename()}")
LOG.error(ex)
self.data = {}
def flush(self):
"""Nuke the old pickle file that stored the old results from last aprsd run."""