summaryrefslogtreecommitdiffstats
path: root/parsers/surveys.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2021-04-26 18:08:42 +0100
committerPhilip Sargent <philip.sargent@klebos.com>2021-04-26 18:08:42 +0100
commit37403a7234a78ff10af4310b91e2258eef8bfb14 (patch)
treea2b469625c888a1bdcbf59b3f38e8e549108a431 /parsers/surveys.py
parentf0d291f527940cc3af8a0973a1fbb06cd1f949d7 (diff)
downloadtroggle-37403a7234a78ff10af4310b91e2258eef8bfb14.tar.gz
troggle-37403a7234a78ff10af4310b91e2258eef8bfb14.tar.bz2
troggle-37403a7234a78ff10af4310b91e2258eef8bfb14.zip
renamed tunnel to drawing or dwg
Diffstat (limited to 'parsers/surveys.py')
-rw-r--r--parsers/surveys.py70
1 files changed, 35 insertions, 35 deletions
diff --git a/parsers/surveys.py b/parsers/surveys.py
index 11aa805..30361d4 100644
--- a/parsers/surveys.py
+++ b/parsers/surveys.py
@@ -10,7 +10,7 @@ from PIL import Image
from functools import reduce
import settings
-from troggle.core.models.survex import SingleScan, ScansFolder, TunnelFile
+from troggle.core.models.survex import SingleScan, ScansFolder, DrawingFile
from troggle.core.models.troggle import DataIssue
from troggle.core.utils import save_carefully
@@ -118,7 +118,7 @@ def LoadListScans():
LoadListScansFile(scansfolder)
-def find_tunnel_scan(tunnelfile, path):
+def find_tunnel_scan(dwgfile, 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 the surveyscans direstories
'''
@@ -130,7 +130,7 @@ def find_tunnel_scan(tunnelfile, path):
if len(scansfolderl):
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)
+ message = "! More than one scan FOLDER matches filter query. [{}]: {} {} {} {}".format(scansfilel[0], mscansdir.group(1), mscansdir.group(2), dwgfile.tunnelpath, path)
print(message)
DataIssue.objects.create(parser='Tunnel', message=message)
@@ -138,27 +138,27 @@ def find_tunnel_scan(tunnelfile, path):
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), dwgfile.tunnelpath, path)
print(message)
DataIssue.objects.create(parser='Tunnel', message=message)
scansfile = scansfilel[0]
if scansfolder:
- tunnelfile.manyscansfolders.add(scansfolder)
+ dwgfile.manyscansfolders.add(scansfolder)
if scansfile:
- tunnelfile.scans.add(scansfile)
+ dwgfile.scans.add(scansfile)
elif path and not re.search(r"\.(?:png|jpg|pdf|jpeg|gif|pdf)$(?i)", path):
name = os.path.split(path)[1]
- rtunnelfilel = TunnelFile.objects.filter(tunnelname=name)
- if len(rtunnelfilel):
+ rdwgfilel = DrawingFile.objects.filter(tunnelname=name)
+ if len(rdwgfilel):
message = "! Two paths with same name [{}]: {}".format(path, name)
print(message)
DataIssue.objects.create(parser='Tunnel', message=message)
- rtunnelfile = rtunnelfilel[0]
- tunnelfile.tunnelcontains.add(rtunnelfile)
+ rdwgfile = rdwgfilel[0]
+ dwgfile.tunnelcontains.add(rdwgfile)
- tunnelfile.save()
+ dwgfile.save()
def findimageinsert(therionfile, xth_me):
'''Tries to link the drawing file (Therion format) to the referenced image (scan) file
@@ -175,7 +175,7 @@ rx_scrap = re.compile(r'^survey (\w*).*$', re.MULTILINE)
rx_input = re.compile(r'^input (\w*).*$', re.MULTILINE)
def settherionfileinfo(filetuple):
- '''Read in the drawing file contents and sets values on the tunnelfile object
+ '''Read in the drawing file contents and sets values on the dwgfile object
'''
thtype, therionfile = filetuple
@@ -199,7 +199,7 @@ def settherionfileinfo(filetuple):
therionfile.save()
# scan and look for survex blocks that might have been included, and image scans (as for tunnel drawings)
- # which would populate tunnelfile.survexfile
+ # which would populate dwgfile.survexfile
# in .th2 files:
# ##XTHERION## xth_me_image_insert {500 1 1.0} {1700 {}} ../../../expofiles/surveyscans/2014/01popped_elev1.jpeg 0 {}
@@ -224,14 +224,14 @@ def settherionfileinfo(filetuple):
rx_skpath = re.compile(rb'<skpath')
rx_pcpath = re.compile(rb'<pcarea area_signal="frame".*?sfsketch="([^"]*)" sfstyle="([^"]*)"')
-def settunnelfileinfo(tunnelfile):
- '''Read in the drawing file contents and sets values on the tunnelfile object
+def setdwgfileinfo(dwgfile):
+ '''Read in the drawing file contents and sets values on the dwgfile object
Should try to read the date too e.g. tunneldate="2010-08-16 22:51:57
then we could display on the master calendar per expo.
'''
- ff = os.path.join(settings.TUNNEL_DATA, tunnelfile.tunnelpath)
- tunnelfile.filesize = os.stat(ff)[stat.ST_SIZE]
- if tunnelfile.filesize <= 0:
+ ff = os.path.join(settings.TUNNEL_DATA, dwgfile.tunnelpath)
+ dwgfile.filesize = os.stat(ff)[stat.ST_SIZE]
+ if dwgfile.filesize <= 0:
message = "! Zero length xml file {}".format(ff)
print(message)
DataIssue.objects.create(parser='Drawings', message=message)
@@ -240,20 +240,20 @@ def settunnelfileinfo(tunnelfile):
ttext = fin.read()
fin.close()
- tunnelfile.npaths = len(rx_skpath.findall(ttext))
- tunnelfile.save()
+ dwgfile.npaths = len(rx_skpath.findall(ttext))
+ dwgfile.save()
# example drawing file in Tunnel format.
# <tunnelxml tunnelversion="version2009-06-21 Matienzo" tunnelproject="ireby" tunneluser="goatchurch" tunneldate="2009-06-29 23:22:17">
# <pcarea area_signal="frame" sfscaledown="12.282584" sfrotatedeg="-90.76982" sfxtrans="11.676667377221136" sfytrans="-15.677173422877454" sfsketch="204description/scans/plan(38).png" sfstyle="" nodeconnzsetrelative="0.0">
for path, style in rx_pcpath.findall(ttext):
- find_tunnel_scan(tunnelfile, path.decode())
+ find_tunnel_scan(dwgfile, path.decode())
# should also scan and look for survex blocks that might have been included, and image scans
- # which would populate tunnelfile.survexfile
+ # which would populate dwgfile.survexfile
- tunnelfile.save()
+ dwgfile.save()
def load_drawings_files():
@@ -261,7 +261,7 @@ def load_drawings_files():
'''
all_xml = []
drawdatadir = settings.TUNNEL_DATA
- TunnelFile.objects.all().delete()
+ DrawingFile.objects.all().delete()
DataIssue.objects.filter(parser='Drawings').delete()
DataIssue.objects.filter(parser='Therion').delete()
DataIssue.objects.filter(parser='Tunnel').delete()
@@ -278,30 +278,30 @@ def load_drawings_files():
drawingsdirs.append(lf) # lunatic! adding to list in middle of list while loop!
elif f[-4:] == ".xml":
# Always creates new
- tunnelfile = TunnelFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1])
- tunnelfile.save()
- all_xml.append(('xml',tunnelfile))
+ dwgfile = DrawingFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1])
+ dwgfile.save()
+ all_xml.append(('xml',dwgfile))
elif f[-3:] == ".th":
# Always creates new
- tunnelfile = TunnelFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1])
- tunnelfile.save()
- all_xml.append(('th',tunnelfile))
+ dwgfile = DrawingFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1])
+ dwgfile.save()
+ all_xml.append(('th',dwgfile))
elif f[-4:] == ".th2":
# Always creates new
- tunnelfile = TunnelFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1])
- tunnelfile.save()
- all_xml.append(('th2',tunnelfile))
+ dwgfile = DrawingFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1])
+ dwgfile.save()
+ all_xml.append(('th2',dwgfile))
print(f' - {len(all_xml)} Drawings files found')
for d in all_xml:
if d[0] == 'xml':
- settunnelfileinfo(d[1])
+ setdwgfileinfo(d[1])
# important to import .th2 files before .th so that we can assign them when found in .th files
if d[0] == 'th2':
settherionfileinfo(d)
if d[0] == 'th':
settherionfileinfo(d)
- # for drawfile in TunnelFile.objects.all():
+ # for drawfile in DrawingFile.objects.all():
# SetTunnelfileInfo(drawfile)