diff options
author | Philip Sargent <philip.sargent@klebos.com> | 2021-04-13 22:27:01 +0100 |
---|---|---|
committer | Philip Sargent <philip.sargent@klebos.com> | 2021-04-13 22:27:01 +0100 |
commit | daf58e9e45b5c2d94cbdcd00d9883cfa6b01c6dd (patch) | |
tree | cd133a50d9a0fba265b6b07b6ff66cf01cce655a /parsers/surveys.py | |
parent | 2467065ac35e17938750f1d977ecf799f529ee07 (diff) | |
download | troggle-daf58e9e45b5c2d94cbdcd00d9883cfa6b01c6dd.tar.gz troggle-daf58e9e45b5c2d94cbdcd00d9883cfa6b01c6dd.tar.bz2 troggle-daf58e9e45b5c2d94cbdcd00d9883cfa6b01c6dd.zip |
replace assert() with message logging
Diffstat (limited to 'parsers/surveys.py')
-rw-r--r-- | parsers/surveys.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/parsers/surveys.py b/parsers/surveys.py index bba5d3f..11aa805 100644 --- a/parsers/surveys.py +++ b/parsers/surveys.py @@ -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] |