2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-25 08:41:51 +00:00

Initial attempts at saving edited survex file

This commit is contained in:
Philip Sargent 2023-03-05 23:06:06 +00:00
parent d5887e8f99
commit 8fc25de794
2 changed files with 58 additions and 3 deletions

View File

@ -21,6 +21,7 @@ from troggle.core.models.caves import Cave
from troggle.core.models.survex import SurvexFile, SurvexBlock
from troggle.core.models.wallets import Wallet
from troggle.core.utils import only_commit
from troggle.parsers.survex import parse_one_file
"""Everything that views survexfiles
but also displays data on a cave or caves when there is ambiguity
@ -198,6 +199,10 @@ class SvxForm(forms.Form):
comment = f"Online survex edit: {self.data['filename']}.svx on dev machine '{socket.gethostname()}' "
only_commit(fname, comment)
parse_one_file(self.data["filename"])
return "SAVED and committed to git (if there were differences)"
def Process(self):
@ -307,9 +312,9 @@ def svx(request, survex_file):
warning = True
if not difflist:
if svxfile:
difflist.append("No differences.")
difflist.append("No differences from last saved file.")
else:
difflist.append("No differences from initial template.")
difflist.append("No differences from last saved file (or from initial template).")
if message:
difflist.insert(0, message)

View File

@ -34,6 +34,9 @@ todo = """
- LoadSurvexFile() Creates a new current survexfile and valid .survexdirectory
The survexblock passed-in is not necessarily the parent. FIX THIS.
- Finish writing the parse_one_file() function for survexfiles edited online. Perhaps
easier if this is a completely new file rather than an existing file.. nasty.
- When Olly implements LEG in the 'dump3d --legs' utility, then we can use that to get the length of
all the legs in a survex block instead of adding them up oursleves. Which means that we can
ignore all the Units and offset stuff, that troggle will work with survex files with backsights,
@ -330,6 +333,7 @@ class LoadingSurvex:
currentteam = set()
inheritteam = set()
pending = []
nocreate = False
def __init__(self):
self.caveslist = GetCaveLookup()
@ -1249,6 +1253,10 @@ 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)
@ -2131,10 +2139,52 @@ 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
"""
print("\n - Loading One Survex file (LinearLoad)", file=sys.stderr)
print(f"\n - Loading One Survex file '{fpath}'", file=sys.stderr)
svx_load = LoadingSurvex()
collatefilename = Path(settings.SURVEX_DATA, (fpath + ".svx"))
print(f" - {collatefilename=}")
svxs = SurvexFile.objects.filter(path=fpath)
# If this SurvexFile object already exists in the database, we want to keep the parent survexblock
# but replace everything else by parsing the file.
# But we do not want to delete and recreate the object as other survex files may have this as the parent
# 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}")
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=}")
dir = svx.survexdirectory
svx_load.survexdict[dir] = [svx]
svx_load.svxdirs[""] = dir
return True
svx_load.nocreate = True
# ----------------------------------------------------------------
svx_load.LinearLoad(survexblockroot, fpath, collatefilename)
# ----------------------------------------------------------------
else:
print(f" - Not seen this survexfile before '{fpath}'")
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