summaryrefslogtreecommitdiffstats
path: root/parsers/survex.py
diff options
context:
space:
mode:
Diffstat (limited to 'parsers/survex.py')
-rw-r--r--parsers/survex.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/parsers/survex.py b/parsers/survex.py
index 0484b86..5720b11 100644
--- a/parsers/survex.py
+++ b/parsers/survex.py
@@ -10,7 +10,7 @@ from django.utils.timezone import make_aware
import re
import os
-from datetime import datetime
+from datetime import datetime, timedelta
line_leg_regex = re.compile(r"[\d\-+.]+$")
@@ -405,20 +405,25 @@ def LoadPos():
updtsvx = os.path.getmtime(topdata + ".svx")
updtcache = os.path.getmtime(cachefile)
age = updtcache - updtsvx
- print(' svx: %s cache: %s cache age: %s' % (updtsvx, updtcache, age ))
+ print(' svx: %s cache: %s cache age: %s' % (updtsvx, updtcache, str(timedelta(seconds=age) )))
if age < 0 :
print " cache is stale."
os.remove(cachefile)
else:
- print " cache is fresh."
+ print " cache is fresh. Reading..."
try:
- f = open(cachefile, "r")
- for line in f:
- notfoundbefore[line] +=1 # should not be duplicates
+ with open(cachefile, "r") as f:
+ for line in f:
+ l = line.rstrip()
+ if l in notfoundbefore:
+ notfoundbefore[l] +=1 # should not be duplicates
+ print " DUPLICATE ", line, notfoundbefore[l]
+ else:
+ notfoundbefore[l] =1
except:
print " FAILURE READ opening cache file %s" % (cachefile)
- f.close()
-
+ raise
+
notfoundnow =[]
found = 0
@@ -434,7 +439,7 @@ def LoadPos():
if r:
x, y, z, name = r.groups() # easting, northing, altitude
if name in notfoundbefore:
- skip[name] += 1
+ skip[name] = 1
else:
try:
ss = models.SurvexStation.objects.lookup(name)
@@ -446,16 +451,18 @@ def LoadPos():
except:
#print "%s in %s.pos not found in lookup of SurvexStation.objects" % (name, settings.SURVEX_TOPNAME)
notfoundnow.append(name)
- print " - %s stations NOT found in lookup of SurvexStation.objects. %s found. %s skipper." % (len(notfoundnow),found, skip)
+ print " - %s stations NOT found in lookup of SurvexStation.objects. %s found. %s skipped." % (len(notfoundnow),found, len(skip))
if found > 10: # i.e. a previous cave import has been done
try:
with open(cachefile, "w") as f:
- print " cache file opened"
+ c = len(notfoundnow)+len(skip)
for i in notfoundnow:
f.write("%s\n" % i)
for j in skip:
f.write("%s\n" % j) # NB skip not notfoundbefore
+ print(' Not-found cache file written: %s entries' % c)
except:
print " FAILURE WRITE opening cache file %s" % (cachefile)
+ raise