summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--expo/views_survex.py141
-rw-r--r--media/css/main2.css11
-rw-r--r--parsers/logbooks.py9
-rw-r--r--templates/index.html6
-rw-r--r--templates/svxfile.html90
-rw-r--r--urls.py5
6 files changed, 229 insertions, 33 deletions
diff --git a/expo/views_survex.py b/expo/views_survex.py
index 067d4e3..554ad4f 100644
--- a/expo/views_survex.py
+++ b/expo/views_survex.py
@@ -1,20 +1,143 @@
+from django import forms
+from django.http import HttpResponseRedirect, HttpResponse
from django.shortcuts import render_to_response
from django.http import HttpResponse, Http404
import re
import os
+import datetime
+import difflib
import troggle.settings as settings
-def index(request, survex_file):
- process(survex_file)
- f = open(settings.SURVEX_DATA + survex_file + ".svx", "rb")
- a = f.read()
- return render_to_response('svxfile.html', {'settings': settings,
- 'has_3d': os.path.isfile(settings.SURVEX_DATA + survex_file + ".3d"),
- 'title': survex_file,
- 'text': unicode(a, "latin1")})
+
+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)
+
+
+class SvxForm(forms.Form):
+ dirname = forms.CharField(widget=forms.TextInput(attrs={"readonly":True}))
+ filename = forms.CharField(widget=forms.TextInput(attrs={"readonly":True}))
+ datetime = forms.DateTimeField(widget=forms.TextInput(attrs={"readonly":True}))
+ outputtype = forms.CharField(widget=forms.TextInput(attrs={"readonly":True}))
+ code = forms.CharField(widget=forms.Textarea(attrs={"cols":150, "rows":18}))
+
+ def GetDiscCode(self):
+ fname = settings.SURVEX_DATA + self.data['filename'] + ".svx"
+ if not os.path.isfile(fname):
+ return None
+ fin = open(fname, "rb")
+ svxtext = fin.read().decode("latin1") # unicode(a, "latin1")
+ svxtext = ReplaceTabs(svxtext).strip()
+ fin.close()
+ return svxtext
+
+ def DiffCode(self, rcode):
+ code = self.GetDiscCode()
+ difftext = difflib.unified_diff(code.splitlines(), rcode.splitlines())
+ difflist = [ diffline.strip() for diffline in difftext if not re.match("\s*$", diffline) ]
+ return difflist
+
+ def SaveCode(self, rcode):
+ fname = settings.SURVEX_DATA + self.data['filename'] + ".svx"
+ if not os.path.isfile(fname):
+ return False
+ fout = open(fname, "w")
+ res = fout.write(rcode.encode("latin1"))
+ fout.close()
+ return True
+
+ def Process(self):
+ print "....\n\n\n....Processing\n\n\n"
+ cwd = os.getcwd()
+ 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")
+ log = fin.read()
+ fin.close()
+ log = re.sub("(?s).*?(Survey contains)", "\\1", log)
+ return log
+
def svx(request, survex_file):
+ # get the basic data from the file given in the URL
+ dirname = os.path.split(survex_file)[0]
+ if dirname:
+ dirname += "/"
+ nowtime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+ outputtype = "normal"
+ form = SvxForm({'filename':survex_file, 'dirname':dirname, 'datetime':nowtime, 'outputtype':outputtype})
+
+ # if the form has been returned
+ difflist = [ ]
+ logmessage = ""
+ message = ""
+
+ if request.method == 'POST': # If the form has been submitted...
+ rform = SvxForm(request.POST) #
+ if rform.is_valid(): # All validation rules pass (how do we check it against the filename and users?)
+ rcode = rform.cleaned_data['code']
+ outputtype = rform.cleaned_data['outputtype']
+ difflist = form.DiffCode(rcode)
+ print "ssss", rform.data
+
+ if "revert" in rform.data:
+ pass
+ if "process" in rform.data:
+ if not difflist:
+ message = "OUTPUT FROM PROCESSING"
+ logmessage = form.Process()
+ print logmessage
+ else:
+ message = "SAVE FILE FIRST"
+ form.data['code'] = rcode
+ if "save" in rform.data:
+ print "sssavvving"
+ if form.SaveCode(rcode):
+ message = "SAVVVED"
+ # we will reload later
+ else:
+ message = "FAILED TO SAVE"
+ form.data['code'] = rcode
+ if "diff" in rform.data:
+ form.data['code'] = rcode
+
+
+ #process(survex_file)
+ if 'code' not in form.data:
+ form.data['code'] = form.GetDiscCode()
+
+ if not difflist:
+ difflist.append("none")
+ if message:
+ difflist.insert(0, message)
+
+ svxincludes = re.findall('\*include\s+"?(.*?)(?:\.svx)?"?\s*?\n(?i)', form.data['code'])
+
+ vmap = {'settings': settings,
+ 'has_3d': os.path.isfile(settings.SURVEX_DATA + survex_file + ".3d"),
+ 'title': survex_file,
+ 'svxincludes': svxincludes,
+ 'difflist': difflist,
+ 'logmessage':logmessage,
+ 'form':form}
+ if outputtype == "ajax":
+ return render_to_response('svxfiledifflistonly.html', vmap)
+ return render_to_response('svxfile.html', vmap)
+
+def Dsvx(request, survex_file):
svx = open(settings.SURVEX_DATA + survex_file + ".svx", "rb")
return HttpResponse(svx, mimetype="text")
@@ -40,5 +163,5 @@ def err(request, survex_file):
def process(survex_file):
cwd = os.getcwd()
os.chdir(os.path.split(settings.SURVEX_DATA + survex_file)[0])
- os.system(settings.CAVERN + " --log " +settings.SURVEX_DATA + survex_file + ".svx")
+ os.system(settings.CAVERN + " --log " + settings.SURVEX_DATA + survex_file + ".svx")
os.chdir(cwd)
diff --git a/media/css/main2.css b/media/css/main2.css
index fee993c..caa6310 100644
--- a/media/css/main2.css
+++ b/media/css/main2.css
@@ -336,4 +336,13 @@ img.thumbnail {
}
br.clearfloat {
clear:both;
-} \ No newline at end of file
+}
+
+div.codeframebit
+{
+ border:thin black dotted;
+}
+.CodeMirror-line-numbers
+{
+ background-color: #bbb;
+}
diff --git a/parsers/logbooks.py b/parsers/logbooks.py
index 281a1b2..ebfd54e 100644
--- a/parsers/logbooks.py
+++ b/parsers/logbooks.py
@@ -166,7 +166,7 @@ def Parseloghtml01(year, expedition, txt):
tripparas = re.findall("<hr[\s/]*>([\s\S]*?)(?=<hr)", txt)
for trippara in tripparas:
s = re.match(u"(?s)\s*(?:<p>)?(.*?)</?p>(.*)$(?i)", trippara)
- assert s, trippara[:100]
+ assert s, trippara[:300]
tripheader, triptext = s.group(1), s.group(2)
mtripid = re.search('<a id="(.*?)"', tripheader)
tripid = mtripid and mtripid.group(1) or ""
@@ -177,7 +177,7 @@ def Parseloghtml01(year, expedition, txt):
tripdate, triptitle, trippeople = tripheader.split("|")
ldate = ParseDate(tripdate.strip(), year)
-
+
mtu = re.search('<p[^>]*>(T/?U.*)', triptext)
if mtu:
tu = mtu.group(1)
@@ -203,9 +203,9 @@ def Parseloghtml01(year, expedition, txt):
ltriptext = re.sub("</?b>", "'''", ltriptext)
- #print ldate, trippeople.strip()
+ print ldate, trippeople.strip()
# could includ the tripid (url link for cross referencing)
- EnterLogIntoDbase(date = ldate, place = tripcave, title = triptitle, text = ltriptext, trippeople=trippeople, expedition=expedition, logtime_underground=0)
+ EnterLogIntoDbase(date=ldate, place=tripcave, title=triptitle, text=ltriptext, trippeople=trippeople, expedition=expedition, logtime_underground=0)
def Parseloghtml03(year, expedition, txt):
@@ -254,6 +254,7 @@ yearlinks = [
("1995", "1995/log.htm", Parseloghtml01),
("1994", "1994/log.htm", Parseloghtml01),
("1993", "1993/log.htm", Parseloghtml01),
+ ("1992", "1992/log.htm", Parseloghtml01),
]
def SetDatesFromLogbookEntries(expedition):
diff --git a/templates/index.html b/templates/index.html
index 1c9fd3b..525b2d9 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -12,16 +12,16 @@
<li><b><a href="{% url caveindex %}">List of Caves</a></b></li>
<li><a href="{% url jgtfile aaaa %}">JGT list of files</a> (temporary simple file list and tunnel use)</li>
<li><a href="{% url survey %}">Survey files</a></li>
- <li><a href="{% url survexindex all %}">Survex directory</a></li>
+ <li><a href="{% url svx all %}">Survex directory</a></li>
<li><a href="{% url expedition 2008 %}">Expedition 2008</a></li>
<li><a href="{% url expedition 2007 %}">Expedition 2007</a></li>
- <li><a href="{% url expedition 1993 %}">Expedition 1993</a> (earliest parsed)</li>
+ <li><a href="{% url expedition 1992 %}">Expedition 1992</a> (earliest parsed)</li>
</ul>
<h2>Further work</h2>
<p>Julian's work:
-<p>parse 1992-1976 logbooks; (esp top 161)</p>
+<p>parse 1976-1991 logbooks; (esp top 161)</p>
<p>detect T/U on log entries; </p>
<p>name matching and spelling in survex files; </p>
<p>Improve logbook wikihtml text</p>
diff --git a/templates/svxfile.html b/templates/svxfile.html
index 1fc4e1b..601d6ba 100644
--- a/templates/svxfile.html
+++ b/templates/svxfile.html
@@ -2,18 +2,80 @@
{% load survex_markup %}
{% block title %}{{ title }}{% endblock %}
+
+{% block head %}
+<script src="{{ settings.MEDIA_URL }}js/base.js" type="text/javascript"></script>
+<script type="text/javascript" src="{{settings.MEDIA_URL}}js/jquery-1.3.2.js"></script>
+<script type="text/javascript" src="{{settings.MEDIA_URL}}js/jquery.form.js"></script>
+<script type="text/javascript" src="{{settings.MEDIA_URL}}CodeMirror-0.62/js/codemirror.js"></script>
+
+<script type="text/javascript">
+var codeeditor;
+$(document).ready(function()
+{
+ codeeditor = CodeMirror.fromTextArea("id_code",
+ {
+ parserfile: ["parsesurvex.js"],
+ stylesheet: "{{settings.MEDIA_URL}}CodeMirror-0.62/css/survexcolors.css",
+ path: "{{settings.MEDIA_URL}}CodeMirror-0.62/js/",
+ textWrapping: false,
+ lineNumbers: true,
+ indentUnit: 4,
+ tabMode: "spaces"
+ });
+ $("#id_outputtype").val("ajax");
+ var options =
+ {
+ target: '#difflistajax',
+ beforeSubmit: function() { $("textarea#id_code").value = codeeditor.getCode().length; },
+ success: function() { codeeditor.focus(); }
+ };
+ $('#codewikiform').ajaxForm(options); // bind form using 'ajaxForm'
+});
+
+</script>
+{% endblock %}
+
{% block content %}
- <H1>{{ title }}</H1>
-
- <div><a href="{{ settings.SVX_URL }}{{ title }}.svx">Download svx file</a></div>
- {% if has_3d %}
- <div><a href="{{ settings.SVX_URL }}{{ title }}.3d">Download 3d file</a></div>
- <div><a href="{{ settings.SVX_URL }}{{ title }}.err">Download err file</a></div>
- {% else %}
- <div>Processing failed</div>
- {% endif %}
- <div><a href="{{ settings.SVX_URL }}{{ title }}.log">Download log file</a></div>
-
- {{ text|survex_to_html }}
-
-{% endblock %} \ No newline at end of file
+<h1>Survex File: {{ title }} .svx</h1>
+
+<form id="codewikiform" action="" method="POST">
+ <div style="display:none">{{form.filename}} {{form.dirname}} {{form.datetime}} {{form.outputtype}}</div>
+ <input type="submit" name="diff" value="Diffy" />
+ <input type="submit" name="save" value="Save"/>
+ <input type="submit" name="revert" value="Revert"/>
+ <input type="submit" name="process" value="Process" title="executes cavern"/>
+ (Not implemented: <input type="submit" name="svncheckin" value="svn check-in"/>)
+ <div class="codeframebit">{{form.code}}</div>
+</form>
+
+<h4>Output</h4>
+
+<div id="difflistajax">
+<pre>
+{% for diffline in difflist %}{{diffline}}
+{% endfor %}
+</pre>
+
+{% if logmessage %}
+{% if has_3d %}
+<p><a href="{{ settings.SVX_URL }}{{ title }}.3d">3d file</a></p>
+{% else %}
+<p><b>No 3d file</b></p>
+{% endif %}
+<pre>
+LOGMESSAGES
+{{logmessage}}
+</pre>
+{% endif %}
+</div>
+
+{% if svxincludes %}
+<p><b>Included files:</b>
+{% for svxinclude in svxincludes %}
+ <a href="{{svxinclude}}.svx">{{svxinclude}}</a>
+{% endfor %}
+</p>
+{% endif %}
+
+{% endblock %}
diff --git a/urls.py b/urls.py
index fc2b7a2..8636b4b 100644
--- a/urls.py
+++ b/urls.py
@@ -39,10 +39,11 @@ urlpatterns = patterns('',
#(r'^cave/(?P<cave_id>[^/]+)/edit/$', edit_cave),
#(r'^cavesearch', caveSearch),
- url(r'^survex/(.*?)\.index$', views_survex.index, name="survexindex"),
url(r'^cave/(?P<cave_id>[^/]+)/(?P<year>\d\d\d\d)-(?P<qm_id>\d\d)(?P<grade>[ABCDX]?)?$', views_caves.qm, name="qm"),
- (r'^survex/(?P<survex_file>.*)\.svx$', svx),
+
+ #url(r'^survex/(.*?)\.index$', views_survex.index, name="survexindex"),
+ url(r'^survex/(?P<survex_file>.*?)\.svx$', svx, name="svx"),
(r'^survex/(?P<survex_file>.*)\.3d$', threed),
(r'^survex/(?P<survex_file>.*)\.log$', log),
(r'^survex/(?P<survex_file>.*)\.err$', err),