diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2023-03-23 19:05:25 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2023-03-23 19:05:25 +0000 |
commit | 770edd639152a220c002258a144a46963b095cb4 (patch) | |
tree | 4b294702518e44c6eb79c22875cb0c5116cae842 /core/views/survex.py | |
parent | 562ef48f190d0f5d8f39782aefe8d3abb71932d7 (diff) | |
download | troggle-770edd639152a220c002258a144a46963b095cb4.tar.gz troggle-770edd639152a220c002258a144a46963b095cb4.tar.bz2 troggle-770edd639152a220c002258a144a46963b095cb4.zip |
Survex editor now parses edited files
Diffstat (limited to 'core/views/survex.py')
-rw-r--r-- | core/views/survex.py | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/core/views/survex.py b/core/views/survex.py index 57a8d1a..3ab7dd9 100644 --- a/core/views/survex.py +++ b/core/views/survex.py @@ -40,9 +40,14 @@ even though there are dozens of surveys. - Save and re-parse an edited survexfile which already exists in the db, and update all its dependencies (work in progress) + +- overlapping and cross-calling when things fail make this hard to undersand, e.g. svx() and + survexcavessingle() can get called for a survex file depending on whether the URL ends in ".svx" or not, + but each tries to handle the other case too. + """ -survexdatasetpath = Path(settings.SURVEX_DATA) +SVXPATH = Path(settings.SURVEX_DATA) # NB this template text must be identical to that in :loser:/templates/template.svx survextemplatefile = """; *** THIS IS A TEMPLATE FILE NOT WHAT YOU MIGHT BE EXPECTING *** @@ -160,7 +165,7 @@ class SvxForm(forms.Form): template = False def GetDiscCode(self): - fname = survexdatasetpath / (self.data["filename"] + ".svx") + fname = SVXPATH / (self.data["filename"] + ".svx") if not fname.is_file(): print(">>> >>> WARNING - svx file not found, showing TEMPLATE SVX", fname, flush=True) self.template = True @@ -186,7 +191,7 @@ class SvxForm(forms.Form): return difflist def SaveCode(self, rcode): - fname = survexdatasetpath / (self.data["filename"] + ".svx") + fname = SVXPATH / (self.data["filename"] + ".svx") if not fname.is_file(): if re.search(r"\[|\]", rcode): errmsg = "Error: remove all []s from the text.\nEverything inside [] are only template guidance.\n\n" @@ -203,7 +208,7 @@ class SvxForm(forms.Form): fout = open(fname, "w", encoding="utf8", newline="\n") except FileNotFoundError: pth = os.path.dirname(self.data["filename"]) - newpath = survexdatasetpath / pth + newpath = SVXPATH / pth if not os.path.exists(newpath): os.makedirs(newpath) fout = open(fname, "w", encoding="utf8", newline="\n") @@ -232,8 +237,8 @@ class SvxForm(forms.Form): def Process(self): print(">>>>....\n....Processing\n") - froox = os.fspath(survexdatasetpath / (self.data["filename"] + ".svx")) - froog = os.fspath(survexdatasetpath / (self.data["filename"] + ".log")) + froox = os.fspath(SVXPATH / (self.data["filename"] + ".svx")) + froog = os.fspath(SVXPATH / (self.data["filename"] + ".log")) cwd = os.getcwd() os.chdir(os.path.split(froox)[0]) os.system(settings.CAVERN + " --log " + froox) @@ -248,7 +253,7 @@ class SvxForm(forms.Form): # print(message) # print(f'stderr:\n\n' + str(sp.stderr) + '\n\n' + str(sp.stdout) + '\n\nreturn code: ' + str(sp.returncode)) - filepatherr = Path(survexdatasetpath / str(self.data["filename"] + ".err")) + filepatherr = Path(SVXPATH / str(self.data["filename"] + ".err")) if filepatherr.is_file(): if filepatherr.stat().st_size == 0: filepatherr.unlink() # delete empty closure error file @@ -281,11 +286,14 @@ def svx(request, survex_file): also has no difflist. Needs refactoring. Too many piecemeal edits and odd state dependencies. + + On Get does the SAME THING as svxcavesingle but is called when the .svx suffix is MISSING """ warning = False print(survex_file) if survex_file.lower().endswith(".svx"): + #cope with ".svx.svx" bollox survex_file = survex_file[:-4] print(survex_file) @@ -361,7 +369,7 @@ def svx(request, survex_file): # collect all the survex blocks which actually have a valid date if svxfile: - has_3d = (Path(survexdatasetpath) / Path(survex_file + ".3d")).is_file() + has_3d = (Path(SVXPATH) / Path(survex_file + ".3d")).is_file() try: svxblocks = svxfile.survexblock_set.filter(date__isnull=False).order_by('date') except: @@ -438,9 +446,9 @@ def events_on_dates(svxblocks): # The cavern running function. This is NOT where it is run inside the form! see SvxForm.Process() for that def process(survex_file): """This runs cavern only where a .3d, .log or .err file is requested.""" - filepathsvx = survexdatasetpath / str(survex_file + ".svx") + filepathsvx = SVXPATH / str(survex_file + ".svx") cwd = os.getcwd() - os.chdir(os.path.split(os.fspath(survexdatasetpath / survex_file))[0]) + os.chdir(os.path.split(os.fspath(SVXPATH / survex_file))[0]) os.system(settings.CAVERN + " --log " + str(filepathsvx)) os.chdir(cwd) @@ -453,27 +461,27 @@ def process(survex_file): # print(message) # print(f'stderr:\n\n' + str(sp.stderr) + '\n\n' + str(sp.stdout) + '\n\nreturn code: ' + str(sp.returncode)) - filepatherr = Path(survexdatasetpath / str(survex_file + ".err")) + filepatherr = Path(SVXPATH / str(survex_file + ".err")) if filepatherr.is_file(): if filepatherr.stat().st_size == 0: filepatherr.unlink() # delete empty closure error file def threed(request, survex_file): - filepath3d = survexdatasetpath / str(survex_file + ".3d") - survexdatasetpath / str(survex_file + ".log") + filepath3d = SVXPATH / str(survex_file + ".3d") + SVXPATH / str(survex_file + ".log") if filepath3d.is_file(): threed = open(filepath3d, "rb") return HttpResponse(threed, content_type="application/x-aven") else: process(survex_file) # should not need to do this if it already exists, as it should. - log = open(survexdatasetpath / str(survex_file + ".log"), "r", encoding="utf-8") + log = open(SVXPATH / str(survex_file + ".log"), "r", encoding="utf-8") return HttpResponse(log, content_type="text") def svxlog(request, survex_file): """Used for rendering .log files from survex outputtype""" - filepathlog = survexdatasetpath / str(survex_file + ".log") + filepathlog = SVXPATH / str(survex_file + ".log") if not filepathlog.is_file(): process(survex_file) log = open(filepathlog, "r") @@ -481,7 +489,7 @@ def svxlog(request, survex_file): def err(request, survex_file): - filepatherr = survexdatasetpath / str(survex_file + ".err") + filepatherr = SVXPATH / str(survex_file + ".err") if not filepatherr.is_file(): # probably not there because it was empty, but re-run anyway process(survex_file) process(survex_file) @@ -547,7 +555,7 @@ def identifycavedircontents(gcavedir): def get_survexareapath(area): - return survexdatasetpath / str("caves-" + area) + return SVXPATH / str("caves-" + area) # direct local non-database browsing through the svx file repositories @@ -653,7 +661,7 @@ def survexcavesingle(request, survex_cave): # maybe - and _ mixed up, or CUCC-2017- instead of 2017-CUCC-, or CUCC2015DL01 . Let's not get carried away.. # or it might be an exact search for a specific survefile but just missing the '.svx. - if (Path(survexdatasetpath) / Path(survex_cave + ".svx")).is_file(): + if (SVXPATH / Path(survex_cave + ".svx")).is_file(): return svx(request, survex_cave) for unoff in [sc, sc.replace("-", "_"), sc.replace("_", "-"), sc.replace("-", ""), sc.replace("_", "")]: |