diff --git a/core/views/cave_kataster.py b/core/views/cave_kataster.py
index 08aced667..48aad7d26 100644
--- a/core/views/cave_kataster.py
+++ b/core/views/cave_kataster.py
@@ -1,3 +1,4 @@
+import re
from pathlib import Path
import django.forms as forms
@@ -23,6 +24,38 @@ is 'katastered', ie.e moves from an informal number, such as
"""
def kataster(request, slug):
+ """Create the page which analyses how to rename a cave and all the files from the unofficial_number
+ identifier, e.g. 1623-2023-mg-03 to the kataster number e.g. 1623-999
+ """
+ def do_file_finding():
+
+ global cavefilename, cave_data, entrance_data, loser_name, loser_data
+
+ cavefilename = str(cave) + ".html"
+
+ cave_data = Path( "cave_data", cavefilename )
+ if not (settings.CAVEDESCRIPTIONS / cavefilename).is_file: # settings.EXPOWEB / cave_data
+ cave_data = "does not exist"
+
+ ent_dir = settings.ENTRANCEDESCRIPTIONS # settings.EXPOWEB / "entrance_data"
+
+ entrance_data = []
+ for ent in ent_dir.iterdir():
+ if str(ent.name).startswith(str(cave)):
+ print(ent.name)
+ entrance_data.append("entrance_data/"+ent.name)
+
+ loser_name = f"caves-{str(cave.areacode)}/{str(cave.unofficial_number)}"
+ loser_dir = settings.SURVEX_DATA / loser_name
+ loser_data = []
+ if (loser_dir).is_dir():
+ print(loser_dir)
+ for svx in loser_dir.iterdir():
+ print(svx)
+ loser_data.append(Path(loser_dir , svx).name)
+
+
+
if cave := get_cave_from_slug(slug.lower()):
pass
elif cave := get_cave_from_slug(slug.upper()):
@@ -31,29 +64,25 @@ def kataster(request, slug):
return HttpResponseRedirect("/caves")
knum = 9999
- filename = str(cave) + ".html"
-
- cave_data = Path( "cave_data", filename )
- if not (settings.EXPOWEB / cave_data).is_file:
- cave_data = "does not exist"
+ do_file_finding()
- ent_dir = settings.EXPOWEB / "entrance_data"
+ try:
+ # this is a python generator idiom.
+ # see https://realpython.com/introduction-to-python-generators/
+ with open(settings.CAVEDESCRIPTIONS / cavefilename, 'r') as f:
+ for line in f:
+ if match := re.search(r'(.*?)', line):
+ entrance = match.group(1)
+ print(entrance)
+
+ except PermissionError as e:
+ msg=f"CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {filepath}. Ask a nerd to fix this: {e}"
+ print(msg)
+ raise
+ except Exception as e:
+ msg=f"CANNOT write this file {filepath}. Ask a nerd to fix this: {e}"
+ print(msg)
- entrance_data = []
- for ent in ent_dir.iterdir():
- if str(ent.name).startswith(str(cave)):
- print(ent.name)
- entrance_data.append("entrance_data/"+ent.name)
-
- loser_name = f"caves-{str(cave.areacode)}/{str(cave.unofficial_number)}"
- loser_dir = settings.SURVEX_DATA / loser_name
- loser_data = []
- if (loser_dir).is_dir():
- print(loser_dir)
- for svx in loser_dir.iterdir():
- print(svx)
- loser_data.append(Path(loser_dir , svx).name)
-
if request.method == "POST": # If the form has been submitted...
form = KatasterForm(request.POST) # A form bound to the POST data
if form.is_valid():
diff --git a/parsers/caves.py b/parsers/caves.py
index db1b94917..48c464f83 100644
--- a/parsers/caves.py
+++ b/parsers/caves.py
@@ -379,6 +379,9 @@ def getXML(text, itemname, minItems=1, maxItems=None, context=""):
This always succeeds, but it produces error message on the terminal and in the
DataIssues log.
+
+ Yes this is using the python2 style of string expansion and not f-expressions.
+ Sorry. This is very old.
"""
items = re.findall("<%(itemname)s>(.*?)%(itemname)s>" % {"itemname": itemname}, text, re.S)
if len(items) < minItems:
diff --git a/templates/cave_kataster.html b/templates/cave_kataster.html
index 72733710a..9da4ce055 100644
--- a/templates/cave_kataster.html
+++ b/templates/cave_kataster.html
@@ -29,7 +29,12 @@ This cave needs to be "katastered". If you have the new number issued by the Aus
Rename the .html files in expoweb
-{{cave_data|safe}}
+{{cave_data|safe}}
+
<kataster_number></kataster_number>
+
+
+→
+
<kataster_number>{{knum}}</kataster_number>
{% for e in entrance_data %}
{{e|safe}}
@@ -46,7 +51,7 @@ This cave needs to be "katastered". If you have the new number issued by the Aus
Rename the cave description directory in expoweb
- Edit all the 'href=' URLS (if they exist) inside all the cave_data and entrance_data files descriptive text to refer to the new directory
-
- Rename the directory (if it exists) inside the areacode directory, e.g. rename /{{cave.areacode}}/{{cave.unofficial_number}}/ as /{{cave.areacode}}/{{knum}}/ (if {{knum}} is the correct new kataster number). Do this last.
+
- Rename the directory (if it exists) inside the areacode directory, e.g. rename /{{cave.areacode}}/{{cave.unofficial_number}}/ as /{{cave.areacode}}/{{knum}}/ (if {{knum}} is the correct new kataster number). Do this last.
@@ -60,40 +65,46 @@ This cave needs to be "katastered". If you have the new number issued by the Aus
- Find the survex files for this cave and edit the *include inside the survex files to use the new kataster number
-
- find and edit the '*_station' tags in each entrance_data file and in the fixed points files in the loser repo.
+
- find and edit the '*_station' tags in each entrance_data file and in the fixed points files in the loser repo.
- Rename the survex files
-
- Run 'cavern caves-{{cave.areacode |safe}}/{{knum}}/{{knum}}.svx' and check it all works as you hope
+
- Run 'cavern caves-{{cave.areacode |safe}}/{{knum}}/{{knum}}.svx' and check it all works as you hope
- Run 'cavern caves-{{cave.areacode |safe}}/caves.svx' and check it all works as you hope
Sort out the *fix point(s) in both loser and in expoweb
-- Find the *fix point for each entrance (one or more in each entrance_data file) in expoweb
+
- Find the *fix point for each entrance (one or more in each entrance_data file) in expoweb. There are three fields where there might be a *fix value: 'tag_station', 'exact_station' and 'other_station'
+
- Change the name of each *fix point in the relevant survex file in loser
- Make the same name change(s) in each entrance file (in each entrance_data file) in expoweb
+Without fully parsing the entire survex *include tree (which this code does not do), it is impossible to find the *fix declaration file from the 'station' fields in the entrance_data files. However in area 1623 we conventionally store the *fix in a "known" place. This does not work for area 1626.
Set the historic alias forwarder in expoweb
-- Add the line
("{{cave.slug|safe}}", "{{cave.areacode |safe}}-{{knum}}"), to the end
+ - Add the line
("{{cave.slug|safe}}", "{{cave.areacode |safe}}-{{knum}}"), to the end
of the file cave_data/cavealiases.txt (don't forget the comma at the end of the line)
+This will cause lost of errors until the cave "{{cave.areacode |safe}}-{{knum}}" has been created by a full database reset.
+
+
Finally
- cd loser
git add *
-git commit -m 'Katastering {{cave.slug|safe}} to {{cave.areacode |safe}}-{{knum}}'
+git commit -m 'Katastering {{cave.slug|safe}} to {{cave.areacode |safe}}-{{knum}}'
git pull
git push
cd ../expoweb
git add *
-git commit -m 'Katastering {{cave.slug|safe}} to {{cave.areacode |safe}}-{{knum}}'
+git commit -m 'Katastering {{cave.slug|safe}} to {{cave.areacode |safe}}-{{knum}}'
git pull
git push
- It is then vital to do a complete databaseReset as troggle has internally indexed all those {{cave.slug}} files, the indexes are now out of date and horrible things will happen when people try to use troggle with any cave that has been altered:
-uv run databaseReset reset K{{knum}}
+uv run databaseReset reset K{{knum}}
- Look in the reset import warnings and errors report to see if anything has gone wrong:
expo.survex.com/dataissues
(in fact, look at this before you do any of this, so you can see what chnages.)