2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-17 09:47:24 +00:00

make 2008 logbook correctly parse

This commit is contained in:
goatchurch
2009-09-14 22:52:46 +01:00
parent 517d291636
commit 24d90bae75
8 changed files with 157 additions and 63 deletions

View File

@@ -5,6 +5,7 @@ from django.http import HttpResponse, Http404
import os, stat
import re
from troggle.core.models import SurvexScansFolder, SurvexScanSingle, SurvexBlock, TunnelFile
import parsers.surveys
# inline fileabstraction into here if it's not going to be useful anywhere else
# keep things simple and ignore exceptions everywhere for now
@@ -182,43 +183,50 @@ def tunneldata(request):
tunnelfiles = TunnelFile.objects.all()
return render_to_response('tunnelfiles.html', { 'tunnelfiles':tunnelfiles, 'settings': settings })
def tunnelfile(request, path):
tunnelfile = TunnelFile.objects.get(tunnelpath=path)
tfile = os.path.join(settings.TUNNEL_DATA, tunnelfile.tunnelpath)
return HttpResponse(content=open(tfile), mimetype="text/plain")
# just output the file
if not request.POST:
return HttpResponse(content=open(tfile), mimetype="text/plain")
def tunnelfileupload(request, path):
tunnelfile = TunnelFile.objects.get(tunnelpath=path)
tfile = os.path.join(settings.TUNNEL_DATA, tunnelfile.tunnelpath)
project, user, password, tunnelversion = request.POST["tunnelproject"], request.POST["tunneluser"], request.POST["tunnelpassword"], request.POST["tunnelversion"]
print (project, user, tunnelversion)
for uploadedfile in request.FILES.values():
if uploadedfile.field_name != "sketch":
return HttpResponse(content="Error: non-sketch file uploaded", mimetype="text/plain")
if uploadedfile.content_type != "text/plain":
return HttpResponse(content="Error: non-plain content type", mimetype="text/plain")
# could use this to add new files
if os.path.split(path)[1] != uploadedfile.name:
return HttpResponse(content="Error: name disagrees", mimetype="text/plain")
assert len(request.FILES.values()) == 1, "only one file to upload"
uploadedfile = request.FILES.values()[0]
orgsize = tunnelfile.filesize # = os.stat(tfile)[stat.ST_SIZE]
ttext = uploadedfile.read()
if uploadedfile.field_name != "sketch":
return HttpResponse(content="Error: non-sketch file uploaded", mimetype="text/plain")
if uploadedfile.content_type != "text/plain":
return HttpResponse(content="Error: non-plain content type", mimetype="text/plain")
# could check that the user and projects agree here
# could use this to add new files
if os.path.split(path)[1] != uploadedfile.name:
return HttpResponse(content="Error: name disagrees", mimetype="text/plain")
orgsize = tunnelfile.filesize # = os.stat(tfile)[stat.ST_SIZE]
fout = open(tfile, "w")
fout.write(ttext)
fout.close()
# redo its settings of
tunnelfile.filesize = os.stat(tfile)[stat.ST_SIZE]
tunnelfile.save()
uploadedfile.close()
message = "File size %d overwritten with size %d" % (orgsize, tunnelfile.filesize)
return HttpResponse(content=message, mimetype="text/plain")
ttext = uploadedfile.read()
# could check that the user and projects agree here
fout = open(tfile, "w")
fout.write(ttext)
fout.close()
# redo its settings of
parsers.surveys.SetTunnelfileInfo(tunnelfile)
tunnelfile.save()
uploadedfile.close()
message = "File size %d overwritten with size %d" % (orgsize, tunnelfile.filesize)
return HttpResponse(content=message, mimetype="text/plain")