From 30003279e35e5931fc85d7e6211ea4de6f9554d7 Mon Sep 17 00:00:00 2001 From: Michael Schmoock Date: Fri, 10 Feb 2023 15:24:44 +0100 Subject: [PATCH] summary: check and dismiss old datastores --- summary/summary.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/summary/summary.py b/summary/summary.py index a1429f2..4fa5d10 100755 --- a/summary/summary.py +++ b/summary/summary.py @@ -246,12 +246,25 @@ def summary(plugin, exclude='', sortkey=None): return reply +def new_datastore(): + return {'p': {}, 'r': 0, 'v': 1} # see summary_avail.py for structure + + +def check_datastore(obj): + if 'v' in obj and type(obj['v']) is int and obj['v'] == 1: + return True + return False + + def load_datastore(plugin): entries = plugin.rpc.listdatastore(key=datastore_key)['datastore'] if len(entries) == 0: plugin.log(f"Creating a new datastore '{datastore_key}'", 'debug') - return {'p': {}, 'r': 0, 'v': 1} # see summary_avail.py for structure + return new_datastore() persist = pickle.loads(bytearray.fromhex(entries[0]["hex"])) + if not check_datastore(persist): + plugin.log(f"Dismissing old datastore '{datastore_key}'", 'debug') + return new_datastore() plugin.log(f"Reopened datastore '{datastore_key}' with {persist['r']} " f"runs and {len(persist['p'])} entries", 'debug') return persist