diff --git a/core/views/cave_kataster.py b/core/views/cave_kataster.py
index 747e88a15..692890e4b 100644
--- a/core/views/cave_kataster.py
+++ b/core/views/cave_kataster.py
@@ -23,6 +23,17 @@ is 'katastered', ie.e moves from an informal number, such as
1623-2024-BL-10 to 1623-999
"""
+def get_loser_dir(cave):
+ """ Copes with capitalisation mismatch between declared loser diretory and actual
+ """
+ loser_name = f"{str(cave.unofficial_number)}"
+ parent = settings.SURVEX_DATA / f"caves-{str(cave.areacode)}"
+
+ for dn in [loser_name, loser_name.lower(), loser_name.upper()]:
+ if ( parent / dn).is_dir():
+ return parent / dn, Path(f"caves-{str(cave.areacode)}") / dn
+ return None, None
+
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
@@ -48,11 +59,9 @@ def kataster(request, slug):
if str(ent.name).startswith(str(cave)):
print(ent.name)
entrance_data.append("entrance_data/"+ent.name)
- mvscript += f"mv {ent.name} {ent.name.replace(str(cave),str(knum))}\n"
-
- loser_name = f"caves-{str(cave.areacode)}/{str(cave.unofficial_number)}"
- loser_dir = settings.SURVEX_DATA / loser_name
+ mvscript += f"mv {ent.name} {ent.name.replace(str(cave.unofficial_number),str(knum))}\n"
loser_data = []
+ loser_dir, loser_name = get_loser_dir(cave)
if (loser_dir).is_dir():
print(loser_dir)
for svx in loser_dir.iterdir():
@@ -63,13 +72,24 @@ def kataster(request, slug):
def script_loser(knum):
global cavefilename, cave_data, entrance_data, loser_name, loser_data
- target= f"caves-{cave.areacode}/{str(knum)}"
+ loser_dir, loser_name = get_loser_dir(cave) #/home/philip/expo/loser/caves-1623/2024-jc-01 , caves-1623/2024-jc-01
+ target = loser_name.parent / str(knum)
+ survex_name = str(loser_name.name)
l_script = f"\ncd {settings.SURVEX_DATA}\n"
+ l_script += f'sed -i "/^*include/s/{survex_name}/{knum}/g" {loser_name.parent}/caves.svx\n'
+
+ l_script += f'sed -i "/^*equate/s/{survex_name}/{knum}/g" {loser_name}/{survex_name}.svx\n'
+ l_script += f'sed -i "/^*begin/s/{survex_name}/{knum}/" {loser_name}/{survex_name}.svx\n'
+ l_script += f'sed -i "/^*end/s/{survex_name}/{knum}/" {loser_name}/{survex_name}.svx\n'
+ l_script +=f"# These 'sed' edits will not do everything in all cases, but they do the basics\n\n"
+
l_script +=f"mv {loser_name} {target}\n"
- l_script +=f"cd {target}\n# But note that git ignores .log and .3d files\n"
+ l_script +=f"cd {target}\n"
for filename in loser_data:
- l_script +=f"mv {filename} {filename.replace(str(cave.unofficial_number),str(knum))}\n"
+ l_script +=f"mv {filename} {filename.replace(survex_name,str(knum))}\n"
+ l_script +=f"# But note that git ignores .log and .3d files\n"
+
return l_script
@@ -90,6 +110,8 @@ def kataster(request, slug):
entrances.append(e.entrance)
_ = do_file_finding(knum)
+ alias = f'(\\"{cave.slug()}\\", \\"{cave.areacode}-{knum}\\"),'
+ aliasfile = settings.CAVEDESCRIPTIONS / "cavealiases.txt"
try:
# this is a python generator idiom.
# see https://realpython.com/introduction-to-python-generators/
@@ -111,32 +133,37 @@ def kataster(request, slug):
print(msg)
# Restart script with POST data
- script = "# Conversion script\n# When doing it by hand, it is less error-prone to do the file re-namings last,\n"
- script += "# but in a script it does not matter so much, so long as everything is consistent and tested,\n"
- script += "# except that reversing changes using git does not always restore directories exactly.\n\n"
+ script = "# Conversion script - VERY INCOMPLETE AS YET\n# When doing it by hand, it is less error-prone to do the file re-namings last,\n"
+ script += "# but in a script it does not matter so much so long as everything is consistent and tested.\n"
+ script += "# Except that reversing changes using git does not always restore directories exactly\n# (because of .gitignore).\n\n"
script += "# Be careful with the directory names, they might not be the same on your PC as on the server\n\n"
+
+ warning =""
+
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():
clean = form.cleaned_data
knum = clean['kataster_number']
print(f" # kataster_number {clean['kataster_number']}")
-
- # DETECT if this is an LAREADY USED kataster number in this area ! If so, WARNING!!
- # (we might be half-way through, so it might exist)
+ if test := get_cave_from_slug(f"{cave.areacode}-{knum}"):
+ warning = "
DANGER DANGER You will overwrite an existing katastered cave !!!
"
+ warning += "resetting proposed new kataster number to 666.
"
+ knum = 666
else: # GET and fall-through if POST is not valid
form = KatasterForm()
script += do_file_finding(knum)
script += script_loser(knum)
- script_rows = str(min(35,3+script.count('\n')))
-
+
+ script += f'\necho "{alias}" >> {aliasfile}'
+ script_rows = str(min(35,3+script.count('\n')))
return render(
request,
"cave_kataster.html",
{
- "form": form,
+ "form": form, "warning": warning,
"cave": cave, "entrances": entrances,
"cave_data": cave_data, "entrance_data": entrance_data,
"loser_name": loser_name, "loser_data": loser_data,
diff --git a/templates/cave_kataster.html b/templates/cave_kataster.html
index d8d57aef2..0e664c669 100644
--- a/templates/cave_kataster.html
+++ b/templates/cave_kataster.html
@@ -26,6 +26,8 @@ This cave needs to be "katastered". If you have the new number issued by the Aus
{% endif %}
+
{% for e in entrance_data %} {{e|safe}} @@ -65,6 +78,7 @@ This cave needs to be "katastered". If you have the new number issued by the Aus {% endfor %}
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.
Edit these Entrance files: This will cause lots of errors until the cave "{{cave.areacode |safe}}-{{knum}}" has been created by a full database reset OR we can do an online rename of the "Cave" object in the database [code yet to be written] by pressing this button [button not yet implemented].
@@ -120,8 +136,8 @@ OR we can do an online rename of the "Cave" object in the database [code yet to
Ideally you do this renumbering on a standalone instance of troggle running on a ⚒ troggle development laptop and you don't push any of the git commits to the server until you have got all the niggles out of the conversion, i.e. the databaseReset runs locally without any warnings or errors introduced by your renaming and 'cavern' runs without any new survex errors.
-
+
{% for e in entrances %}
-
-{{e}}.html
{% if e.tag_station%}tag_station: {{e.tag_station}}{% endif %}
-{% if e.other_station%}other_station: {{e.other_station}}{% endif %}
+
+entrance_data/{{e}}.html{% if e.tag_station%}
tag_station: {{e.tag_station}}{% endif %}
+{% if e.other_station%}
other_station: {{e.other_station}}{% endif %}
{% endfor %}
Set the historic alias forwarder in expoweb
-
("{{cave.slug|safe}}", "{{cave.areacode |safe}}-{{knum}}"), to the end
+
+("{{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)
Ideal scenario
Copy this script and edit it to match the directory names on your PC