summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parsers/survex.py70
-rw-r--r--templates/svxcavesingle.html14
2 files changed, 50 insertions, 34 deletions
diff --git a/parsers/survex.py b/parsers/survex.py
index 4d47d7b..460fc3f 100644
--- a/parsers/survex.py
+++ b/parsers/survex.py
@@ -43,12 +43,21 @@ class LoadingSurvex():
rx_qm = re.compile(r'(?i)^\s*QM(\d)\s+?([a-dA-DxX])\s+([\w\-]+)\.(\d+)\s+(([\w\-]+)\.(\d+)|\-)\s+(.+)$')
# remember there is also QM_PATTERN used in views_other and set in settings.py
+ rx_begin = re.compile(r'(?i)begin')
+ rx_end = re.compile(r'(?i)end$')
+ rx_title = re.compile(r'(?i)title$')
+ rx_ref = re.compile(r'(?i)ref$')
+ rx_data = re.compile(r'(?i)data$')
+ rx_flags = re.compile(r'(?i)flags$')
+
rx_cave = re.compile(r'(?i)caves-(\d\d\d\d)/([-\d\w]+|\d\d\d\d-?\w+-\d+)')
rx_comment = re.compile(r'([^;]*?)\s*(?:;\s*(.*))?\n?$')
rx_comminc = re.compile(r'(?i)^\*include[\s]*([-\w/]*).*$') # inserted by linear collate ;*include
rx_commcni = re.compile(r'(?i)^\*edulcni[\s]*([-\w/]*).*$') # inserted by linear collate ;*edulcni
rx_include = re.compile(r'(?i)^\s*(\*include[\s].*)$')
- rx_ref = re.compile(r'(?i)^\s*ref(erence)?[\s.:]*(\d+)\s*#\s*(X)?\s*(\d+)')
+ rx_commref = re.compile(r'(?i)^\s*ref(?:erence)?[\s.:]*(\d+)\s*#\s*(X)?\s*(\d+)')
+ rx_wallet = re.compile(r'(?i)^\s*wallet[\s.:]*(\d+)\s*#\s*(X)?\s*(\d+)')
+ rx_implicit= re.compile(r'(?i)^[\s.:]*(\d+)\s*#\s*(X)?\s*(\d+)')
rx_ref_text= re.compile(r'(?i)^\s*\"[^"]*\"\s*$')
rx_star = re.compile(r'(?i)\s*\*[\s,]*(\w+)\s*(.*?)\s*(?:;.*)?$')
rx_starref = re.compile(r'(?i)^\s*\*ref[\s.:]*((?:19[6789]\d)|(?:20[0123]\d))\s*#?\s*(X)?\s*(.*?\d+.*?)$')
@@ -91,7 +100,7 @@ class LoadingSurvex():
self.caveslist = GetCaveLookup()
pass
- def LoadSurvexIgnore(self, survexblock, line, cmd):
+ def LoadSurvexFallThrough(self, survexblock, line, cmd):
if cmd == "require":
pass # should we check survex version available for processing?
elif cmd in ["equate", "fix", "calibrate", "cs", "export", "case",
@@ -280,7 +289,7 @@ class LoadingSurvex():
survexleg = None
def LoadSurvexRef(self, survexblock, args):
- print(self.insp+ "*REF ---- '"+ args +"'")
+ #print(self.insp+ "*REF ---- '"+ args +"'")
# *REF but also ; Ref years from 1960 to 2039
refline = self.rx_ref_text.match(args)
@@ -516,7 +525,7 @@ class LoadingSurvex():
depth = " " * self.depthbegin
- print("{:2}{} - NEW survexfile:'{}'".format(self.depthbegin, depth, svxid))
+ # print("{:2}{} - NEW survexfile:'{}'".format(self.depthbegin, depth, svxid))
headpath = os.path.dirname(svxid)
newfile = models_survex.SurvexFile(path=svxid)
@@ -575,11 +584,18 @@ class LoadingSurvex():
self.currentsurvexfile = self.stacksvxfiles.pop()
def LoadSurvexComment(self, survexblock, comment):
- # ignore all comments except ;ref and ;QM and ;*include (for collated survex file)
- refline = self.rx_ref.match(comment)
+ # ignore all comments except ;ref, ; wallet and ;QM and ;*include (for collated survex file)
+ refline = self.rx_commref.match(comment)
if refline:
comment = re.sub('(?i)\s*ref[.;]?',"",comment.strip())
self.LoadSurvexRef(survexblock, comment)
+ walletline = self.rx_wallet.match(comment)
+ if walletline:
+ comment = re.sub('(?i)\s*wallet[.;]?',"",comment.strip())
+ self.LoadSurvexRef(survexblock, comment)
+ implicitline = self.rx_implicit.match(comment)
+ if implicitline:
+ self.LoadSurvexRef(survexblock, comment)
qmline = self.rx_qm.match(comment)
if qmline:
@@ -654,7 +670,7 @@ class LoadingSurvex():
depth = " " * self.depthbegin
self.insp = depth
- print("{:2}{} - Begin for :'{}'".format(self.depthbegin,depth, blkid))
+ #print("{:2}{} - Begin for :'{}'".format(self.depthbegin,depth, blkid))
pathlist = ""
for id in self.stackbegin:
if len(id) > 0:
@@ -664,9 +680,9 @@ class LoadingSurvex():
nonlocal args
depth = " " * self.depthbegin
- print("{:2}{} - End from:'{}'".format(self.depthbegin,depth,args))
- print("{:2}{} - LEGS: {} (n: {}, length:{})".format(self.depthbegin,
- depth, self.slength, self.slength, self.legsnumber))
+ #print("{:2}{} - End from:'{}'".format(self.depthbegin,depth,args))
+ #print("{:2}{} - LEGS: {} (n: {}, length:{})".format(self.depthbegin,
+ # depth, self.slength, self.slength, self.legsnumber))
def pushblock():
nonlocal blkid
@@ -709,8 +725,8 @@ class LoadingSurvex():
# ------------ * FLAGS
self.flagsstar = copy.deepcopy(self.flagsstack.pop())
# ------------ * FLAGS
- if oldflags["skiplegs"] != self.flagsstar["skiplegs"]:
- print(" # POP 'any' flag now:'{}' was:{} ".format(self.flagsstar["skiplegs"], oldflags["skiplegs"]))
+ # if oldflags["skiplegs"] != self.flagsstar["skiplegs"]:
+ # print(" # POP 'any' flag now:'{}' was:{} ".format(self.flagsstar["skiplegs"], oldflags["skiplegs"]))
def starstatement(star):
nonlocal survexblock
@@ -725,7 +741,7 @@ class LoadingSurvex():
cmd = cmd.lower()
# ------------------------BEGIN
- if re.match("begin$(?i)", cmd):
+ if self.rx_begin.match(cmd):
blkid = args.lower()
# PUSH state ++++++++++++++
self.stackbegin.append(blkid)
@@ -741,13 +757,13 @@ class LoadingSurvex():
cave=self.currentcave, survexfile=self.currentsurvexfile,
legsall=0, legslength=0.0)
newsurvexblock.save()
- newsurvexblock.title = "("+survexblock.title+")" # copy parent inititally
+ newsurvexblock.title = "("+survexblock.title+")" # copy parent inititally, overwrite if it has its own
survexblock = newsurvexblock
survexblock.save() # django insists on this , but we want to save at the end !
tickle()
# ---------------------------END
- elif re.match("end$(?i)", cmd):
+ elif self.rx_end.match(cmd):
survexblock.legsall = self.legsnumber
survexblock.legslength = self.slength
printend()
@@ -776,17 +792,21 @@ class LoadingSurvex():
# POP state ++++++++++++++
# -----------------------------
- elif re.match("(?i)title$", cmd):
- survexblock.title = args # block has own title, overwrite that from parent
- elif re.match("(?i)ref$", cmd):
+ elif self.rx_title.match(cmd):
+ quotedtitle = re.match("(?i)^\"(.*)\"$",args)
+ if quotedtitle:
+ survexblock.title = quotedtitle.groups()[0]
+ else:
+ survexblock.title = args
+ elif self.rx_ref.match(cmd):
self.LoadSurvexRef(survexblock, args)
- elif re.match("(?i)flags$", cmd):
+ elif self.rx_flags.match(cmd):
oldflags = self.flagsstar
self.LoadSurvexFlags(args)
- if oldflags["skiplegs"] != self.flagsstar["skiplegs"]:
- print(" # CHANGE 'any' flag now:'{}' was:{} ".format(self.flagsstar["skiplegs"], oldflags["skiplegs"]))
+ # if oldflags["skiplegs"] != self.flagsstar["skiplegs"]:
+ # print(" # CHANGE 'any' flag now:'{}' was:{} ".format(self.flagsstar["skiplegs"], oldflags["skiplegs"]))
- elif re.match("(?i)data$", cmd):
+ elif self.rx_data.match(cmd):
self.LoadSurvexDataCmd(survexblock, args)
elif re.match("(?i)alias$", cmd):
self.LoadSurvexAlias(survexblock, args)
@@ -804,7 +824,7 @@ class LoadingSurvex():
print(message,file=sys.stderr)
models.DataIssue.objects.create(parser='survex', message=message)
else:
- self.LoadSurvexIgnore(survexblock, args, cmd)
+ self.LoadSurvexFallThrough(survexblock, args, cmd)
for svxline in svxlines:
@@ -831,7 +851,7 @@ class LoadingSurvex():
def RecursiveScan(self, survexblock, path, fin, flinear, fcollate):
"""Follows the *include links in all the survex files from the root file 1623.svx
and reads only the *include and *begin and *end statements. It produces a linearised
- list of the include tree
+ list of the include tree and detects blocks included more than once.
"""
indent = " " * self.depthinclude
sys.stderr.flush();
@@ -841,8 +861,6 @@ class LoadingSurvex():
if self.callcount % 500 ==0 :
print("\n ", file=sys.stderr,end='')
-
-
if path in self.svxfileslist:
message = " * Warning. Duplicate detected in *include list at callcount:{} depth:{} file:{}".format(self.callcount, self.depthinclude, path)
print(message)
diff --git a/templates/svxcavesingle.html b/templates/svxcavesingle.html
index b2c1096..42f3c1c 100644
--- a/templates/svxcavesingle.html
+++ b/templates/svxcavesingle.html
@@ -38,12 +38,12 @@
{% for survexblock in survexfile.survexblock_set.all %}
<tr>
- <td>{{survexblock.name}}</td>
- <td>
+ <td style="width:10 em">{{survexblock.name}}</td>
+ <td style="white-space:nowrap">
{% if survexblock.expedition %}
<a href="{{survexblock.expedition.get_absolute_url}}">{{survexblock.date|date:"D d M Y"}}</a>
{% else %}
- {{survexblock.date}}
+ <!--{{survexblock.date}}-->
{% endif %}
</td>
@@ -57,12 +57,10 @@
{% endfor %}
</td>
- <td>{{survexblock.legslength}}</td>
+ <td style="padding-right: 3px; text-align:right">{{survexblock.legslength|stringformat:".1f"}}</td>
- <td>
- {% for survextitle in survexblock.survextitle_set.all %}
- {{survextitle.title}}
- {% endfor %}
+ <td style="padding-left: 3px;">
+ {{survexblock.title}}
</td>
<td>