mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11:52 +00:00
logbook cache reading broken - disabled
This commit is contained in:
parent
2391b5a504
commit
8a43cf7dfb
@ -1,10 +1,12 @@
|
|||||||
import csv
|
import csv
|
||||||
from datetime import datetime, date, time
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
#import time
|
|
||||||
import pickle
|
import pickle
|
||||||
import shelve
|
import shelve
|
||||||
|
import time
|
||||||
|
from random import randint
|
||||||
|
from datetime import datetime, date
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.template.defaultfilters import slugify
|
from django.template.defaultfilters import slugify
|
||||||
@ -24,6 +26,9 @@ Parses and imports logbooks in all their wonderful confusion
|
|||||||
todo='''
|
todo='''
|
||||||
- Put the object store 'trips' and the 'logdataissues' into TROG global object
|
- Put the object store 'trips' and the 'logdataissues' into TROG global object
|
||||||
|
|
||||||
|
- works parsing logbooks but when reading cache files fails on storing data
|
||||||
|
and is slower than parsing from scratch now!
|
||||||
|
|
||||||
- refactor everything with some urgency, esp. LoadLogbookForExpedition()
|
- refactor everything with some urgency, esp. LoadLogbookForExpedition()
|
||||||
|
|
||||||
- Logbooks log.htm exist for 1983, 84, 85, 87, 88, 89 but have no full-working parser,
|
- Logbooks log.htm exist for 1983, 84, 85, 87, 88, 89 but have no full-working parser,
|
||||||
@ -141,7 +146,11 @@ def EnterLogIntoDbase(date, place, title, text, trippeople, expedition, logtime_
|
|||||||
# but it is a db query which we should try to avoid - rewrite this
|
# but it is a db query which we should try to avoid - rewrite this
|
||||||
|
|
||||||
#NEW slug for a logbook entry here! Unique id + slugified title fragment
|
#NEW slug for a logbook entry here! Unique id + slugified title fragment
|
||||||
slug = tid + "_" + slugify(title)[:10].replace('-','_')
|
# working for all cache files 2019-2005, failed on 2004; but fine when parsing logbook and not reading cache. Hmm.
|
||||||
|
if tid is not None:
|
||||||
|
slug = tid + "_" + slugify(title)[:10].replace('-','_')
|
||||||
|
else:
|
||||||
|
slug = str(randint(1000,10000)) + "_" + slugify(title)[:10].replace('-','_')
|
||||||
nonLookupAttribs={'place':place, 'text':text, 'expedition':expedition, 'cave_slug':str(cave), 'slug': slug, 'entry_type':entry_type}
|
nonLookupAttribs={'place':place, 'text':text, 'expedition':expedition, 'cave_slug':str(cave), 'slug': slug, 'entry_type':entry_type}
|
||||||
|
|
||||||
lbo, created=save_carefully(LogbookEntry, lookupAttribs, nonLookupAttribs)
|
lbo, created=save_carefully(LogbookEntry, lookupAttribs, nonLookupAttribs)
|
||||||
@ -565,12 +574,14 @@ def LoadLogbookForExpedition(expedition, expect):
|
|||||||
logbookfile = os.path.join(expologbase, expedition.year, settings.DEFAULT_LOGBOOK_FILE)
|
logbookfile = os.path.join(expologbase, expedition.year, settings.DEFAULT_LOGBOOK_FILE)
|
||||||
expedition.logbookfile = settings.DEFAULT_LOGBOOK_FILE
|
expedition.logbookfile = settings.DEFAULT_LOGBOOK_FILE
|
||||||
parsefunc = settings.DEFAULT_LOGBOOK_PARSER
|
parsefunc = settings.DEFAULT_LOGBOOK_PARSER
|
||||||
cache_filename = logbookfile + ".cache"
|
cache_filename = Path(logbookfile + ".cache")
|
||||||
expedition.save()
|
if not cache_filename.is_file():
|
||||||
|
print(" - Cache file does not exist \"" + str(cache_filename) +"\"")
|
||||||
|
|
||||||
|
expedition.save()
|
||||||
|
now = time.time()
|
||||||
|
bad_cache = True # emporarily disable reading the cache - buggy
|
||||||
try:
|
try:
|
||||||
bad_cache = False
|
|
||||||
now = time.time()
|
|
||||||
cache_t = os.path.getmtime(cache_filename)
|
cache_t = os.path.getmtime(cache_filename)
|
||||||
if os.path.getmtime(logbookfile) - cache_t > 2: # at least 2 secs later
|
if os.path.getmtime(logbookfile) - cache_t > 2: # at least 2 secs later
|
||||||
bad_cache= True
|
bad_cache= True
|
||||||
@ -582,7 +593,7 @@ def LoadLogbookForExpedition(expedition, expect):
|
|||||||
logentries=[]
|
logentries=[]
|
||||||
print(" ! Removed stale or corrupt cache file")
|
print(" ! Removed stale or corrupt cache file")
|
||||||
raise
|
raise
|
||||||
print(" - Reading cache: " + cache_filename, end='')
|
print(" - Reading cache: " + str(cache_filename), end='')
|
||||||
try:
|
try:
|
||||||
with open(cache_filename, "rb") as f:
|
with open(cache_filename, "rb") as f:
|
||||||
year,n,logentries = pickle.load(f)
|
year,n,logentries = pickle.load(f)
|
||||||
@ -597,8 +608,8 @@ def LoadLogbookForExpedition(expedition, expect):
|
|||||||
os.remove(cache_filename)
|
os.remove(cache_filename)
|
||||||
logentries=[]
|
logentries=[]
|
||||||
raise
|
raise
|
||||||
except : # no cache found
|
except :
|
||||||
#print(" - No cache \"" + cache_filename +"\"")
|
print(" - Cache de-pickle failure \"" + str(cache_filename) +"\"")
|
||||||
try:
|
try:
|
||||||
file_in = open(logbookfile,'rb')
|
file_in = open(logbookfile,'rb')
|
||||||
txt = file_in.read().decode("latin1")
|
txt = file_in.read().decode("latin1")
|
||||||
@ -627,10 +638,11 @@ def LoadLogbookForExpedition(expedition, expect):
|
|||||||
i=0
|
i=0
|
||||||
for entrytuple in range(len(logentries)):
|
for entrytuple in range(len(logentries)):
|
||||||
date, tripcave, triptitle, text, trippeople, expedition, logtime_underground, entry_type, tripid1 = logentries[i]
|
date, tripcave, triptitle, text, trippeople, expedition, logtime_underground, entry_type, tripid1 = logentries[i]
|
||||||
|
#print(" - entry tuple " , i, " tid", tripid1)
|
||||||
EnterLogIntoDbase(date, tripcave, triptitle, text, trippeople, expedition, 0,
|
EnterLogIntoDbase(date, tripcave, triptitle, text, trippeople, expedition, 0,
|
||||||
entry_type)
|
entry_type, tripid1)
|
||||||
EnterLogIntoObjStore(expedition.year, date, tripcave, triptitle, text, trippeople, logtime_underground,
|
EnterLogIntoObjStore(expedition.year, date, tripcave, triptitle, text, trippeople, logtime_underground,
|
||||||
entry_type, tripid1, i)
|
entry_type, tripid1, i)
|
||||||
i +=1
|
i +=1
|
||||||
SetDatesFromLogbookEntries(expedition)
|
SetDatesFromLogbookEntries(expedition)
|
||||||
return len(logentries)
|
return len(logentries)
|
||||||
|
@ -24,4 +24,4 @@ echo ""
|
|||||||
echo `tail -1 lines-of-python.txt` non-comment lines of python.
|
echo `tail -1 lines-of-python.txt` non-comment lines of python.
|
||||||
echo `tail -1 lines-of-templates.txt` non-comment lines of HTML templates.
|
echo `tail -1 lines-of-templates.txt` non-comment lines of HTML templates.
|
||||||
|
|
||||||
echo 'If you have an error running manage.py, maybe you are not in an activated venv ?
|
echo 'If you have an error running manage.py, maybe you are not in an activated venv ?'
|
Loading…
Reference in New Issue
Block a user