2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-17 14:27:12 +00:00

cleaned up wallets import process

This commit is contained in:
2024-08-11 18:41:27 +03:00
parent fc145648e6
commit 3e198fc410
3 changed files with 39 additions and 32 deletions

View File

@@ -143,43 +143,41 @@ class Wallet(models.Model):
Reads JSON date and sets w.walletdate
This repeats a lot of stuff done in the initial parsing job:
traversing the file system.
Needs to be refactored as special handling of subdirectories is duplicated
import DataIssue locally to prevent import cycle problem"""
if hasattr(self, "JSONdata"):
return self.JSONdata
scans_path = Path(settings.SCANS_ROOT)
wurl = self.get_url()
# :drawings: walletjson/2022/2022#01/contents.json
# fpath = /mnt/d/EXPO/expofiles/surveyscans/1999/1999#02
# This does not work if there are subdirectories in the surveyscan folder
fp = Path(self.fpath)
if fp.name in archaic_wallets:
return None
if fp.parent.parent.parent.parent == scans_path:
print(f" ! ", end="")
if fp.parent.parent.parent.parent.parent == scans_path:
print(f" !! ", end="")
if fp.parent.parent.parent.parent == scans_path:
subfolder = fp.parent.name
wname = fp.parent.parent.name
wyear = fp.parent.parent.parent.name
print(f"\n - Subfolder {subfolder} one deep, detected in {wname}")
# print(f" - Subfolder {subfolder} two deep, detected in {wname=} {wyear=} {wurl=}")
else:
wname = fp.name
wyear = fp.parent.name
try:
y = int(wyear)
except:
message = f"\n! 2 or more deep subfolder detected?:\n {fp.parent.name=}\n {fp.name=} \n {self.fpath=}"
print(message)
# this is a hack, work down from /surveyscans instead. To be fixed
wname = fp.parent.parent.parent.name
wyear = fp.parent.parent.parent.parent.name
wurl = self.get_url()
try:
y = int(wyear)
except:
message = f"! 3 or more deep subfolder detected?:\n {fp.parent.name=}\n {fp.name=} \n {self.fpath=} {wurl=}"
print(message)
# this is a hack, work down from /surveyscans instead. To be fixed
wname = fp.parent.parent.parent.name
wyear = fp.parent.parent.parent.parent.name
if len(wyear) != 4 or len(wname) !=6:
# no contents.json for old-style wallets
# but this ruined all the tick-list displays.. why?!
@@ -188,6 +186,9 @@ class Wallet(models.Model):
jsonfile = Path(settings.DRAWINGS_DATA, "walletjson") / wyear / wname / "contents.json"
if not Path(jsonfile).is_file():
message = f"! {jsonfile} is not a file:\n {wyear=} (should be eg. '2035')\n {wname=} (should be eg. '2035#13')\n {self.fpath=}"
print(message)
if wname not in archaic_wallets:
message = f"! {jsonfile} is not a file:\n {wyear=} (should be eg. '2023')\n {wname=} (should be eg. '2023#13')\n {self.fpath=}"
print(message)