mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-17 23:27:09 +00:00
kataaster tool complete (probably buggy)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user