mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-16 05:17:34 +00:00
Saving new survex file parses contents.
This commit is contained in:
@@ -333,7 +333,7 @@ class LoadingSurvex:
|
||||
currentteam = set()
|
||||
inheritteam = set()
|
||||
pending = []
|
||||
nocreate = False
|
||||
adhocload = False
|
||||
|
||||
def __init__(self):
|
||||
self.caveslist = GetCaveLookup()
|
||||
@@ -1253,10 +1253,6 @@ class LoadingSurvex:
|
||||
svxid = included.groups()[0]
|
||||
if svxid.lower() == debugprinttrigger.lower():
|
||||
debugprint = True
|
||||
if self.nocreate:
|
||||
# skip *include files if we are parsing just one file ?!
|
||||
# Maybe do this as a setting in the survexfile SAVE form?
|
||||
return
|
||||
self.LoadSurvexFile(svxid)
|
||||
self.stacksvxfiles.append(self.currentsurvexfile)
|
||||
|
||||
@@ -2138,19 +2134,24 @@ def FindAndLoadSurvex(survexblockroot):
|
||||
|
||||
def parse_one_file(fpath): # --------------------------------------in progress-------------------
|
||||
"""Parse just one file. Use when re-loading after editing.
|
||||
NB careful of *include lines, which may exist! Ignore them.
|
||||
|
||||
WORK IN PROGRESS. NONE OF THIS WORKS.
|
||||
Currently just returns True without saving anything
|
||||
Problems with re-setting multiple anonymous blocks in the survexfile
|
||||
Need to delete them all and recreate all the links, e.g. to wallets and people
|
||||
NOTE: *include lines are ignored.
|
||||
In the initial file parsing in databaseReset, the *include expansion is done
|
||||
in an earlier stange than LinearLoad(). By the time LinearLoad() is called,
|
||||
all the *include expansion has happened.
|
||||
|
||||
WORK IN PROGRESS.
|
||||
Works fine for completely new survex file.
|
||||
|
||||
For an edited, pre-existing survex file,
|
||||
deleting all the survex blocks means that some other pages just crash, e.g.
|
||||
/expedition/1996
|
||||
"""
|
||||
print(f"\n - Loading One Survex file '{fpath}'", file=sys.stderr)
|
||||
svx_load = LoadingSurvex()
|
||||
|
||||
collatefilename = Path(settings.SURVEX_DATA, (fpath + ".svx"))
|
||||
print(f" - {collatefilename=}")
|
||||
|
||||
fname = Path(settings.SURVEX_DATA, (fpath + ".svx"))
|
||||
# print(f" - {fname=}")
|
||||
|
||||
svxs = SurvexFile.objects.filter(path=fpath)
|
||||
# If this SurvexFile object already exists in the database, we want to keep the parent survexblock
|
||||
@@ -2159,51 +2160,66 @@ def parse_one_file(fpath): # --------------------------------------in progress--
|
||||
# and we are not processing any *include we find
|
||||
if svxs:
|
||||
if len(svxs)>1:
|
||||
print(f" ! Error. More than one survex file object in database with the same file-path {svx}")
|
||||
raise
|
||||
print(f" - pre-existing survexfile {svxs}")
|
||||
|
||||
print(f" ! Mistake? More than one survex file object in database with the same file-path {svxs}")
|
||||
print(f" - Aborting file parsing & import into database.")
|
||||
return True
|
||||
print(f" - Pre-existing survexfile {svxs}. NOT re-parsing now.")
|
||||
# SurvexBlock.objects.all().delete()
|
||||
|
||||
return True # NOT WORKING YET
|
||||
svx = svxs[0] # first and only member of QuerySet
|
||||
b = SurvexBlock.objects.filter(survexfile=svx)
|
||||
if len(b)>1:
|
||||
print(f" ! Error. More than one survex file object in database attached to survexblock {b}")
|
||||
raise
|
||||
|
||||
survexblockroot=b[0]
|
||||
print(f" - {survexblockroot=}")
|
||||
if len(b) >= 1:
|
||||
# survexblockparent=b[0].parent
|
||||
# survexblockparent.survexfile = svx
|
||||
# # Stamp all over the accumulated lengths and legs in the parent block,
|
||||
# # This also obliterates survey lengths from all other 'sibling' survex files
|
||||
# # to the one being re-parsed
|
||||
# survexblockparent.legsall=0
|
||||
# survexblockparent.legslength=0.0
|
||||
|
||||
b.delete() # deletes all pre-existing SurvexBlocks attached to this SurvexFile
|
||||
# all these foreign keys should be recreated properly when the file is parsed.
|
||||
# so whiy is /expedition/1996 crashing in nasty template error?
|
||||
else:
|
||||
survexblockparent = SurvexBlock(
|
||||
name="fresh_parent", survexpath="", survexfile=svx, legsall=0, legslength=0.0
|
||||
)
|
||||
survexblockparent.save()
|
||||
survexblockparent = SurvexBlock(
|
||||
name="fresh_parent", survexpath="", survexfile=svx, legsall=0, legslength=0.0
|
||||
)
|
||||
survexblockparent.save()
|
||||
print(f" - {survexblockparent=}")
|
||||
|
||||
dir = svx.survexdirectory
|
||||
svx_load.survexdict[dir] = [svx]
|
||||
svx_load.svxdirs[""] = dir
|
||||
return True
|
||||
svx_load.nocreate = True
|
||||
|
||||
svx_load.adhocload = True
|
||||
# ----------------------------------------------------------------
|
||||
svx_load.LinearLoad(survexblockroot, fpath, collatefilename)
|
||||
svx_load.LinearLoad(survexblockparent, fpath, fname)
|
||||
# ----------------------------------------------------------------
|
||||
svx_load.adhocload = False
|
||||
|
||||
else:
|
||||
print(f" - Not seen this survexfile before '{fpath}'")
|
||||
print(f" - Not seen this survexfile before '{fpath}' Loading...")
|
||||
|
||||
return True
|
||||
omitsfileroot = MakeOmitFileRoot(fpath) # NO! This always creats a SurvexFile object. We are overwriting one..
|
||||
survexomitsroot = SurvexBlock(
|
||||
name=OMITBLOCK, survexpath="", survexfile=omitsfileroot, legsall=0, legslength=0.0
|
||||
)
|
||||
survexomitsroot.save()
|
||||
# SurvexBlock.objects.all().delete()
|
||||
# SurvexFile.objects.all().delete()
|
||||
# SurvexDirectory.objects.all().delete()
|
||||
# SurvexPersonRole.objects.all().delete()
|
||||
# SurvexStation.objects.all().delete()
|
||||
print(" - Loading Survex Blocks...")
|
||||
|
||||
svx_load.survexdict[survexfileroot.survexdirectory] = []
|
||||
svx_load.survexdict[survexfileroot.survexdirectory].append(survexfileroot)
|
||||
svx_load.svxdirs[""] = survexfileroot.survexdirectory
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
svx_load.LinearLoad(survexblockroot, survexfileroot.path, collatefilename)
|
||||
# ----------------------------------------------------------------
|
||||
newfileroot = MakeFileRoot(fpath)
|
||||
survexblockparent = SurvexBlock(
|
||||
name="adhoc_parent", survexpath="", survexfile=newfileroot, legsall=0, legslength=0.0
|
||||
)
|
||||
survexblockparent.save()
|
||||
|
||||
svx_load.survexdict[newfileroot.survexdirectory] = []
|
||||
svx_load.survexdict[newfileroot.survexdirectory].append(newfileroot)
|
||||
svx_load.svxdirs[""] = newfileroot.survexdirectory
|
||||
|
||||
svx_load.adhocload = True
|
||||
# ----------------------------------------------------------------
|
||||
svx_load.LinearLoad(survexblockparent, newfileroot.path, fname)
|
||||
# ----------------------------------------------------------------
|
||||
svx_load.adhocload = False
|
||||
|
||||
legsnumber = svx_load.legsnumber
|
||||
|
||||
@@ -2213,6 +2229,7 @@ def parse_one_file(fpath): # --------------------------------------in progress--
|
||||
tf += len(svx_load.survexdict[d])
|
||||
print(f" - Number of SurvexFiles: {tf:,}")
|
||||
print(f" - Number of Survex legs: {legsnumber:,}")
|
||||
print(f" - Length of Survex legs: {svx_load.slength}")
|
||||
|
||||
# Now set Django SurvexFile object..
|
||||
|
||||
@@ -2234,7 +2251,7 @@ def MakeSurvexFileRoot():
|
||||
return fileroot
|
||||
|
||||
|
||||
def MakeOmitFileRoot(fn):
|
||||
def MakeFileRoot(fn):
|
||||
"""Returns a file_object.path = _unseens.svx associated with directory_object.path = SURVEX_DATA"""
|
||||
fileroot = SurvexFile(path=fn, cave=None)
|
||||
fileroot.survexdirectory = SurvexDirectory.objects.get(path=settings.SURVEX_DATA)
|
||||
@@ -2288,7 +2305,7 @@ def LoadSurvexBlocks():
|
||||
# sudo service mariadb start
|
||||
survexblockroot.save()
|
||||
|
||||
omitsfileroot = MakeOmitFileRoot(UNSEENS)
|
||||
omitsfileroot = MakeFileRoot(UNSEENS)
|
||||
survexomitsroot = SurvexBlock(
|
||||
name=OMITBLOCK, survexpath="", survexfile=omitsfileroot, legsall=0, legslength=0.0
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user