Update prospecting guide scripts to include greisskogel area

And make much more robust for missing files, processing errors and
simplify main regex
This commit is contained in:
Wookey 2013-06-19 03:21:41 +01:00
parent ceb1d4e34b
commit dca54300c4

View File

@ -1,3 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Script to create a slightly more useful attempt
# at a prospecting guide.
@ -46,6 +49,19 @@ areacolours = {
cavelists={}
for a in areas: cavelists[a]=[]
#check to see if cmd is on $PATH
def exists_in_path(cmd):
# can't search the path if a directory is specified
assert not os.path.dirname(cmd)
extensions = os.environ.get("PATHEXT", "").split(os.pathsep)
for directory in os.environ.get("PATH", "").split(os.pathsep):
base = os.path.join(directory, cmd)
options = [base] + [(base + ext) for ext in extensions]
for filename in options:
if os.path.exists(filename):
return True
return False
def chomp(s):
if not s: return s
@ -172,7 +188,7 @@ def get_img_name(maparea):
maps = {
# id left top right bottom zoom
# G&K G&K G&K G&K factor
"all": [34394.9, 84508.6, 37399.4, 80895.6, 1.0,
"all": [34950.9, 86300.0, 38325.0, 80895.6, 1.0,
"All"],
"40": [36275.6, 82392.5, 36780.3, 81800.0, 3.0,
"Eishöhle"],
@ -182,12 +198,12 @@ maps = {
"Steinbrückenhöhle"],
"tc": [35230.0, 82690.0, 36110.0, 82100.0, 3.0,
"Near Top Camp"],
#"jenny":
# [35740.0, 82870.0, 36090.0, 82390.0, 4.0,
# "Jenny"],
"grieß":
[36000.0, 86300.0, 38320.0, 84400.0, 4.0,
"Grießkogel Area"],
}
# Keys in the order in which we want the maps output
mapcodes = ["all", "40", "76", "204", "tc"] # "jenny"
mapcodes = ["all", "grieß","40", "76", "204", "tc"]
# Field codes
L = 0
T = 1
@ -310,19 +326,33 @@ print "Done"
# Draw cave passage
print "Munging dump3d output"
if exists_in_path("dump3d"):
dump3d_binary = "dump3d"
else:
# assume it's in this directory
dump3d_binary = os.path.join(os.path.dirname(os.path.realpath(__file__)),"./dump3d")
positions = {}
surfacecolour = "#808080"
repath = re.compile(r'^(?:182to(?:tc|184)|tctocol|82to97|vd1to161d|161ftod|161etof|161etog|40entlink2|surfnr161|surf161|kansurf)$')
for fnm in ("all.3d", "alltracks.3d"):
for fnm in ("../all.3d", "../alltracks.3d"):
for mapcode in draws.keys():
file3d = os.popen("./dump3d ../" + fnm)
try:
file3d = os.popen(dump3d_binary + " " + fnm)
except:
#dump3d doesn't return an error code on "Couldnt open data file". It should.
print "Running command: %s %s failed: %s" % (dump3d_binary, fnm, file3d)
draw = draws[mapcode]
lastx, lasty = 0, 0
for l in file3d:
match = re.match(r'(MOVE|LINE|NODE)\s+(-?[0-9.]+)\s+(-?[0-9.]+)\s+(-?[0-9.]+)\s+(?:[^[]*\[(.*)\] ?([^]]*)$)?', l)
if not match: continue
match = re.match(r'^(MOVE|LINE|NODE)\s+(-?[0-9.]+)\s+(-?[0-9.]+)\s+(-?[0-9.]+)(?:\s+\[(\S*)\])*(?:\s+(.*))*$', l)
#oldregex match = re.match(r'^(MOVE|LINE|NODE)\s+(-?[0-9.]+)\s+(-?[0-9.]+)\s+(-?[0-9.]+)\s+(?:[^[]*\[(.*)\] ?([^]]*)$)?', l)
if not match:
continue
act,E,N,alt,name,flags = match.groups()
# print "act:%s, E:%s, N:%s, name:%s flags:%s" % (act,E,N,name,flags)
# Only need to process NODEs once
if act == "NODE" and mapcode != "all": continue
@ -368,19 +398,23 @@ for cave in cavetab:
area = re.sub(r' .*', "", area)
if area == '1626' or area == 'nonexistent': continue
loctuple = find_location(cave)
label = find_label(cave, shortnumber)
if(cave["Multiple entrances"] == "yes"):
locn = "<td colspan=\"3\">&nbsp;</td>"
elif(loctuple):
locn = "<td class=\"locn good\">%d</td><td class=\"locn good\">%d</td><td class=\"locn good\">%d</td>" % loctuple
cavestoplot.append((loctuple, number, area, label))
else:
locn = "<td colspan=\"3\" class=%s>" % findability_color(cave) + (cave["Findability"] or '?') + "</td>"
try:
cavelists[area].append((number, cave, locn))
try:
loctuple = find_location(cave)
except:
print "Bad area '%s' for cave %s" % (area, number)
print "Unable to find location for %s" % (number)
else:
label = find_label(cave, shortnumber)
if(cave["Multiple entrances"] == "yes"):
locn = "<td colspan=\"3\">&nbsp;</td>"
elif(loctuple):
locn = "<td class=\"locn good\">%d</td><td class=\"locn good\">%d</td><td class=\"locn good\">%d</td>" % loctuple
cavestoplot.append((loctuple, number, area, label))
else:
locn = "<td colspan=\"3\" class=%s>" % findability_color(cave) + (cave["Findability"] or '?') + "</td>"
try:
cavelists[area].append((number, cave, locn))
except:
print "Bad area '%s' for cave %s" % (area, number)
if showbg:
htmlfile = file("/dev/null", "w")