2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-24 08:11:52 +00:00

Fix skipped import error messages for drawings

This commit is contained in:
Philip Sargent 2020-07-29 22:54:53 +01:00
parent 95b9daca80
commit 3574dd4b1e

View File

@ -12,8 +12,6 @@ from utils import save_carefully
from functools import reduce from functools import reduce
import settings import settings
#from troggle.core.models import *
#from troggle.core.models_caves import *
from troggle.core.models_survex import SingleScan, ScansFolder, TunnelFile from troggle.core.models_survex import SingleScan, ScansFolder, TunnelFile
from troggle.core.models import DataIssue from troggle.core.models import DataIssue
@ -128,25 +126,24 @@ def FindTunnelScan(tunnelfile, path):
scansfilel = scansfolder.singlescan_set.filter(name=mscansdir.group(2)) scansfilel = scansfolder.singlescan_set.filter(name=mscansdir.group(2))
if len(scansfilel): if len(scansfilel):
if len(scansfilel) > 1: if len(scansfilel) > 1:
print("BORK more than one image filename matches filter query. ", scansfilel[0]) message = "! More than one image filename matches filter query. [{}]: {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), tunnelfile.tunnelpath, path)
print("BORK ", tunnelfile.tunnelpath, path) print(message)
print("BORK ", mscansdir.group(1), mscansdir.group(2), len(scansfilel)) DataIssue.objects.create(parser='Drawings', message=message)
#assert len(scansfilel) == 1
scansfile = scansfilel[0] scansfile = scansfilel[0]
if scansfolder: if scansfolder:
tunnelfile.manyscansfolders.add(scansfolder) tunnelfile.manyscansfolders.add(scansfolder)
if scansfile: if scansfile:
tunnelfile.scans.add(scansfile) tunnelfile.scans.add(scansfile)
elif path and not re.search(rb"\.(?:png|jpg|pdf|jpeg)$(?i)", path): elif path and not re.search(rb"\.(?:png|jpg|pdf|jpeg|gif|pdf)$(?i)", path):
name = os.path.split(path)[1] name = os.path.split(path)[1]
#print("debug-tunnelfileobjects ", tunnelfile.tunnelpath, path, name)
rtunnelfilel = TunnelFile.objects.filter(tunnelname=name) rtunnelfilel = TunnelFile.objects.filter(tunnelname=name)
if len(rtunnelfilel): if len(rtunnelfilel):
assert len(rtunnelfilel) == 1, ("two paths with name of", path, "need more discrimination coded") message = "! Two paths with same name [{}]: {}".format(path, name)
print(message)
DataIssue.objects.create(parser='Drawings', message=message)
rtunnelfile = rtunnelfilel[0] rtunnelfile = rtunnelfilel[0]
#print "ttt", tunnelfile.tunnelpath, path, name, rtunnelfile.tunnelpath
tunnelfile.tunnelcontains.add(rtunnelfile) tunnelfile.tunnelcontains.add(rtunnelfile)
tunnelfile.save() tunnelfile.save()
@ -155,15 +152,16 @@ def FindTunnelScan(tunnelfile, path):
def SetTunnelfileInfo(tunnelfile): def SetTunnelfileInfo(tunnelfile):
ff = os.path.join(settings.TUNNEL_DATA, tunnelfile.tunnelpath) ff = os.path.join(settings.TUNNEL_DATA, tunnelfile.tunnelpath)
tunnelfile.filesize = os.stat(ff)[stat.ST_SIZE] tunnelfile.filesize = os.stat(ff)[stat.ST_SIZE]
if tunnelfile.filesize <= 0:
message = "! Zero length xml file {}".format(ff)
print(message)
DataIssue.objects.create(parser='Drawings', message=message)
return
fin = open(ff,'rb') fin = open(ff,'rb')
ttext = fin.read() ttext = fin.read()
fin.close() fin.close()
if tunnelfile.filesize <= 0:
print("DEBUG - zero length xml file", ff)
return
mtype = re.search(rb"<(fontcolours|sketch)", ttext) mtype = re.search(rb"<(fontcolours|sketch)", ttext)
assert mtype, ff
tunnelfile.bfontcolours = (mtype.group(1)=="fontcolours") tunnelfile.bfontcolours = (mtype.group(1)=="fontcolours")
tunnelfile.npaths = len(re.findall(rb"<skpath", ttext)) tunnelfile.npaths = len(re.findall(rb"<skpath", ttext))
tunnelfile.save() tunnelfile.save()
@ -174,8 +172,8 @@ def SetTunnelfileInfo(tunnelfile):
FindTunnelScan(tunnelfile, path) FindTunnelScan(tunnelfile, path)
# should also scan and look for survex blocks that might have been included # should also scan and look for survex blocks that might have been included
# and also survex titles as well. # which would populate tunnelfile.survexfile
tunnelfile.save() tunnelfile.save()