summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2025-01-31 21:55:52 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2025-01-31 21:55:52 +0000
commitafa3727757f9faa402a92b8508d130b0bc68d797 (patch)
treec28ca91b2051c770aa8b54c36a7b928949ae0e0a
parent062ab3e5f80648fe727cb41a0a7c0b2d500de79d (diff)
downloadtroggle-afa3727757f9faa402a92b8508d130b0bc68d797.tar.gz
troggle-afa3727757f9faa402a92b8508d130b0bc68d797.tar.bz2
troggle-afa3727757f9faa402a92b8508d130b0bc68d797.zip
sed basics done for survex files in :loser:
-rw-r--r--core/views/cave_kataster.py59
-rw-r--r--templates/cave_kataster.html26
2 files changed, 64 insertions, 21 deletions
diff --git a/core/views/cave_kataster.py b/core/views/cave_kataster.py
index 747e88a..692890e 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 = "<br /><br />DANGER DANGER You will overwrite an existing katastered cave !!!<br />"
+ warning += "resetting proposed new kataster number to 666.<br /><br />"
+ 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 d8d57ae..0e664c6 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
</button>
{% endif %}
+<div style="color:red; font-weight: bold; font-size: large">
+{{warning|safe}}</div>
<h3>Rename the .html files in <var>expoweb</var></h3>
<div style="font-family: monospace; font-weight: bold;">
@@ -35,6 +37,17 @@ This cave needs to be "katastered". If you have the new number issued by the Aus
&nbsp;&nbsp;&nbsp;
&rarr;
<span style="color:grey">&lt;kataster_number&gt;</span><span style="color:blue">{{knum}}</span><span style="color:grey">&lt;/kataster_number&gt;</span>
+
+<br />
+&nbsp;&nbsp;&nbsp;<span style="color:grey">&lt;survex_file&gt;</span>{{cave.survex_file}}
+<span style="color:grey">&lt;/survex_file&gt;</span>
+<br />
+&nbsp;&nbsp;&nbsp;
+&rarr;
+<span style="color:grey">&lt;survex_file&gt;</span><span style="color:blue">caves-{{cave.areacode}}/{{knum}}/{{knum}}.svx</span>
+<span style="color:grey">&lt;/survex_file&gt;</span>
+
+
<p>
{% for e in entrance_data %}
{{e|safe}}</br />
@@ -65,6 +78,7 @@ This cave needs to be "katastered". If you have the new number issued by the Aus
{% endfor %}
</div>
<ul style="list-style: disc">
+<li>Beware that the capitalisation of the directory name in the <var>loser</var> repo may be different from the cave name in the <var>expoweb</var> repo.
<li> Find the survex files for this cave and edit the <samp>*include</samp> inside the survex files to use the new kataster number
<li> find and edit the <samp>'*_station'</samp> tags in each <samp>entrance_data</samp> file and in the fixed points files in the loser repo.
<li> Rename the survex files
@@ -82,14 +96,16 @@ This cave needs to be "katastered". If you have the new number issued by the Aus
<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>Edit these Entrance files:<br />
{% for e in entrances %}
-<samp>
-{{e}}.html<br />&nbsp;&nbsp;&nbsp;{% if e.tag_station%}</samp>tag_station: <samp>{{e.tag_station}}{% endif %}
-{% if e.other_station%}</samp>other_station: <samp>{{e.other_station}}{% endif %}<br /><samp>
+<b><samp>
+entrance_data/{{e}}.html{% if e.tag_station%}</samp><br />&nbsp;&nbsp;&nbsp;</b>tag_station:<b> <samp>{{e.tag_station}}{% endif %}
+{% if e.other_station%}</samp><br />&nbsp;&nbsp;&nbsp;</b>other_station:<b> <samp>{{e.other_station}}{% endif %}<br /><samp></b>
{% endfor %}
<h3>Set the historic alias forwarder in <var>expoweb</var></h3>
<ul style="list-style: disc">
-<li> Add the line <br /><samp>("{{cave.slug|safe}}", "<span style="color:blue">{{cave.areacode |safe}}-{{knum}}</span>"),</samp></br /> to the end
+<li> Add the line <br />
+<b><samp>("{{cave.slug|safe}}", "<span style="color:blue">{{cave.areacode |safe}}-{{knum}}</span>"),</samp></b></br />
+ to the end
of the file <var><a href="/cave_data/cavealiases.txt_edit">cave_data/cavealiases.txt</a></var> (don't forget the comma at the end of the line)
</ul>
<p>This will cause lots of errors until the cave <samp>"<span style="color:blue">{{cave.areacode |safe}}-{{knum}}</span>"</samp> 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
<h3>Ideal scenario</h3>
<p>
<p>Ideally you do this renumbering on a standalone instance of troggle running on a <var> &#9874; <a href="/handbook/troggle/troglaptop.html">troggle development laptop</a></var> 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 <em>and</em> 'cavern' runs without any new survex errors.
-<p>
+<h3>Copy this script and edit it to match the directory names on your PC</h3>
<textarea id="script" name="script" rows="{{rows}}" cols="100" style="font-size:small; font-weight: bold; background-color: LemonChiffon">
{{script}}
</textarea>