forked from expo/troggle
removing technical debt, replace convoluted code
This commit is contained in:
parent
aa20692ad6
commit
97b0ce8c96
@ -74,6 +74,8 @@ def chaosmonkey(n):
|
|||||||
def GetListDir(sdir):
|
def GetListDir(sdir):
|
||||||
'''handles url or file, so we can refer to a set of scans (not drawings) on another server
|
'''handles url or file, so we can refer to a set of scans (not drawings) on another server
|
||||||
returns a list of f (file), ff (file full path), is_dir (bool)
|
returns a list of f (file), ff (file full path), is_dir (bool)
|
||||||
|
|
||||||
|
REPLACE all use of this with Path.rglob() !
|
||||||
'''
|
'''
|
||||||
res = [ ]
|
res = [ ]
|
||||||
if type(sdir) is str and sdir[:7] == "http://":
|
if type(sdir) is str and sdir[:7] == "http://":
|
||||||
|
@ -73,9 +73,11 @@ def load_all_scans():
|
|||||||
It does NOT read or validate anything in the JSON data attached to each wallet. Those checks
|
It does NOT read or validate anything in the JSON data attached to each wallet. Those checks
|
||||||
are done at runtime, when a wallet is accessed, not at import time.
|
are done at runtime, when a wallet is accessed, not at import time.
|
||||||
|
|
||||||
NOTE that parsers/survex.py does NOT create a wallet if it finds an unrecognised *REF wallet.
|
Replace GetListDir with a more modern Path.iter idiom
|
||||||
Instead it reports an error in DataIssues. But it does make a link in the db between the
|
path = Path("scans")
|
||||||
existing wallet (probably no JSON, just a folder containing scans) and the survex file.
|
for p in path.rglob("*"):
|
||||||
|
print(p.name)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
print(' - Loading Survey Scans')
|
print(' - Loading Survey Scans')
|
||||||
|
|
||||||
@ -84,23 +86,55 @@ def load_all_scans():
|
|||||||
print(' - deleting all Wallet and SingleScan objects')
|
print(' - deleting all Wallet and SingleScan objects')
|
||||||
DataIssue.objects.filter(parser='scans').delete()
|
DataIssue.objects.filter(parser='scans').delete()
|
||||||
|
|
||||||
# first do the smkhs (large kh survey scans) directory
|
valids = [".top",".txt",".tif",".png",".jpg",".jpeg",".pdf",".svg",".gif",".xvi",
|
||||||
# this seems to be never used ?!
|
".json",".autosave",".sxd",".svx",".th",".th2",".tdr",".sql",".zip",".dxf",".3d",
|
||||||
#We should load all the scans, even for nonstandard names.
|
".ods",".csv",".xcf",".xml"]
|
||||||
manywallets_smkhs = Wallet(fpath=os.path.join(settings.SCANS_ROOT, "../surveys/smkhs"), walletname="smkhs")
|
validnames = ["thconfig","manifest"]
|
||||||
print("smkhs", end=' ')
|
|
||||||
if os.path.isdir(manywallets_smkhs.fpath):
|
|
||||||
manywallets_smkhs.save()
|
|
||||||
LoadListScansFile(manywallets_smkhs)
|
|
||||||
else:
|
|
||||||
print("smkhs NOT LOADED", end=' ')
|
|
||||||
|
|
||||||
# iterate into the surveyscans directory
|
# iterate into the surveyscans directory
|
||||||
|
# Not all folders with files in them are wallets.
|
||||||
|
# they are if they are /2010/2010#33
|
||||||
|
# or /1996-1999NotKHbook/
|
||||||
|
# but not if they are /2010/1010#33/therion or /1998/
|
||||||
print(' - ', end=' ')
|
print(' - ', end=' ')
|
||||||
for walletname, fpath, fisdir in GetListDir(settings.SCANS_ROOT):
|
scans_path = Path(settings.SCANS_ROOT)
|
||||||
|
seen = []
|
||||||
|
for p in scans_path.rglob('*'):
|
||||||
|
if p.is_file():
|
||||||
|
if p.suffix.lower() not in valids and p.name.lower() not in validnames:
|
||||||
|
# print(f"'{p}'", end='\n')
|
||||||
|
pass
|
||||||
|
elif p.parent == scans_path: # skip files directly in /surveyscans/
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if p.parent.parent.parent.parent == scans_path:
|
||||||
|
# print(f"too deep {p}", end='\n')
|
||||||
|
fpath = p.parent.parent
|
||||||
|
walletname = p.parent.parent.name # wallet is one level higher
|
||||||
|
else:
|
||||||
|
fpath = p.parent
|
||||||
|
walletname = p.parent.name
|
||||||
|
|
||||||
|
# UNFINISHED
|
||||||
|
tag = p.parent
|
||||||
|
if len(walletname)>4:
|
||||||
|
if walletname[4] == "#":
|
||||||
|
tag = p.parent.parent
|
||||||
|
|
||||||
|
if tag not in seen:
|
||||||
|
print(f"{tag.name}", end=' ')
|
||||||
|
seen.append(tag)
|
||||||
|
#wallet = Wallet(fpath=fpath, walletname=walletname)
|
||||||
|
|
||||||
|
|
||||||
|
print('\n UNFINISHED \n\n--- ')
|
||||||
|
for topfolder, fpath, fisdir in GetListDir(settings.SCANS_ROOT):
|
||||||
if not fisdir:
|
if not fisdir:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# do the year folders
|
||||||
|
if re.match(r"\d\d\d\d$", topfolder):
|
||||||
|
print(f"{topfolder}", end=' ')
|
||||||
for walletname, fpath, fisdir in GetListDir(fpath):
|
for walletname, fpath, fisdir in GetListDir(fpath):
|
||||||
if fisdir:
|
if fisdir:
|
||||||
wallet = Wallet(fpath=fpath, walletname=walletname)
|
wallet = Wallet(fpath=fpath, walletname=walletname)
|
||||||
@ -110,22 +144,9 @@ def load_all_scans():
|
|||||||
CheckEmptyPeople(wallet)
|
CheckEmptyPeople(wallet)
|
||||||
wallet.save()
|
wallet.save()
|
||||||
LoadListScansFile(wallet)
|
LoadListScansFile(wallet)
|
||||||
|
else:
|
||||||
# # do the year folders
|
# but We *should* load all the scans, even for nonstandard names.
|
||||||
# if re.match(r"\d\d\d\d$", walletname):
|
print(f'\n - IGNORE {walletname} - {fpath}')
|
||||||
# print(f"{walletname}", end=' ')
|
|
||||||
# for walletname, fpath, fisdir in GetListDir(fpath):
|
|
||||||
# if fisdir:
|
|
||||||
# wallet = Wallet(fpath=fpath, walletname=walletname)
|
|
||||||
# # this is where we should record the year explicitly
|
|
||||||
# # line 347 of view/uploads.py and needs refactoring for loading contentsjson
|
|
||||||
# CheckEmptyDate(wallet)
|
|
||||||
# CheckEmptyPeople(wallet)
|
|
||||||
# wallet.save()
|
|
||||||
# LoadListScansFile(wallet)
|
|
||||||
# else:
|
|
||||||
# # but We *should* load all the scans, even for nonstandard names.
|
|
||||||
# print(f'\n - IGNORE {walletname} - {fpath}')
|
|
||||||
|
|
||||||
# but we also need to check if JSON exists, even if there are no uploaded scan files
|
# but we also need to check if JSON exists, even if there are no uploaded scan files
|
||||||
contents_path = Path(settings.DRAWINGS_DATA, "walletjson")
|
contents_path = Path(settings.DRAWINGS_DATA, "walletjson")
|
||||||
|
Loading…
Reference in New Issue
Block a user