From e873dedcf281b5feedde26c2c26883baf9fff9a0 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 1 Jun 2020 02:18:25 +0100 Subject: [PATCH] bugfixes done using _future_ --- parsers/survex.py | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/parsers/survex.py b/parsers/survex.py index 98eed39..31f545b 100644 --- a/parsers/survex.py +++ b/parsers/survex.py @@ -1,21 +1,17 @@ -from __future__ import (absolute_import, division, - print_function) -import sys +from __future__ import absolute_import, division, print_function + import os import re +import sys import time from datetime import datetime, timedelta -from subprocess import call, Popen, PIPE +from subprocess import PIPE, Popen, call +from django.utils.timezone import get_current_timezone, make_aware + +import troggle.settings as settings +import troggle.core.models as models from troggle.parsers.people import GetPersonExpeditionNameLookup -from django.utils.timezone import get_current_timezone -from django.utils.timezone import make_aware - -import re -import os -import time -from datetime import datetime, timedelta -import sys """A 'survex block' is a *begin...*end set of cave data. A 'survexscansfolder' is what we today call a "survey scans folder" or a "wallet". @@ -516,35 +512,35 @@ def LoadPos(): now = time.time() if now - updtcache > 3*24*60*60: - print " cache is more than 3 days old. Deleting." + print( " cache is more than 3 days old. Deleting.") os.remove(cachefile) elif age < 0 : - print " cache is stale. Deleting." + print(" cache is stale. Deleting.") os.remove(cachefile) else: - print " cache is fresh. Reading..." + print(" cache is fresh. Reading...") try: 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] + print(" DUPLICATE ", line, notfoundbefore[l]) else: notfoundbefore[l] =1 except: - print " FAILURE READ opening cache file %s" % (cachefile) + print(" FAILURE READ opening cache file %s" % (cachefile)) raise notfoundnow =[] found = 0 skip = {} - print "\n" # extra line because cavern overwrites the text buffer somehow + print("\n") # extra line because cavern overwrites the text buffer somehow # cavern defaults to using same cwd as supplied input file call([settings.CAVERN, "--output=%s.3d" % (topdata), "%s.svx" % (topdata)]) call([settings.THREEDTOPOS, '%s.3d' % (topdata)], cwd = settings.SURVEX_DATA) - print " - This next bit takes a while. Matching ~32,000 survey positions. Be patient..." + print(" - This next bit takes a while. Matching ~32,000 survey positions. Be patient...") posfile = open("%s.pos" % (topdata)) posfile.readline() #Drop header @@ -564,7 +560,7 @@ def LoadPos(): found += 1 except: notfoundnow.append(name) - print " - %s stations not found in lookup of SurvexStation.objects. %s found. %s skipped." % (len(notfoundnow),found, len(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: @@ -576,6 +572,5 @@ def LoadPos(): 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) + print(" FAILURE WRITE opening cache file %s" % (cachefile)) raise -