From 5770a9b2e7df233b1eafed401b17b0b861212e41 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sun, 20 Jul 2025 12:46:27 +0200 Subject: [PATCH] remove redundant code --- parsers/locations.py | 136 ++++++++++++++++++++++++++----------------- 1 file changed, 81 insertions(+), 55 deletions(-) diff --git a/parsers/locations.py b/parsers/locations.py index 9a6a65e17..f3afce3af 100644 --- a/parsers/locations.py +++ b/parsers/locations.py @@ -199,6 +199,32 @@ def validate_entrance_stations(ent=None): poslineregex = re.compile(r"^\(\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*),\s*([+-]?\d*\.\d*)\s*\)\s*([^\s]+)$") +# This regular expression matches a specific format: +# A tuple of three floating-point numbers, followed by a non-space string. + +# Pattern breakdown: +# ^ : Start of string +# \( : Literal opening parenthesis +# \s* : Optional whitespace +# ([+-]?\d*\.\d*) : First float (with optional sign) +# ,\s* : Comma and optional whitespace +# ([+-]?\d*\.\d*) : Second float +# ,\s* : Comma and optional whitespace +# ([+-]?\d*\.\d*) : Third float +# \s*\) : Optional whitespace and closing parenthesis +# \s* : Optional whitespace after the tuple +# ([^\s]+) : Captures a non-space string (e.g. identifier, label) +# $ : End of string + +# Example matches: +# "(1.23, -4.56, +7.89)SomeTextHere" +# "( 0.0 , 3.14 , 2.71 )ExtraStuff" + +# Capturing groups returned: +# group(1): First float +# group(2): Second float +# group(3): Third float +# group(4): Trailing text (no spaces) def LoadPositions(): """First load the survex stations for entrances and fixed points (about 600) into the database. @@ -215,65 +241,65 @@ def LoadPositions(): SurvexStation.objects.all().delete() - def runcavern3d(msg=None): - if msg: - print(" - ", msg) - outputdir = Path(str(f"{topdata}.svx")).parent - file3d = Path(f"{topdata}.3d") - try: - sp = subprocess.run( - [settings.CAVERN, "--log", f"--output={outputdir}", f"{topdata}.svx"], - capture_output=True, - check=False, - text=True, - ) # check=False means exception not raised - if sp.returncode != 0: - message = f" ! Error: cavern: creating {file3d} in runcavern3()" - stash_data_issue(parser="positions", message=message) - print(message) + # def runcavern3d(msg=None): + # if msg: + # print(" - ", msg) + # outputdir = Path(str(f"{topdata}.svx")).parent + # file3d = Path(f"{topdata}.3d") + # try: + # sp = subprocess.run( + # [settings.CAVERN, "--log", f"--output={outputdir}", f"{topdata}.svx"], + # capture_output=True, + # check=False, + # text=True, + # ) # check=False means exception not raised + # if sp.returncode != 0: + # message = f" ! Error: cavern: creating {file3d} in runcavern3()" + # stash_data_issue(parser="positions", message=message) + # print(message) - # find the errors in the .log file - sp = subprocess.run( - ["grep", "error:", f"{topdata}.log"], capture_output=True, check=False, text=True - ) # check=False means exception not raised - message = f" ! Error: cavern: {sp.stdout} creating {file3d} " - stash_data_issue(parser="positions", message=message) - print(message) + # # find the errors in the .log file + # sp = subprocess.run( + # ["grep", "error:", f"{topdata}.log"], capture_output=True, check=False, text=True + # ) # check=False means exception not raised + # message = f" ! Error: cavern: {sp.stdout} creating {file3d} " + # stash_data_issue(parser="positions", message=message) + # print(message) - except: - message = f" ! CalledProcessError 'cavern' in runcavern3() at {topdata}." - stash_data_issue(parser="positions", message=message) - print(message) + # except: + # message = f" ! CalledProcessError 'cavern' in runcavern3() at {topdata}." + # stash_data_issue(parser="positions", message=message) + # print(message) - if file3d.is_file(): - message = f" ! CalledProcessError. File permissions {file3d.stat().st_mode} on {str(file3d)}" - stash_data_issue(parser="positions", message=message) - print(message) + # if file3d.is_file(): + # message = f" ! CalledProcessError. File permissions {file3d.stat().st_mode} on {str(file3d)}" + # stash_data_issue(parser="positions", message=message) + # print(message) - if file3d.is_file(): # might be an old one though, if previous step failed - try: - sp = subprocess.run( - [settings.SURVEXPORT, "--pos", f"{file3d}"], - cwd=settings.SURVEX_DATA, - capture_output=True, - check=False, - text=True, - ) - if sp.returncode != 0: - print( - f" ! Error: survexport creating {topdata}.pos in runcavern3().\n\n" - + str(sp.stdout) - + "\n\nreturn code: " - + str(sp.returncode) - ) - except: - message = f" ! CalledProcessError 'survexport' in runcavern3() at {file3d}." - stash_data_issue(parser="positions", message=message) - print(message) - else: - message = f" ! Failed to find {file3d} so aborting generation of new .pos, using old one if present" - stash_data_issue(parser="positions", message=message) - print(message) + # if file3d.is_file(): # might be an old one though, if previous step failed + # try: + # sp = subprocess.run( + # [settings.SURVEXPORT, "--pos", f"{file3d}"], + # cwd=settings.SURVEX_DATA, + # capture_output=True, + # check=False, + # text=True, + # ) + # if sp.returncode != 0: + # print( + # f" ! Error: survexport creating {topdata}.pos in runcavern3().\n\n" + # + str(sp.stdout) + # + "\n\nreturn code: " + # + str(sp.returncode) + # ) + # except: + # message = f" ! CalledProcessError 'survexport' in runcavern3() at {file3d}." + # stash_data_issue(parser="positions", message=message) + # print(message) + # else: + # message = f" ! Failed to find {file3d} so aborting generation of new .pos, using old one if present" + # stash_data_issue(parser="positions", message=message) + # print(message) topdata = Path(settings.SURVEX_DATA, settings.SURVEX_TOPNAME) print(f" - Generating a list of Pos from {topdata}.3d and then loading...")