summaryrefslogtreecommitdiffstats
path: root/parsers/survex.py
diff options
context:
space:
mode:
Diffstat (limited to 'parsers/survex.py')
-rw-r--r--parsers/survex.py35
1 files changed, 19 insertions, 16 deletions
diff --git a/parsers/survex.py b/parsers/survex.py
index a5a9959..ba2622c 100644
--- a/parsers/survex.py
+++ b/parsers/survex.py
@@ -1174,15 +1174,20 @@ class LoadingSurvex:
in the directory, where first is defined by the *include ordering. Which is what we
are doing.
- This does NOT set the current cave id in the SurvexDirectory, that happens later
"""
if not headpath:
- return self.svxdirs[""]
+ # This is normal for .svx file in the root of the :loser: repo
+ # message = f" ! GetSurvexDirectory NO headpath given at {self.currentsurvexfile}"
+ # print("\n"+message,file=sys.stderr)
+ # stash_data_issue(parser="survex", message=message, url=f"/survexfile/{self.currentsurvexfile}")
+ return self.svxdirs[""], self.currentsurvexfile
+
if headpath.lower() not in self.svxdirs:
- self.svxdirs[headpath.lower()] = SurvexDirectory(path=headpath, primarysurvexfile=self.currentsurvexfile)
+ primary = self.currentsurvexfile
+ self.svxdirs[headpath.lower()] = SurvexDirectory(path=headpath, primarysurvexfile=primary) # NOT .lower()
self.svxdirs[headpath.lower()].save()
self.survexdict[self.svxdirs[headpath.lower()]] = [] # list of the files in the directory
- return self.svxdirs[headpath.lower()]
+ return self.svxdirs[headpath.lower()], self.svxdirs[headpath.lower()].primarysurvexfile
def ReportNonCaveIncludes(self, headpath, includelabel, depth):
"""Ignore surface, kataser and gpx *include survex files"""
@@ -1238,7 +1243,6 @@ class LoadingSurvex:
def LoadSurvexFile(self, svxid):
"""Creates SurvexFile in the database, and SurvexDirectory if needed
- with links to 'cave'
Creates a new current survexfile and valid .survexdirectory
Inspects the parent folder of the survexfile and uses that to decide if this is
a cave we know.
@@ -1274,10 +1278,11 @@ class LoadingSurvex:
newfile.save() # until we do this there is no internal id so no foreign key works
self.currentsurvexfile = newfile
- newdirectory = self.GetSurvexDirectory(headpath)
+ newdirectory, primary = self.GetSurvexDirectory(headpath)
newdirectory.save()
newfile.survexdirectory = newdirectory
self.survexdict[newdirectory].append(newfile)
+ newfile.primary = primary
if not newdirectory:
message = f" ! 'None' SurvexDirectory returned from GetSurvexDirectory({headpath})"
@@ -1285,6 +1290,7 @@ class LoadingSurvex:
print(message, file=sys.stderr)
stash_data_issue(parser="survex", message=message, url=f"/survexfile/{svxid}")
+ # REPLACE all this IdentifyCave() stuff with GCaveLookup ?
cave = IdentifyCave(headpath) # cave already exists in db
if not cave:
# probably a surface survey, or a cave in a new area
@@ -1293,12 +1299,16 @@ class LoadingSurvex:
#try again
cave = IdentifyCave(headpath)
if cave:
- # newdirectory.cave = cave # turns uout to be never used
newfile.cave = cave
# print(f"\n - New directory '{newdirectory}' for cave '{cave}'",file=sys.stderr)
if not newfile.survexdirectory:
- message = f" ! SurvexDirectory NOT SET in new SurvexFile {svxid} "
+ message = f" ! .survexdirectory NOT SET in new SurvexFile {svxid} "
+ print(message)
+ print(message, file=sys.stderr)
+ stash_data_issue(parser="survex", message=message)
+ if not newfile.primary:
+ message = f" ! .primary NOT SET in new SurvexFile {svxid} "
print(message)
print(message, file=sys.stderr)
stash_data_issue(parser="survex", message=message)
@@ -1310,12 +1320,6 @@ class LoadingSurvex:
print(newdirectory.primarysurvexfile, file=sys.stderr)
raise
- if debugprint:
- print(f" # datastack end LoadSurvexFile:{svxid} 'type':", end="")
- for dict in self.datastack:
- print(f"'{dict['type'].upper()}' ", end="")
- print("")
-
def ProcessIncludeLine(self, included):
"""As we read the long linear file, we come across lines telling us that the
@@ -2500,7 +2504,6 @@ def MakeSurvexFileRoot():
fileroot = SurvexFile(path=settings.SURVEX_TOPNAME, cave=None)
fileroot.save()
- #directoryroot = SurvexDirectory(path=settings.SURVEX_DATA, cave=smk[0], primarysurvexfile=fileroot)
directoryroot = SurvexDirectory(path=settings.SURVEX_DATA, primarysurvexfile=fileroot)
# MariaDB doesn't like this hack. Complains about non-null cave_id EVEN THOUGH our model file says this is OK:
# cave = models.ForeignKey('Cave', blank=True, null=True,on_delete=models.SET_NULL)
@@ -2525,7 +2528,7 @@ def MakeFileRoot(fn):
try:
fileroot.survexdirectory = SurvexDirectory.objects.get(id=1) # default
except:
- fileroot.survexdirectory = None
+ fileroot.survexdirectory = None
# if cave: