summaryrefslogtreecommitdiffstats
path: root/parsers/survex.py
diff options
context:
space:
mode:
Diffstat (limited to 'parsers/survex.py')
-rw-r--r--parsers/survex.py52
1 files changed, 22 insertions, 30 deletions
diff --git a/parsers/survex.py b/parsers/survex.py
index a1cab9a..70fc987 100644
--- a/parsers/survex.py
+++ b/parsers/survex.py
@@ -15,6 +15,7 @@ from troggle.core.models.wallets import Wallet
from troggle.core.models.troggle import DataIssue, Expedition
from troggle.core.utils import chaosmonkey, get_process_memory
#from troggle.parsers.logbooks import GetCaveLookup
+from troggle.parsers.caves import create_new_cave
from troggle.parsers.people import GetPersonExpeditionNameLookup, known_foreigner
"""Imports the tree of survex files following from a defined root .svx file
@@ -1168,15 +1169,20 @@ class LoadingSurvex:
print(f"! ALREADY PENDING {id}", file=sys.stderr)
return
+ # It is too late to add it to the pending caves list here, they were already
+ # processed in parsers/caves.py So we have to do a bespoke creation.
+ cave = create_new_cave(includelabel)
+
message = f" ! Warning: cave identifier '{caveid}'or {id} (guessed from file path) is not a known cave. Need to add to expoweb/cave_data/pending.txt ? In '{includelabel}.svx' at depth:[{len(depth)}]."
print("\n" + message)
print("\n" + message, file=sys.stderr)
print(f"{self.pending}", end="", file=sys.stderr)
stash_data_issue(parser="survex", message=message, url=None, sb=(includelabel))
- # print(f' # datastack in LoadSurvexFile:{includelabel}', file=sys.stderr)
- # for dict in self.datastack:
- # print(f' type: <{dict["type"].upper()} >', file=sys.stderr)
-
+
+ # It is too late to add it to pending caves here, they were already processed in parsers/caves.py
+ # and something else is creating them...
+ # cave = create_new_cave(includelabel)
+
def LoadSurvexFile(self, svxid):
"""Creates SurvexFile in the database, and SurvexDirectory if needed
with links to 'cave'
@@ -1219,7 +1225,6 @@ class LoadingSurvex:
newdirectory.save()
newfile.survexdirectory = newdirectory
self.survexdict[newdirectory].append(newfile)
- cave = IdentifyCave(headpath) # cave already exists in db
if not newdirectory:
message = f" ! 'None' SurvexDirectory returned from GetSurvexDirectory({headpath})"
@@ -1227,13 +1232,18 @@ class LoadingSurvex:
print(message, file=sys.stderr)
stash_data_issue(parser="survex", message=message, url=f"/survexfile/{svxid}")
+ cave = IdentifyCave(headpath) # cave already exists in db
+ if not cave:
+ # probably a surface survey, or a cave in a new area
+ # e.g. 1624 not previously managed, and not in the pending list
+ self.ReportNonCaveIncludes(headpath, svxid, depth)
+ #try again
+ cave = IdentifyCave(headpath)
if cave:
newdirectory.cave = cave
newfile.cave = cave
# print(f"\n - New directory '{newdirectory}' for cave '{cave}'",file=sys.stderr)
- else: # probably a surface survey, or a cave in a new area e.g. 1624 not previously managed, and not in the pending list
- self.ReportNonCaveIncludes(headpath, svxid, depth)
-
+
if not newfile.survexdirectory:
message = f" ! SurvexDirectory NOT SET in new SurvexFile {svxid} "
print(message)
@@ -2443,30 +2453,12 @@ def MakeFileRoot(fn):
or tries to find the primary survex file for this cave
"""
cave = IdentifyCave(fn)
+ if not cave:
+ if fn != UNSEENS:
+ cave = create_new_cave(fn)
print(f" - Making/finding a new root survexfile for this import: {fn}")
-
- #this doesn't work. Using the cave primary survex file as the fileroot
- # 1. does not parse the file correctly and does not attach the blocks in it to the surfvexfile
- # 2. it still doesn't appear on the http://localhost:8000/survexfile/107 list
- # 3. it does make the sb appear on http://localhost:8000/survexfile/caves-1623/107/107.svx when it shouldnt.
-
- # if cave == None:
- # fileroot = SurvexFile(path=fn, cave=cave)
- # fileroot.survexdirectory = SurvexDirectory.objects.get(id=1) # just re-use the first thing we made
- # fileroot.save()
- # fileroot.cave = cave
- # print(f" - new fileroot {type(fileroot)} for {fn} with cave {cave} - {fileroot}")
- # else:
- # print(f" - {cave.survexdirectory_set.all()}")
- # print(f" - {cave.survexdirectory_set.filter(cave=cave)}")
- # for sd in cave.survexdirectory_set.filter(cave=cave):
- # print(f" - {sd.cave} {sd.primarysurvexfile}")
- # if f"{sd.primarysurvexfile}".replace("caves-","").startswith(f"{sd.cave}"[:4]):
- # print(f" - USE THIS ONE {sd.cave} {sd.primarysurvexfile}")
- # fileroot = sd.primarysurvexfile
- # print(f" - old fileroot {type(fileroot)} for {fn} with cave {cave} - {fileroot}")
-
+
fileroot = SurvexFile(path=fn, cave=cave)
fileroot.survexdirectory = SurvexDirectory.objects.get(id=1) # default