2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-16 19:47:11 +00:00

replace assert() with message logging

This commit is contained in:
Philip Sargent
2021-04-13 22:27:01 +01:00
parent 2467065ac3
commit daf58e9e45
8 changed files with 43 additions and 29 deletions

View File

@@ -1,7 +1,6 @@
import sys
import os
import types
import logging
import stat
import csv
import re
@@ -46,13 +45,16 @@ def listdir(*directories):
def GetListDir(sdir):
res = [ ]
if sdir[:7] == "http://":
assert False, "Not written"
s = urllib.request.urlopen(sdir)
else:
for f in os.listdir(sdir):
if f[0] != ".":
ff = os.path.join(sdir, f)
res.append((f, ff, os.path.isdir(ff)))
# s = urllib.request.urlopen(sdir)
message = f"! Requesting loading from http:// NOT IMPLEMENTED. [{sdir}]"
print(message)
DataIssue.objects.create(parser='Drawings', message=message)
sdir[:7] = ""
for f in os.listdir(sdir):
if f[0] != ".":
ff = os.path.join(sdir, f)
res.append((f, ff, os.path.isdir(ff)))
return res
@@ -67,7 +69,6 @@ def LoadListScansFile(scansfolder):
c=0
for (fyf, ffyf, fisdiryf) in gld:
#assert not fisdiryf, ffyf
if re.search(r"\.(?:png|jpg|jpeg|pdf|svg|gif)(?i)$", fyf):
singlescan = SingleScan(ffile=ffyf, name=fyf, scansfolder=scansfolder)
singlescan.save()
@@ -106,7 +107,6 @@ def LoadListScans():
print("%s" % f, end=' ')
for fy, ffy, fisdiry in GetListDir(ff):
if fisdiry:
assert fisdiry, ffy
scansfolder = ScansFolder(fpath=ffy, walletname=fy)
scansfolder.save()
LoadListScansFile(scansfolder)
@@ -120,20 +120,25 @@ def LoadListScans():
def find_tunnel_scan(tunnelfile, path):
'''Is given a line of text 'path' which may or may not contain a recognisable name of a scanned file
which we have already seen when we imported all the files we could find in teh surveyscans direstories
which we have already seen when we imported all the files we could find in the surveyscans direstories
'''
scansfolder, scansfile = None, None
mscansdir = re.search(r"(\d\d\d\d#X?\d+\w?|1995-96kh|92-94Surveybookkh|1991surveybook|smkhs)/(.*?(?:png|jpg|pdf|jpeg))$", path)
if mscansdir:
scansfolderl = ScansFolder.objects.filter(walletname=mscansdir.group(1))
# This should properly detect if a list of folders is returned and do something sensible, not just pick the first.
if len(scansfolderl):
assert len(scansfolderl) == 1
scansfolder = scansfolderl[0]
if len(scansfolderl) > 1:
message = "! More than one scan FOLDER matches filter query. [{}]: {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), tunnelfile.tunnelpath, path)
print(message)
DataIssue.objects.create(parser='Tunnel', message=message)
if scansfolder:
scansfilel = scansfolder.singlescan_set.filter(name=mscansdir.group(2))
if len(scansfilel):
if len(scansfilel) > 1:
message = "! More than one image filename matches filter query. [{}]: {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), tunnelfile.tunnelpath, path)
message = "! More than one image FILENAME matches filter query. [{}]: {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), tunnelfile.tunnelpath, path)
print(message)
DataIssue.objects.create(parser='Tunnel', message=message)
scansfile = scansfilel[0]