1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-06-25 05:25:21 -04:00

Added iterator to objectstore

Since the objectstore mixin uses a iterable to store it's data,
it was easy to add an __iter__ to the objectstore class itself.
This commit is contained in:
Hemna 2024-02-24 14:27:39 -05:00
parent e89f8a805b
commit df2798eafb

View File

@ -28,6 +28,9 @@ class ObjectStoreMixin:
def __len__(self): def __len__(self):
return len(self.data) return len(self.data)
def __iter__(self):
return iter(self.data)
def get_all(self): def get_all(self):
with self.lock: with self.lock:
return self.data return self.data
@ -96,11 +99,15 @@ class ObjectStoreMixin:
LOG.debug( LOG.debug(
f"{self.__class__.__name__}::Loaded {len(self)} entries from disk.", f"{self.__class__.__name__}::Loaded {len(self)} entries from disk.",
) )
LOG.debug(f"{self.data}") #LOG.debug(f"{self.data}")
else:
LOG.debug(f"{self.__class__.__name__}::No data to load.")
except (pickle.UnpicklingError, Exception) as ex: except (pickle.UnpicklingError, Exception) as ex:
LOG.error(f"Failed to UnPickle {self._save_filename()}") LOG.error(f"Failed to UnPickle {self._save_filename()}")
LOG.error(ex) LOG.error(ex)
self.data = {} self.data = {}
else:
LOG.debug(f"{self.__class__.__name__}::No save file found.")
def flush(self): def flush(self):
"""Nuke the old pickle file that stored the old results from last aprsd run.""" """Nuke the old pickle file that stored the old results from last aprsd run."""