2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00

update svx template & fix CRLF

This commit is contained in:
Philip Sargent 2020-06-02 21:38:29 +01:00
parent 4dd0a5ddf2
commit 973c6f4ef8

View File

@ -18,46 +18,74 @@ from troggle.parsers.people import GetPersonExpeditionNameLookup
survextemplatefile = """; Locn: Totes Gebirge, Austria - Loser/Augst-Eck Plateau (kataster group 1623)
; Cave:
survextemplatefile = """; *** DO NOT SAVE THIS FILE WITHOUT RENAMING IT !! ***
;[Stuff in square brackets is example text to be replaced with real data,
; removing the square brackets]
*begin [surveyname]
*export [connecting stations]
; stations linked into other surveys (or likely to)
*export [1 8 12 34]
*title "area title"
*date 2099.99.99
*team Insts [Caver]
*team Insts [Caver]
*team Notes [Caver]
*instrument [set number]
; Cave:
; Area in cave/QM:
*title ""
*date [2040.07.04]
*team Insts [Fred Foo]
*team Notes [Brenda Bar]
*team Pics [Brenda Bar]
*team Tape [Albert Anyone]
*instrument [SAP #+Laser Tape/DistoX/Compass # ; Clino #]
; Calibration: [Where, readings]
*ref 2040#00
; the #number is on the clear pocket containing the original notes
*ref: 2099#NN
; if using a tape:
*calibrate tape +0.0 ; +ve if tape was too short, -ve if too long
*calibrate tape +0.0 ; +ve if tape was too short, -ve if too long
; Centreline data
*data normal from to length bearing gradient ignoreall
[ 1 2 5.57 034.5 -12.8 ]
*data normal from to tape compass clino
1 2 3.90 298 -20
;-----------
;recorded station details (leave commented out)
;(NP=Nail Polish, LHW/RHW=Left/Right Hand Wall)
;Station Left Right Up Down Description
;[Red] nail varnish markings
[;1 0.8 0 5.3 1.6 ; NP on boulder. pt 23 on foo survey ]
[;2 0.3 1.2 6 1.2 ; NP '2' LHW ]
[;3 1.3 0 3.4 0.2 ; Rock on floor - not refindable ]
*data passage station left right up down ignoreall
1 [L] [R] [U] [D] comment
*end [surveyname]"""
;LRUDs arranged into passage tubes
;new *data command for each 'passage',
;repeat stations and adjust numbers as needed
*data passage station left right up down
;[ 1 0.8 0 5.3 1.6 ]
;[ 2 0.3 1.2 6 1.2 ]
*data passage station left right up down
;[ 1 1.3 1.5 5.3 1.6 ]
;[ 3 2.4 0 3.4 0.2 ]
def ReplaceTabs(stext):
res = [ ]
nsl = 0
for s in re.split("(\t|\n)", stext):
if s == "\t":
res.append(" " * (4 - (nsl % 4)))
nsl = 0
continue
if s == "\n":
nsl = 0
else:
nsl += len(s)
res.append(s)
return "".join(res)
;-----------
;Question Mark List ;(leave commented-out)
; The nearest-station is the name of the survey and station which are nearest to
; the QM. The resolution-station is either '-' to indicate that the QM hasn't
; been checked; or the name of the survey and station which push that QM. If a
; QM doesn't go anywhere, set the resolution-station to be the same as the
; nearest-station. Include any relevant details of how to find or push the QM in
; the textual description.
;Serial number grade(A/B/C/X) nearest-station resolution-station description
;[ QM1 A surveyname.3 - description of QM ]
;[ QM2 B surveyname.5 - description of QM ]
;------------
;Cave description ;(leave commented-out)
;freeform text describing this section of the cave
*end [surveyname]
"""
class SvxForm(forms.Form):
@ -71,9 +99,8 @@ class SvxForm(forms.Form):
fname = settings.SURVEX_DATA + self.data['filename'] + ".svx"
if not os.path.isfile(fname):
return survextemplatefile
fin = open(fname, "rb")
svxtext = fin.read().decode("latin1") # unicode(a, "latin1")
svxtext = ReplaceTabs(svxtext).strip()
fin = open(fname, "rt",encoding='utf8',newline='')
svxtext = fin.read()
fin.close()
return svxtext
@ -86,19 +113,19 @@ class SvxForm(forms.Form):
def SaveCode(self, rcode):
fname = settings.SURVEX_DATA + self.data['filename'] + ".svx"
if not os.path.isfile(fname):
# only save if appears valid
if re.search(r"\[|\]", rcode):
return "Error: clean up all []s from the text"
return "Error: remove all []s from the text. They are only template guidance."
mbeginend = re.search(r"(?s)\*begin\s+(\w+).*?\*end\s+(\w+)", rcode)
if not mbeginend:
return "Error: no begin/end block here"
if mbeginend.group(1) != mbeginend.group(2):
return "Error: mismatching beginend"
return "Error: mismatching begin/end labels"
fout = open(fname, "wb")
res = fout.write(rcode.encode("latin1"))
fout = open(fname, "wt", encoding='utf8',newline='\n')
# javascript seems to insert CRLF on WSL1.
res = fout.write(rcode.replace("\r",""))
fout.close()
return "SAVED"
return "SAVED ."
def Process(self):
print("....\n\n\n....Processing\n\n\n")
@ -106,10 +133,10 @@ class SvxForm(forms.Form):
os.chdir(os.path.split(settings.SURVEX_DATA + self.data['filename'])[0])
os.system(settings.CAVERN + " --log " + settings.SURVEX_DATA + self.data['filename'] + ".svx")
os.chdir(cwd)
fin = open(settings.SURVEX_DATA + self.data['filename'] + ".log", "rb")
fin = open(settings.SURVEX_DATA + self.data['filename'] + ".log", "rt",encoding='utf8')
log = fin.read()
fin.close()
log = re.sub(b"(?s).*?(Survey contains)", "\\1", log)
log = re.sub("(?s).*?(Survey contains)", "\\1", log)
return log
@ -181,7 +208,7 @@ def svx(request, survex_file):
return render_to_response('svxfile.html', vmap)
def svxraw(request, survex_file):
svx = open(os.path.join(settings.SURVEX_DATA, survex_file+".svx"), "rb")
svx = open(os.path.join(settings.SURVEX_DATA, survex_file+".svx"), "rt",encoding='utf8')
return HttpResponse(svx, content_type="text")
@ -196,20 +223,20 @@ def process(survex_file):
def threed(request, survex_file):
process(survex_file)
try:
threed = open(settings.SURVEX_DATA + survex_file + ".3d", "rb")
threed = open(settings.SURVEX_DATA + survex_file + ".3d", "rt",encoding='utf8')
return HttpResponse(threed, content_type="model/3d")
except:
log = open(settings.SURVEX_DATA + survex_file + ".log", "rb")
log = open(settings.SURVEX_DATA + survex_file + ".log", "rt",encoding='utf8')
return HttpResponse(log, content_type="text")
def log(request, survex_file):
process(survex_file)
log = open(settings.SURVEX_DATA + survex_file + ".log", "rb")
log = open(settings.SURVEX_DATA + survex_file + ".log", "rt",encoding='utf8')
return HttpResponse(log, content_type="text")
def err(request, survex_file):
process(survex_file)
err = open(settings.SURVEX_DATA + survex_file + ".err", "rb")
err = open(settings.SURVEX_DATA + survex_file + ".err", "rt",encoding='utf8')
return HttpResponse(err, content_type="text")