diff options
author | goatchurch <goatchurch@ubuntu.clocksoft.dom> | 2009-09-13 17:27:46 +0100 |
---|---|---|
committer | goatchurch <goatchurch@ubuntu.clocksoft.dom> | 2009-09-13 17:27:46 +0100 |
commit | 517d29163669de836f631fa17855a0b5cd914660 (patch) | |
tree | 76f89ac86e61547b52793719f236fa0da9bab792 | |
parent | 12cf3a6d534e5038b5d78b11a03cef2b81f5f852 (diff) | |
download | troggle-517d29163669de836f631fa17855a0b5cd914660.tar.gz troggle-517d29163669de836f631fa17855a0b5cd914660.tar.bz2 troggle-517d29163669de836f631fa17855a0b5cd914660.zip |
able to save sketches up from tunnel
-rw-r--r-- | core/models_survex.py | 4 | ||||
-rw-r--r-- | core/view_surveys.py | 45 | ||||
-rw-r--r-- | databaseReset.py | 2 | ||||
-rw-r--r-- | parsers/surveys.py | 37 | ||||
-rw-r--r-- | templates/tunnelfiles.html | 8 | ||||
-rw-r--r-- | urls.py | 3 |
6 files changed, 84 insertions, 15 deletions
diff --git a/core/models_survex.py b/core/models_survex.py index 9fd23c4..2828389 100644 --- a/core/models_survex.py +++ b/core/models_survex.py @@ -173,5 +173,9 @@ class TunnelFile(models.Model): survexscans = models.ManyToManyField("SurvexScanSingle")
survexblocks = models.ManyToManyField("SurvexBlock")
tunnelcontains = models.ManyToManyField("TunnelFile") # case when its a frame type
+ filesize = models.IntegerField(default=0)
+ npaths = models.IntegerField(default=0)
+ class Meta:
+ ordering = ('tunnelpath',)
\ No newline at end of file diff --git a/core/view_surveys.py b/core/view_surveys.py index 0324b24..fc93a7e 100644 --- a/core/view_surveys.py +++ b/core/view_surveys.py @@ -2,7 +2,7 @@ from django.conf import settings import fileAbstraction
from django.shortcuts import render_to_response
from django.http import HttpResponse, Http404
-import os
+import os, stat
import re
from troggle.core.models import SurvexScansFolder, SurvexScanSingle, SurvexBlock, TunnelFile
@@ -181,4 +181,45 @@ def surveyscansfolders(request): def tunneldata(request):
tunnelfiles = TunnelFile.objects.all()
return render_to_response('tunnelfiles.html', { 'tunnelfiles':tunnelfiles, 'settings': settings })
-
\ No newline at end of file +
+def tunnelfile(request, path):
+ tunnelfile = TunnelFile.objects.get(tunnelpath=path)
+ tfile = os.path.join(settings.TUNNEL_DATA, tunnelfile.tunnelpath)
+
+ # just output the file
+ if not request.POST:
+ return HttpResponse(content=open(tfile), mimetype="text/plain")
+
+ 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")
+
+ orgsize = tunnelfile.filesize # = os.stat(tfile)[stat.ST_SIZE]
+
+ 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
+ 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")
+
+
+
+
diff --git a/databaseReset.py b/databaseReset.py index 6c635d1..6e049b6 100644 --- a/databaseReset.py +++ b/databaseReset.py @@ -77,7 +77,7 @@ def parse_descriptions(): def import_tunnelfiles():
import parsers.surveys
- parsers.surveys.LoadTunnelFiles(settings.TUNNEL_DATA)
+ parsers.surveys.LoadTunnelFiles()
def reset():
diff --git a/parsers/surveys.py b/parsers/surveys.py index 86f6405..cffeb4a 100644 --- a/parsers/surveys.py +++ b/parsers/surveys.py @@ -1,4 +1,4 @@ -import sys, os, types, logging
+import sys, os, types, logging, stat
#sys.path.append('C:\\Expo\\expoweb')
#from troggle import *
#os.environ['DJANGO_SETTINGS_MODULE']='troggle.settings'
@@ -204,7 +204,30 @@ def LoadListScans(surveyscansdir): -def LoadTunnelFiles(tunneldatadir):
+def SetTunnelfileInfo(tunnelfile):
+ ff = os.path.join(settings.TUNNEL_DATA, tunnelfile.tunnelpath)
+ tunnelfile.filesize = os.stat(ff)[stat.ST_SIZE]
+ fin = open(ff)
+ ttext = fin.read()
+ fin.close()
+
+ mtype = re.search("<(fontcolours|sketch)", ttext)
+ assert mtype, ff
+ tunnelfile.bfontcolours = (mtype.group(1)=="fontcolours")
+ tunnelfile.npaths = len(re.findall("<skpath", ttext))
+ tunnelfile.save()
+
+ # <tunnelxml tunnelversion="version2009-06-21 Matienzo" tunnelproject="ireby" tunneluser="goatchurch" tunneldate="2009-06-29 23:22:17">
+ # <pcarea area_signal="frame" sfscaledown="12.282584" sfrotatedeg="-90.76982" sfxtrans="11.676667377221136" sfytrans="-15.677173422877454" sfsketch="204description/scans/plan(38).png" sfstyle="" nodeconnzsetrelative="0.0">
+ print tunnelfile.tunnelpath, re.findall('<pcarea area_signal="frame".*?sfsketch="([^"]*)" sfstyle="([^"]*)"', ttext)
+# npaths = models.IntegerField()
+# survexscans = models.ManyToManyField("SurvexScanSingle")
+# survexblocks = models.ManyToManyField("SurvexBlock")
+# tunnelcontains = models.ManyToManyField("TunnelFile") # case when its a frame type
+
+
+def LoadTunnelFiles():
+ tunneldatadir = settings.TUNNEL_DATA
TunnelFile.objects.all().delete()
tunneldirs = [ "" ]
while tunneldirs:
@@ -217,16 +240,10 @@ def LoadTunnelFiles(tunneldatadir): if os.path.isdir(ff):
tunneldirs.append(lf)
elif f[-4:] == ".xml":
- fin = open(ff)
- mtype = re.search("<(fontcolours|sketch)", fin.read(200))
- assert mtype, lf
- fin.close()
- tunnelfile = TunnelFile(tunnelpath=lf, bfontcolours=(mtype.group(1)=="fontcolours"))
+ tunnelfile = TunnelFile(tunnelpath=lf)
tunnelfile.save()
+ SetTunnelfileInfo(tunnelfile)
-# survexscans = models.ManyToManyField("SurvexScanSingle")
-# survexblocks = models.ManyToManyField("SurvexBlock")
-# tunnelcontains = models.ManyToManyField("TunnelFile") # case when its a frame type
diff --git a/templates/tunnelfiles.html b/templates/tunnelfiles.html index 34afc28..8b80ade 100644 --- a/templates/tunnelfiles.html +++ b/templates/tunnelfiles.html @@ -8,11 +8,15 @@ <h3>All Tunnel files</h3>
<table>
-<tr><th>File</th><th>Font</th><th>Frame</th><th>SurvexBlocks</th><th>Size</th></tr>
+<tr><th>File</th><th>Font</th><th>Frame</th><th>SurvexBlocks</th><th>Size</th><th>Paths</td></tr>
{% for tunnelfile in tunnelfiles %}
<tr>
- <td>{{tunnelfile.tunnelpath}}</td>
+ <td><a href="{% url tunnelfile tunnelfile.tunnelpath %}">{{tunnelfile.tunnelpath}}</a></td>
<td>{{tunnelfile.bfontcolours}}</td>
+ <td></td>
+ <td></td>
+ <td>{{tunnelfile.filesize}}</td>
+ <td>{{tunnelfile.npaths}}</td>
</tr>
{% endfor %}
</table>
@@ -108,7 +108,10 @@ urlpatterns = patterns('', url(r'^survey_scans/(?P<path>[^/]+)/$', view_surveys.surveyscansfolder, name="surveyscansfolder"),
url(r'^survey_scans/(?P<path>[^/]+)/(?P<file>[^/]+(?:png|jpg))$',
view_surveys.surveyscansingle, name="surveyscansingle"),
+
url(r'^tunneldata/$', view_surveys.tunneldata, name="tunneldata"),
+ url(r'^tunneldataraw/(?P<path>.+?\.xml)$', view_surveys.tunnelfile, name="tunnelfile"),
+ #url(r'^tunneldatainfo/(?P<path>.+?\.xml)$', view_surveys.tunnelfileinfo, name="tunnelfileinfo"),
(r'^photos/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.PHOTOS_ROOT, 'show_indexes':True}),
|