summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/views/cave_kataster.py73
-rw-r--r--templates/cave_kataster.html13
-rw-r--r--templates/controlPanel.html1
3 files changed, 66 insertions, 21 deletions
diff --git a/core/views/cave_kataster.py b/core/views/cave_kataster.py
index e5a3ea3..cc5f5ab 100644
--- a/core/views/cave_kataster.py
+++ b/core/views/cave_kataster.py
@@ -34,6 +34,25 @@ def get_loser_dir(cave):
return parent / dn, Path(f"caves-{str(cave.areacode)}") / dn
return None, None
+def get_cd(path):
+ return f"$BASE_DIR/{path.relative_to(settings.REPOS_ROOT_PATH)}"
+
+def entrances_list(cave):
+ entrances = []
+ for e in cave.entrances(): # horrid CaveAndEntrance indirection we need to refactor out in due course
+ if e.entrance.best_station():
+ entrances.append(e.entrance)
+ return entrances
+
+def entrances_stations(cave):
+ entrance_stations = []
+ for e in cave.entrances(): # horrid CaveAndEntrance indirection we need to refactor out in due course
+ if e.entrance.tag_station:
+ entrance_stations.append((e.entrance, e.entrance.tag_station[4:]))
+ if e.entrance.other_station:
+ entrance_stations.append((e.entrance, e.entrance.other_station[4:]))
+ return entrance_stations
+
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
@@ -43,12 +62,22 @@ def kataster(request, slug):
global cavefilename, cave_data, entrance_data, loser_name, loser_data
- mvscript = ""
+ mvscript = f"BASE_DIR={settings.REPOS_ROOT_PATH}\n\n"
ent_dir = settings.ENTRANCEDESCRIPTIONS # settings.EXPOWEB / "entrance_data"
- mvscript += f"cd {settings.ENTRANCEDESCRIPTIONS }\n"
+ mvscript += f"cd {get_cd(settings.ENTRANCEDESCRIPTIONS)}\n"
+
+ if cave.areacode == "1623":
+ pt_target = "$BASE_DIR/loser/fixedpts/gps/gps*.svx"
+ elif cave.areacode == "1626":
+ pt_target = "$BASE_DIR/loser/fixedpts/*.svx"
+ for ent, station in entrances_stations(cave):
+ new = station.replace(cave.unofficial_number,str(knum))
+ sed_cmd = f"s/{station}/{new}/g".replace(".","\.")
+ mvscript += f'sed -i {sed_cmd} {ent}.html\n'
+ mvscript += f'sed -i {sed_cmd} {pt_target}\n'
+
entrance_data = []
- # entrance_ids =[]
for ent in ent_dir.iterdir():
if str(ent.name).startswith(str(cave)):
print(ent.name)
@@ -56,7 +85,7 @@ def kataster(request, slug):
# entrance_ids.append(ent.name.replace(".html",""))
mvscript += f"mv {ent.name} {ent.name.replace(str(cave.unofficial_number),str(knum))}\n"
- mvscript += f"\ncd {settings.CAVEDESCRIPTIONS }\n"
+ mvscript += f"\ncd {get_cd(settings.CAVEDESCRIPTIONS)}\n"
cavefilename = str(cave) + ".html"
target= f"{cave.areacode}-{str(knum)}"
@@ -69,7 +98,10 @@ def kataster(request, slug):
mvscript += f'sed -i "/<entranceslug>/s/<entranceslug>{str(cave)}/<entranceslug>{cave.areacode}-{knum}/" {cavefilename}\n'
mvscript += f'sed -i "/href=\|src=/s/\/{cave.areacode}\/{cave.unofficial_number}\//\/{cave.areacode}\/{knum}\//g" {cavefilename}\n'
- mvscript += f"mv {cavefilename} {target}.html\n"
+ mvscript += f"mv {cavefilename} {target}.html\n\n"
+
+ mvscript += f"cd {get_cd(settings.EXPOWEB / cave.areacode / cave.unofficial_number)}\n"
+
loser_data = []
loser_dir, loser_name = get_loser_dir(cave)
@@ -86,10 +118,11 @@ def kataster(request, slug):
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"\ncd {get_cd(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 "/^*entrance/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"
@@ -98,13 +131,14 @@ def kataster(request, slug):
l_script +=f"cd {target}\n"
for filename in loser_data:
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"
+ l_script +=f"# But note that git ignores .log and .3d files\n\n"
+
+ # 1623 : fixedpts/gps/gps23.svx:26:*fix p2023-mg-03 reference 13.81514 47.69169 1767
+ # 1626: fixedpts/1626-no-schoenberg-hs-not-tied-to-caves.svx
return l_script
-
-
knum = 9999
@@ -115,14 +149,12 @@ def kataster(request, slug):
else:
return HttpResponseRedirect("/caves")
- entrances = []
- for e in cave.entrances(): # horrid CaveAndEntrance indirection we need to refactor out in due course
- if e.entrance.best_station():
- entrances.append(e.entrance)
+ entrances = entrances_list(cave)
+ # for e in cave.entrances(): # horrid CaveAndEntrance indirection we need to refactor out in due course
+ # if e.entrance.best_station():
+ # 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/
@@ -148,7 +180,7 @@ def kataster(request, slug):
script += "# after the edits, but in a script it does not matter so much\n"
script += "# 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 will usually NOT be the same on your PC as on the server\n\n"
+ script += "# Be careful with the BASE_DIR directory: usually NOT be the same on your PC as on the server\n\n"
warning =""
@@ -168,8 +200,15 @@ def kataster(request, slug):
script += do_file_finding(knum)
script += script_loser(knum)
+ alias = f'(\\"{cave.slug()}\\", \\"{cave.areacode}-{knum}\\"),'
+ aliasfile = settings.CAVEDESCRIPTIONS / "cavealiases.txt"
+ script += f'\necho "{alias}" >> {get_cd(aliasfile)}\n\n'
+
+ script += f"# grep to see what we have missed, though should still be records of the old name in expoweb.\n"
+ script += f"# (and gps_essentials will need refreshing)\n"
+ script += f'grep -nirI --exclude-dir=.git --exclude-dir=gpx --exclude="*.gpx" --exclude="*.log" --exclude="*.kml" --exclude="*.pos" "{cave.unofficial_number}" $BASE_DIR/loser\n'
+ script += f'grep -nirI --exclude-dir=.git --exclude="*.gpx" "{cave.unofficial_number}" $BASE_DIR/expoweb\n'
- script += f'\necho "{alias}" >> {aliasfile}'
script_rows = str(max(35,3+script.count('\n')))
return render(
request,
diff --git a/templates/cave_kataster.html b/templates/cave_kataster.html
index a00a91f..41b5024 100644
--- a/templates/cave_kataster.html
+++ b/templates/cave_kataster.html
@@ -63,13 +63,18 @@ This cave needs to be "katastered". If you have the new number issued by the Aus
</ul>
<h3>Rename the cave description directory in <var>expoweb</var></h3>
-[ TO DO ]
<p>
<ul style="list-style: disc">
<li> Edit all the '<samp>href=</samp>' and '<samp>src=</samp>' <small>URLS</small> (if they exist) inside all the <samp>cave_data</samp> and <samp>entrance_data</samp> files descriptive text to refer to the new directory
<li> Rename the directory (if it exists) inside the areacode directory, e.g. rename <samp>/{{cave.areacode}}/{{cave.unofficial_number}}/</samp> as <samp>/{{cave.areacode}}/<span style="color:blue">{{knum}}</span>/</samp> (if <span style="color:blue">{{knum}}</span> is the correct new kataster number). Do this last.
</ul>
-
+There are 82 cave description sub-files, i.e. single pages with a larger image and caption using the t/i/l convention, are not in <br>
+<samp><b>1623/[cave]/l/*.html</b></samp> but are directly in <br />
+<samp><b>1623/l/[cave]_*.html</b></samp> <br>
+due to early versions of Martin's image insertion tool for editing cave descriptions. 21 of these do not even have filenames beginning with [cave], the cave unofficial identifier, but are all digits. They seem to be all 2023 discoveries or caves which have had images added to their descriptions in 2023.
+<p>
+If we don't edit these, things will still work, i.e. cave description images will still appear, but the names of the files no longer match the new kataster name of the cave. Fixing this - so that these files are stored together with the rest of the stuff just for that cave - could be included in in this renaming tool, but is perhaps better done as another job - which needs doing as troggle does some weird perversions to display these images. Some of these caves may never be katastered.
+<p>
<h3>Rename the survex directory in <var>loser</var></h3>
<div style="font-family: monospace; font-weight: bold;">
@@ -101,9 +106,9 @@ Here are all the survex files which are involved with this cave, the first one o
and patching any <samp>*equate</samp> statements)
<li> Make the same name change(s) in each entrance (i.e. in each <samp>entrance_data</samp> file) in <var>expoweb</var>
</ul>
-<p>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 <samp>'station'</samp> 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.
+<p>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 <samp>'station'</samp> fields in the entrance_data files. However we conventionally store the *fix in a "known" place, so we try.
<p>Edit these Entrance files:<br />
-[ TO DO ]<p>
+<p>
{% for e in entrances %}
<b><samp>
entrance_data/{{e}}.html{% if e.tag_station%}</samp><br />&nbsp;&nbsp;&nbsp;</b>tag_station:<b> <samp>{{e.tag_station}}{% endif %}
diff --git a/templates/controlPanel.html b/templates/controlPanel.html
index 373526f..a7fed70 100644
--- a/templates/controlPanel.html
+++ b/templates/controlPanel.html
@@ -13,6 +13,7 @@
<li><a href="/survexdir">Survex Directories</a> - Every Cave has an associated directory and a Primary survex file
<li><a href="/surveximport">Survex import record</a> - indented *include and begin/end tree<br /><li><a href="/survexdebug">Survex debug report</a> - warnings and details<br />
<li><a href="/therionissues">Therion Import issues</a> - warnings from the recent data import<br /><br />
+<li><a href="/kataster/1623-2002-08">Kataster renumber</a> - Rename a cave to a new kataster number <span style="color:red">{{error}}</span>
<li><a href="/admin/">Django admin</a> - Deep magic access to all models and data <span style="color:red">{{error}}</span>
</ul>
<h3>This control panel is/will/maybe being redeveloped</h3>