summaryrefslogtreecommitdiffstats
path: root/parsers/survex.py
diff options
context:
space:
mode:
authorSam Wenham <sam@wenhams.co.uk>2019-02-24 13:03:34 +0000
committerSam Wenham <sam@wenhams.co.uk>2019-02-24 13:03:34 +0000
commit4ad5b684333bfb995160cd6bf00308d9f3839d4a (patch)
treef5683df0d04d8decad0685198e6e76980e376ef0 /parsers/survex.py
parent552730f0a38f474a181f2e1550589a4823667f3c (diff)
downloadtroggle-4ad5b684333bfb995160cd6bf00308d9f3839d4a.tar.gz
troggle-4ad5b684333bfb995160cd6bf00308d9f3839d4a.tar.bz2
troggle-4ad5b684333bfb995160cd6bf00308d9f3839d4a.zip
Make things more compatiable with newer python
Fix the expeditions list Improvements to make it compatiable with django 1.8 Bump the years to add 2018 Update the .hgignore file to ignore junk
Diffstat (limited to 'parsers/survex.py')
-rw-r--r--parsers/survex.py98
1 files changed, 54 insertions, 44 deletions
diff --git a/parsers/survex.py b/parsers/survex.py
index 0c108ac..536314f 100644
--- a/parsers/survex.py
+++ b/parsers/survex.py
@@ -9,7 +9,6 @@ import re
import os
-
def LoadSurvexLineLeg(survexblock, stardata, sline, comment):
ls = sline.lower().split()
ssfrom = survexblock.MakeSurvexStation(ls[stardata["from"]])
@@ -20,23 +19,23 @@ def LoadSurvexLineLeg(survexblock, stardata, sline, comment):
try:
survexleg.tape = float(ls[stardata["tape"]])
except ValueError:
- print "Tape misread in", survexblock.survexfile.path
- print "Stardata:", stardata
- print "Line:", ls
+ print("Tape misread in", survexblock.survexfile.path)
+ print("Stardata:", stardata)
+ print("Line:", ls)
survexleg.tape = 1000
try:
lclino = ls[stardata["clino"]]
except:
- print "Clino misread in", survexblock.survexfile.path
- print "Stardata:", stardata
- print "Line:", ls
+ print("Clino misread in", survexblock.survexfile.path)
+ print("Stardata:", stardata)
+ print("Line:", ls)
lclino = error
try:
lcompass = ls[stardata["compass"]]
except:
- print "Compass misread in", survexblock.survexfile.path
- print "Stardata:", stardata
- print "Line:", ls
+ print("Compass misread in", survexblock.survexfile.path)
+ print("Stardata:", stardata)
+ print("Line:", ls)
lcompass = error
if lclino == "up":
survexleg.compass = 0.0
@@ -48,14 +47,14 @@ def LoadSurvexLineLeg(survexblock, stardata, sline, comment):
try:
survexleg.compass = float(lcompass)
except ValueError:
- print "Compass misread in", survexblock.survexfile.path
- print "Stardata:", stardata
- print "Line:", ls
+ print("Compass misread in", survexblock.survexfile.path)
+ print("Stardata:", stardata)
+ print("Line:", ls)
survexleg.compass = 1000
survexleg.clino = -90.0
else:
- assert re.match("[\d\-+.]+$", lcompass), ls
- assert re.match("[\d\-+.]+$", lclino) and lclino != "-", ls
+ assert re.match(r"[\d\-+.]+$", lcompass), ls
+ assert re.match(r"[\d\-+.]+$", lclino) and lclino != "-", ls
survexleg.compass = float(lcompass)
survexleg.clino = float(lclino)
@@ -67,9 +66,10 @@ def LoadSurvexLineLeg(survexblock, stardata, sline, comment):
try:
survexblock.totalleglength += float(ls[itape])
except ValueError:
- print "Length not added"
+ print("Length not added")
survexblock.save()
-
+
+
def LoadSurvexEquate(survexblock, sline):
#print sline #
stations = sline.split()
@@ -77,12 +77,13 @@ def LoadSurvexEquate(survexblock, sline):
for station in stations:
survexblock.MakeSurvexStation(station)
+
def LoadSurvexLinePassage(survexblock, stardata, sline, comment):
pass
-stardatadefault = { "type":"normal", "t":"leg", "from":0, "to":1, "tape":2, "compass":3, "clino":4 }
-stardataparamconvert = { "length":"tape", "bearing":"compass", "gradient":"clino" }
+stardatadefault = {"type":"normal", "t":"leg", "from":0, "to":1, "tape":2, "compass":3, "clino":4}
+stardataparamconvert = {"length":"tape", "bearing":"compass", "gradient":"clino"}
def RecursiveLoad(survexblock, survexfile, fin, textlines):
iblankbegins = 0
@@ -91,7 +92,7 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines):
teammembers = [ ]
# uncomment to print out all files during parsing
-# print "Reading file:", survexblock.survexfile.path
+ print("Reading file:", survexblock.survexfile.path)
while True:
svxline = fin.readline().decode("latin1")
if not svxline:
@@ -99,10 +100,10 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines):
textlines.append(svxline)
# break the line at the comment
- sline, comment = re.match("([^;]*?)\s*(?:;\s*(.*))?\n?$", svxline.strip()).groups()
+ sline, comment = re.match(r"([^;]*?)\s*(?:;\s*(.*))?\n?$", svxline.strip()).groups()
# detect ref line pointing to the scans directory
- mref = comment and re.match('.*?ref.*?(\d+)\s*#\s*(\d+)', comment)
+ mref = comment and re.match(r'.*?ref.*?(\d+)\s*#\s*(\d+)', comment)
if mref:
refscan = "%s#%s" % (mref.group(1), mref.group(2))
survexscansfolders = models.SurvexScansFolder.objects.filter(walletname=refscan)
@@ -116,7 +117,7 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines):
continue
# detect the star command
- mstar = re.match('\s*\*[\s,]*(\w+)\s*(.*?)\s*(?:;.*)?$', sline)
+ mstar = re.match(r'\s*\*[\s,]*(\w+)\s*(.*?)\s*(?:;.*)?$', sline)
if not mstar:
if "from" in stardata:
LoadSurvexLineLeg(survexblock, stardata, sline, comment)
@@ -129,7 +130,7 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines):
cmd, line = mstar.groups()
cmd = cmd.lower()
if re.match("include$(?i)", cmd):
- includepath = os.path.join(os.path.split(survexfile.path)[0], re.sub("\.svx$", "", line))
+ includepath = os.path.join(os.path.split(survexfile.path)[0], re.sub(r"\.svx$", "", line))
includesurvexfile = models.SurvexFile(path=includepath, cave=survexfile.cave)
includesurvexfile.save()
includesurvexfile.SetDirectory()
@@ -157,7 +158,7 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines):
elif re.match("date$(?i)", cmd):
if len(line) == 10:
- survexblock.date = re.sub("\.", "-", line)
+ survexblock.date = re.sub(r"\.", "-", line)
expeditions = models.Expedition.objects.filter(year=line[:4])
if expeditions:
assert len(expeditions) == 1
@@ -166,9 +167,9 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines):
survexblock.save()
elif re.match("team$(?i)", cmd):
- mteammember = re.match("(Insts|Notes|Tape|Dog|Useless|Pics|Helper|Disto|Consultant)\s+(.*)$(?i)", line)
+ mteammember = re.match(r"(Insts|Notes|Tape|Dog|Useless|Pics|Helper|Disto|Consultant)\s+(.*)$(?i)", line)
if mteammember:
- for tm in re.split(" and | / |, | & | \+ |^both$|^none$(?i)", mteammember.group(2)):
+ for tm in re.split(r" and | / |, | & | \+ |^both$|^none$(?i)", mteammember.group(2)):
if tm:
personexpedition = survexblock.expedition and GetPersonExpeditionNameLookup(survexblock.expedition).get(tm.lower())
if (personexpedition, tm) not in teammembers:
@@ -206,22 +207,25 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines):
survexblock.MakeSurvexStation(line.split()[0])
else:
- if not cmd in [ "sd", "include", "units", "entrance", "data", "flags", "title", "export", "instrument", "calibrate", "set", "infer", "alias", "ref" ]:
- print ("Unrecognised command in line:", cmd, line, survexblock)
-
-
+ if cmd not in ["sd", "include", "units", "entrance", "data", "flags", "title", "export", "instrument",
+ "calibrate", "set", "infer", "alias", "ref", "cs", "declination", "case"]:
+ print("Unrecognised command in line:", cmd, line, survexblock, survexblock.survexfile.path)
-def ReloadSurvexCave(survex_cave):
- cave = models.Cave.objects.get(kataster_number=survex_cave)
+
+def ReloadSurvexCave(survex_cave, area):
+ print(survex_cave, area)
+ cave = models.Cave.objects.get(kataster_number=survex_cave, area__short_name=area)
+ print(cave)
+ #cave = models.Cave.objects.get(kataster_number=survex_cave)
cave.survexblock_set.all().delete()
cave.survexfile_set.all().delete()
cave.survexdirectory_set.all().delete()
- survexfile = models.SurvexFile(path="caves/" + survex_cave + "/" + survex_cave, cave=cave)
+ survexfile = models.SurvexFile(path="caves-" + cave.kat_area() + "/" + survex_cave + "/" + survex_cave, cave=cave)
survexfile.save()
survexfile.SetDirectory()
- survexblockroot = models.SurvexBlock(name="root", survexpath="caves", begin_char=0, cave=cave, survexfile=survexfile, totalleglength=0.0)
+ survexblockroot = models.SurvexBlock(name="root", survexpath="caves-" + cave.kat_area(), begin_char=0, cave=cave, survexfile=survexfile, totalleglength=0.0)
survexblockroot.save()
fin = survexfile.OpenFile()
textlines = [ ]
@@ -232,7 +236,7 @@ def ReloadSurvexCave(survex_cave):
def LoadAllSurvexBlocks():
- print 'Loading All Survex Blocks...'
+ print('Loading All Survex Blocks...')
models.SurvexBlock.objects.all().delete()
models.SurvexFile.objects.all().delete()
@@ -243,6 +247,8 @@ def LoadAllSurvexBlocks():
models.SurvexPersonRole.objects.all().delete()
models.SurvexStation.objects.all().delete()
+ print(" - Data flushed")
+
survexfile = models.SurvexFile(path="all", cave=None)
survexfile.save()
survexfile.SetDirectory()
@@ -259,22 +265,26 @@ def LoadAllSurvexBlocks():
#Load each cave,
#FIXME this should be dealt with load all above
+ print(" - Reloading all caves")
caves = models.Cave.objects.all()
for cave in caves:
- if cave.kataster_number and os.path.isdir(os.path.join(settings.SURVEX_DATA, "caves", cave.kataster_number)):
+ if cave.kataster_number and os.path.isdir(os.path.join(settings.SURVEX_DATA, "caves-" + cave.kat_area(), cave.kataster_number)):
if cave.kataster_number not in ['40']:
- print "loading", cave
- ReloadSurvexCave(cave.kataster_number)
-
-poslineregex = re.compile("^\(\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*)\s*\)\s*([^\s]+)$")
+ print("loading", cave, cave.kat_area())
+ ReloadSurvexCave(cave.kataster_number, cave.kat_area())
+
+
+poslineregex = re.compile(r"^\(\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*)\s*\)\s*([^\s]+)$")
+
+
def LoadPos():
- print 'Loading Pos....'
+ print('Loading Pos....')
call([settings.CAVERN, "--output=%s/all.3d" % settings.SURVEX_DATA, "%s/all.svx" % settings.SURVEX_DATA])
call([settings.THREEDTOPOS, '%sall.3d' % settings.SURVEX_DATA], cwd = settings.SURVEX_DATA)
posfile = open("%sall.pos" % settings.SURVEX_DATA)
- posfile.readline()#Drop header
+ posfile.readline() #Drop header
for line in posfile.readlines():
r = poslineregex.match(line)
if r:
@@ -286,4 +296,4 @@ def LoadPos():
ss.z = float(z)
ss.save()
except:
- print "%s not parsed in survex" % name
+ print("%s not parsed in survex" % name)