summaryrefslogtreecommitdiffstats
path: root/parsers
diff options
context:
space:
mode:
Diffstat (limited to 'parsers')
-rw-r--r--parsers/cavetab.py143
-rw-r--r--parsers/survex.py19
2 files changed, 91 insertions, 71 deletions
diff --git a/parsers/cavetab.py b/parsers/cavetab.py
index d76a280..9f04105 100644
--- a/parsers/cavetab.py
+++ b/parsers/cavetab.py
@@ -108,14 +108,15 @@ def LoadCaveTab():
addToDefaultArgs(AutogenFile, "url")
if line[Area] == "1626":
if line[KatasterNumber] != "":
- args["slug"] = line[Area] + "-" + line[KatasterNumber]
+ slug = line[Area] + "-" + line[KatasterNumber]
else:
- args["slug"] = line[Area] + "-" + line[UnofficialNumber]
+ slug = line[Area] + "-" + line[UnofficialNumber]
else:
if line[KatasterNumber] != "":
- args["slug"] = "1623" + "-" + line[KatasterNumber]
+ slug = "1623" + "-" + line[KatasterNumber]
else:
- args["slug"] = "1623" + "-" + line[UnofficialNumber]
+ slug = "1623" + "-" + line[UnofficialNumber]
+ args["filename"] = "%s.html" % slug
#The following adds the legacy_file_path. This is always in either Autogen file or Link file
for header in (AutogenFile,LinkFile):
if line[header]:
@@ -126,8 +127,9 @@ def LoadCaveTab():
#Noinfo was the name of the old password protected directory, so if it has that then we will
#set the non_public field of the model instance to true.
defaultArgs["non_public"]=line[AutogenFile].startswith('noinfo') or line[LinkFile].startswith('noinfo')
-
- newCave, created=save_carefully(models.Cave, lookupAttribs=args, nonLookupAttribs=defaultArgs)
+ newCave, created = save_carefully(models.Cave, lookupAttribs=args, nonLookupAttribs=defaultArgs)
+ cs = models.CaveSlug(slug = slug, cave = newCave, primary = True)
+ cs.save()
logging.info("Added cave "+str(newCave)+"\n")
#If we created a new cave, add the area to it. This does mean that if a cave's identifying features have not changed, areas will not be updated from csv.
@@ -148,8 +150,7 @@ def LoadCaveTab():
newCave.save()
- logging.info("Added area "+line[Area]+" to cave "+str(newCave)+"\n")
-
+ logging.info("Added area "+line[Area]+" to cave "+str(newCave)+"\n")
if created and line[UnofficialName]:
newUnofficialName = models.OtherCaveName(cave = newCave, name = line[UnofficialName])
newUnofficialName.save()
@@ -161,70 +162,80 @@ def LoadCaveTab():
line[MultipleEntrances] == 'entrance' or \
line[MultipleEntrances] == 'last entrance':
args = {}
-
- if line[Entrances]:
- entrance_letter = line[Entrances]
- else:
- entrance_letter = ''
-
def addToArgs(CSVname, modelName):
if line[CSVname]:
args[modelName] = line[CSVname]
def addToArgsViaDict(CSVname, modelName, dictionary):
if line[CSVname]:
args[modelName] = dictionary[line[CSVname]]
- addToArgs(EntranceName, 'name')
- addToArgs(Explorers, 'explorers')
- addToArgs(Map, 'map_description')
- addToArgs(Location, 'location_description')
- addToArgs(Approach, 'approach')
- addToArgs(EntranceDescription, 'entrance_description')
- addToArgs(UndergroundDescription, 'underground_description')
- addToArgs(PhotoOfLocation, 'photo')
- addToArgsViaDict(Marking, 'marking', {"Paint": "P",
- "Paint (?)": "P?",
- "Tag": "T",
- "Tag (?)": "T?",
- "Retagged": "R",
- "Retag": "R",
- "Spit": "S",
- "Spit (?)": "S?",
- "Unmarked": "U",
- "": "?",
- })
-
- addToArgs(MarkingComment, 'marking_comment')
- addToArgsViaDict(Findability, 'findability', {"Surveyed": "S",
- "Lost": "L",
- "Refindable": "R",
- "": "?",
- "?": "?",
- })
- addToArgs(FindabilityComment, 'findability_description')
- addToArgs(Easting, 'easting')
- addToArgs(Northing, 'northing')
- addToArgs(Altitude, 'alt')
- addToArgs(DescriptionOfOtherPoint, 'other_description')
- addToArgs(TagPoint, 'tag_station')
- addToArgs(ExactEntrance, 'exact_station')
- addToArgs(OtherPoint, 'other_station')
- addToArgs(OtherPoint, 'other_description')
- if line[GPSpreSA]:
- addToArgs(GPSpreSA, 'other_station')
- args['other_description'] = 'pre selective availability GPS'
- if line[GPSpostSA]:
- addToArgs(GPSpostSA, 'other_station')
- args['other_description'] = 'post selective availability GPS'
- addToArgs(Bearings, 'bearings')
- args['slug'] = newCave.slug + entrance_letter
- newEntrance = models.Entrance(**args)
- newEntrance.save()
-
- logging.info("Added entrance "+str(newEntrance)+"\n")
-
-
- newCaveAndEntrance = models.CaveAndEntrance(cave = newCave, entrance = newEntrance, entrance_letter = entrance_letter)
- newCaveAndEntrance.save()
+
+ if line[Entrances]:
+ entrance_letter = line[Entrances]
+ else:
+ entrance_letter = ''
+
+ if not line[LinkFile]:
+ addToArgs(Map, 'map_description')
+ addToArgs(Location, 'location_description')
+ addToArgs(Approach, 'approach')
+ addToArgs(EntranceDescription, 'entrance_description')
+ if line[MultipleEntrances] == 'entrance' or \
+ line[MultipleEntrances] == 'last entrance':
+ addToArgs(UndergroundDescription, 'underground_description')
+ addToArgs(AutogenFile, 'url')
+ addToArgs(EntranceName, 'name')
+ addToArgs(Explorers, 'explorers')
+ addToArgs(PhotoOfLocation, 'photo')
+ addToArgsViaDict(Marking, 'marking', {"Paint": "P",
+ "Paint (?)": "P?",
+ "Tag": "T",
+ "Tag (?)": "T?",
+ "Retagged": "R",
+ "Retag": "R",
+ "Spit": "S",
+ "Spit (?)": "S?",
+ "Unmarked": "U",
+ "": "?",
+ })
+
+ addToArgs(MarkingComment, 'marking_comment')
+ addToArgsViaDict(Findability, 'findability', {"Surveyed": "S",
+ "Lost": "L",
+ "Refindable": "R",
+ "": "?",
+ "?": "?",
+ })
+ addToArgs(FindabilityComment, 'findability_description')
+ addToArgs(Easting, 'easting')
+ addToArgs(Northing, 'northing')
+ addToArgs(Altitude, 'alt')
+ addToArgs(DescriptionOfOtherPoint, 'other_description')
+ addToArgs(TagPoint, 'tag_station')
+ addToArgs(ExactEntrance, 'exact_station')
+ addToArgs(OtherPoint, 'other_station')
+ addToArgs(OtherPoint, 'other_description')
+ if line[GPSpreSA]:
+ addToArgs(GPSpreSA, 'other_station')
+ args['other_description'] = 'pre selective availability GPS'
+ if line[GPSpostSA]:
+ addToArgs(GPSpostSA, 'other_station')
+ args['other_description'] = 'post selective availability GPS'
+ addToArgs(Bearings, 'bearings')
+ args["filename"] = "%s.html" % (slug + entrance_letter)
+
+ newEntrance = models.Entrance(**args)
+ newEntrance.save()
+ es = models.EntranceSlug(slug = slug + entrance_letter, entrance = newEntrance, primary = True)
+ es.save()
+
+
+ logging.info("Added entrance "+str(newEntrance)+"\n")
+
+
+ newCaveAndEntrance = models.CaveAndEntrance(cave = newCave,
+ entrance = newEntrance,
+ entrance_letter = entrance_letter)
+ newCaveAndEntrance.save()
logging.info("Added CaveAndEntrance "+str(newCaveAndEntrance)+"\n")
if line[AutogenFile] != "":
diff --git a/parsers/survex.py b/parsers/survex.py
index 2e0b8d3..d43c303 100644
--- a/parsers/survex.py
+++ b/parsers/survex.py
@@ -59,7 +59,11 @@ def LoadSurvexLineLeg(survexblock, stardata, sline, comment):
survexblock.save()
def LoadSurvexEquate(survexblock, sline):
- pass
+ #print sline #
+ stations = sline.split()
+ assert len(stations) > 1
+ for station in stations:
+ survexblock.MakeSurvexStation(station)
def LoadSurvexLinePassage(survexblock, stardata, sline, comment):
pass
@@ -109,6 +113,7 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines):
# detect the star command
cmd, line = mstar.groups()
+ cmd = cmd.lower()
if re.match("include$(?i)", cmd):
includepath = os.path.join(os.path.split(survexfile.path)[0], re.sub("\.svx$", "", line))
includesurvexfile = models.SurvexFile(path=includepath, cave=survexfile.cave)
@@ -177,10 +182,12 @@ def RecursiveLoad(survexblock, survexfile, fin, textlines):
assert ls[0] == "passage", line
elif cmd == "equate":
- LoadSurvexEquate(survexblock, sline)
-
+ LoadSurvexEquate(survexblock, line)
+
+ elif cmd == "fix":
+ survexblock.MakeSurvexStation(line.split()[0])
else:
- assert cmd.lower() in [ "sd", "equate", "include", "units", "entrance", "fix", "data", "flags", "title", "export", "instrument", "calibrate", "set", "infer"], (cmd, line, survexblock)
+ assert cmd in [ "sd", "include", "units", "entrance", "data", "flags", "title", "export", "instrument", "calibrate", "set", "infer"], (cmd, line, survexblock)
@@ -211,6 +218,7 @@ def LoadAllSurvexBlocks():
models.SurvexLeg.objects.all().delete()
models.SurvexTitle.objects.all().delete()
models.SurvexPersonRole.objects.all().delete()
+ models.SurvexStation.objects.all().delete()
survexfile = models.SurvexFile(path="all", cave=None)
survexfile.save()
@@ -248,7 +256,8 @@ def LoadPos():
try:
ss = models.SurvexStation.objects.lookup(name)
except:
- pass
+ print name
ss.x = float(x)
ss.y = float(y)
ss.z = float(z)
+ ss.save()