summaryrefslogtreecommitdiffstats
path: root/parsers/logbooks.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2022-10-05 21:10:05 +0300
committerPhilip Sargent <philip.sargent@klebos.com>2022-10-05 21:10:05 +0300
commit9e5bdace2c75eb6436ad33fc8908b1dd4df29c93 (patch)
treecc15c1426a589ec4cf4ec3ee8a3e1f10a6079bff /parsers/logbooks.py
parenta6e60c0bf7ac09175b556cabb8dd13d0d2d49a12 (diff)
downloadtroggle-9e5bdace2c75eb6436ad33fc8908b1dd4df29c93.tar.gz
troggle-9e5bdace2c75eb6436ad33fc8908b1dd4df29c93.tar.bz2
troggle-9e5bdace2c75eb6436ad33fc8908b1dd4df29c93.zip
make cache work even if timestamps wrong
Diffstat (limited to 'parsers/logbooks.py')
-rw-r--r--parsers/logbooks.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/parsers/logbooks.py b/parsers/logbooks.py
index d693b9a..8fc78d6 100644
--- a/parsers/logbooks.py
+++ b/parsers/logbooks.py
@@ -585,15 +585,19 @@ def LoadLogbookForExpedition(expedition):
expect = entries[year]
# print(" - Logbook for: " + year)
- def validcache(year,n):
+ def validcache(year,n, lbsize):
if year != expedition:
- print(" ! year != expedition ",year, expedition )
+ print(" ! cache loading: year != expedition ",year, expedition )
+ return False
+ currentsize = logbookpath.stat().st_size
+ if lbsize != currentsize:
+ print(f" ! cache loading: Logbook size {lbsize} != {currentsize} ")
return False
if len(logentries) != n:
- print(" ! len(logentries) != n ",len(logentries), n )
+ print(" ! cache loading: len(logentries) != n ",len(logentries), n )
return False
if n != expect:
- print(" ! n != expect ",n, expect )
+ print(" ! cache loading: n != expect ",n, expect )
return False
return True
@@ -652,15 +656,15 @@ def LoadLogbookForExpedition(expedition):
try:
# print(" - Reading cache: " + str(cache_filename), end='')
with open(cache_filename, "rb") as f:
- year,n,logentries = pickle.load(f)
- if validcache(year,n):
+ year, lbsize, n, logentries = pickle.load(f)
+ if validcache(year, n, lbsize):
print(f" -- {year} : Loaded {len(logentries)} log entries")
logbook_cached = True
else:
- print(" !- Told to expect ", expect, " but ", len(logentries), " found in cache")
+ print(" !- {year} : Cache failed validity checks")
raise
except:
- print(" ! Failed to load corrupt cache. (Or I was told to ignore it). Deleting it.")
+ print(" ! Failed to load corrupt cache (or I was told to ignore it). Deleting it.")
os.remove(cache_filename)
logentries=[]
raise
@@ -684,8 +688,9 @@ def LoadLogbookForExpedition(expedition):
SetDatesFromLogbookEntries(expedition)
if len(logentries) >0:
print(" - Cacheing " , len(logentries), " log entries")
+ lbsize = logbookpath.stat().st_size
with open(cache_filename, "wb") as fc: # we much check that permission are g+w ! or expo can't delete the cache
- logbk=(expedition,len(logentries),logentries)
+ logbk=(expedition,lbsize,len(logentries),logentries)
pickle.dump(logbk, fc, protocol=4)
else:
print(" ! NO TRIP entries found in logbook, check the syntax.")
@@ -737,7 +742,7 @@ def LoadLogbooks():
expd ={}
actuals = []
- for expo in expos:
+ for expo in expos: # pointless as we explicitly know the years in this code.
year = expo.year
TROG['pagecache']['expedition'][year] = None # clear cache
if year in sqlfail: