2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-17 14:47:08 +00:00

renamed tunnel to drawing or dwg

This commit is contained in:
Philip Sargent
2021-04-26 18:08:42 +01:00
parent f0d291f527
commit 37403a7234
5 changed files with 57 additions and 57 deletions

View File

@@ -199,13 +199,13 @@ class SingleScan(models.Model):
def __str__(self): def __str__(self):
return "Survey Scan Image: " + str(self.name) + " in " + str(self.scansfolder) return "Survey Scan Image: " + str(self.name) + " in " + str(self.scansfolder)
class TunnelFile(models.Model): class DrawingFile(models.Model):
tunnelpath = models.CharField(max_length=200) tunnelpath = models.CharField(max_length=200)
tunnelname = models.CharField(max_length=200) tunnelname = models.CharField(max_length=200)
bfontcolours = models.BooleanField(default=False) # UNUSED now, can be deleted bfontcolours = models.BooleanField(default=False) # UNUSED now, can be deleted
manyscansfolders = models.ManyToManyField("ScansFolder") # implicitly links via folders to scans to SVX files manyscansfolders = models.ManyToManyField("ScansFolder") # implicitly links via folders to scans to SVX files
scans = models.ManyToManyField("SingleScan") # implicitly links via scans to SVX files scans = models.ManyToManyField("SingleScan") # implicitly links via scans to SVX files
tunnelcontains = models.ManyToManyField("TunnelFile") # case when its a frame type tunnelcontains = models.ManyToManyField("DrawingFile") # case when its a frame type
filesize = models.IntegerField(default=0) filesize = models.IntegerField(default=0)
npaths = models.IntegerField(default=0) npaths = models.IntegerField(default=0)
survexfiles = models.ManyToManyField("SurvexFile") # direct link to SVX files - not populated yet survexfiles = models.ManyToManyField("SurvexFile") # direct link to SVX files - not populated yet

View File

@@ -92,7 +92,7 @@ def controlpanel(request):
import_surveyscans() import_surveyscans()
import_logbooks() import_logbooks()
import_QMs() import_QMs()
import_tunnelfiles() import_dwgfiles()
import_survexblks() import_survexblks()
import_survexpos() import_survexpos()
else: else:

View File

@@ -8,7 +8,7 @@ from django.conf import settings
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from troggle.core.models.survex import ScansFolder, SingleScan, SurvexBlock, TunnelFile from troggle.core.models.survex import ScansFolder, SingleScan, SurvexBlock, DrawingFile
from troggle.core.views.expo import getmimetype from troggle.core.views.expo import getmimetype
import parsers.surveys import parsers.surveys
@@ -50,8 +50,8 @@ def scanswallets(request):
def dwgdata(request): def dwgdata(request):
'''Report on all the drawing files in the system. These were loaded by parsing the entire directory tree '''Report on all the drawing files in the system. These were loaded by parsing the entire directory tree
''' '''
tunnelfiles = TunnelFile.objects.all() dwgfiles = DrawingFile.objects.all()
return render(request, 'dwgfiles.html', { 'tunnelfiles':tunnelfiles, 'settings': settings }) return render(request, 'dwgfiles.html', { 'dwgfiles':dwgfiles, 'settings': settings })
def dwgfilesingle(request, path): def dwgfilesingle(request, path):
@@ -59,12 +59,12 @@ def dwgfilesingle(request, path):
but it might be a Therion file but it might be a Therion file
''' '''
try: try:
tunnelfile = TunnelFile.objects.get(tunnelpath=urlunquote(path)) dwgfile = DrawingFile.objects.get(tunnelpath=urlunquote(path))
except: except:
message = f'Drawing file error or not found \'{path}\' .' message = f'Drawing file error or not found \'{path}\' .'
return render(request, 'errors/generic.html', {'message': message}) return render(request, 'errors/generic.html', {'message': message})
tfile = Path(settings.TUNNEL_DATA, tunnelfile.tunnelpath) tfile = Path(settings.TUNNEL_DATA, dwgfile.tunnelpath)
try: # for display not download try: # for display not download
return HttpResponse(content=open(tfile, errors='strict'), content_type="text/xhtml") return HttpResponse(content=open(tfile, errors='strict'), content_type="text/xhtml")
except UnicodeDecodeError: except UnicodeDecodeError:
@@ -82,11 +82,11 @@ def dwgfileupload(request, path):
'''uploads a drawing file, but where is the Form? This just processes POST info. Apparently unfinished? '''uploads a drawing file, but where is the Form? This just processes POST info. Apparently unfinished?
''' '''
try: try:
tunnelfile = TunnelFile.objects.get(tunnelpath=urlunquote(path)) # need to check if inavlid query string and produce friendly error dwgfile = DrawingFile.objects.get(tunnelpath=urlunquote(path)) # need to check if inavlid query string and produce friendly error
except: except:
message = f'Drawing file error or not found \'{path}\' .' message = f'Drawing file error or not found \'{path}\' .'
return render(request, 'errors/generic.html', {'message': message}) return render(request, 'errors/generic.html', {'message': message})
tfile = Path(settings.TUNNEL_DATA, tunnelfile.tunnelpath) tfile = Path(settings.TUNNEL_DATA, dwgfile.tunnelpath)
project, user, password, tunnelversion = request.POST["tunnelproject"], request.POST["tunneluser"], request.POST["tunnelpassword"], request.POST["tunnelversion"] project, user, password, tunnelversion = request.POST["tunnelproject"], request.POST["tunneluser"], request.POST["tunnelpassword"], request.POST["tunnelversion"]
print(project, user, tunnelversion) print(project, user, tunnelversion)
@@ -106,7 +106,7 @@ def dwgfileupload(request, path):
if os.path.split(path)[1] != uploadedfile.name: if os.path.split(path)[1] != uploadedfile.name:
return HttpResponse(content="Error: name disagrees", content_type="text/plain") return HttpResponse(content="Error: name disagrees", content_type="text/plain")
orgsize = tunnelfile.filesize # = os.stat(tfile)[stat.ST_SIZE] orgsize = dwgfile.filesize # = os.stat(tfile)[stat.ST_SIZE]
ttext = uploadedfile.read() ttext = uploadedfile.read()
@@ -117,11 +117,11 @@ def dwgfileupload(request, path):
fout.close() fout.close()
# redo its settings of # redo its settings of
parsers.surveys.SetTunnelfileInfo(tunnelfile) parsers.surveys.SetTunnelfileInfo(dwgfile) # commented out
tunnelfile.save() dwgfile.save()
uploadedfile.close() uploadedfile.close()
message = "File size %d overwritten with size %d" % (orgsize, tunnelfile.filesize) message = "File size %d overwritten with size %d" % (orgsize, dwgfile.filesize)
return HttpResponse(content=message, content_type="text/plain") return HttpResponse(content=message, content_type="text/plain")

View File

@@ -10,7 +10,7 @@ from PIL import Image
from functools import reduce from functools import reduce
import settings 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.models.troggle import DataIssue
from troggle.core.utils import save_carefully from troggle.core.utils import save_carefully
@@ -118,7 +118,7 @@ def LoadListScans():
LoadListScansFile(scansfolder) 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 '''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 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): if len(scansfolderl):
scansfolder = scansfolderl[0] scansfolder = scansfolderl[0]
if len(scansfolderl) > 1: 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) print(message)
DataIssue.objects.create(parser='Tunnel', message=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)) scansfilel = scansfolder.singlescan_set.filter(name=mscansdir.group(2))
if len(scansfilel): if len(scansfilel):
if len(scansfilel) > 1: 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) print(message)
DataIssue.objects.create(parser='Tunnel', message=message) DataIssue.objects.create(parser='Tunnel', message=message)
scansfile = scansfilel[0] scansfile = scansfilel[0]
if scansfolder: if scansfolder:
tunnelfile.manyscansfolders.add(scansfolder) dwgfile.manyscansfolders.add(scansfolder)
if scansfile: 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): elif path and not re.search(r"\.(?:png|jpg|pdf|jpeg|gif|pdf)$(?i)", path):
name = os.path.split(path)[1] name = os.path.split(path)[1]
rtunnelfilel = TunnelFile.objects.filter(tunnelname=name) rdwgfilel = DrawingFile.objects.filter(tunnelname=name)
if len(rtunnelfilel): if len(rdwgfilel):
message = "! Two paths with same name [{}]: {}".format(path, name) message = "! Two paths with same name [{}]: {}".format(path, name)
print(message) print(message)
DataIssue.objects.create(parser='Tunnel', message=message) DataIssue.objects.create(parser='Tunnel', message=message)
rtunnelfile = rtunnelfilel[0] rdwgfile = rdwgfilel[0]
tunnelfile.tunnelcontains.add(rtunnelfile) dwgfile.tunnelcontains.add(rdwgfile)
tunnelfile.save() dwgfile.save()
def findimageinsert(therionfile, xth_me): def findimageinsert(therionfile, xth_me):
'''Tries to link the drawing file (Therion format) to the referenced image (scan) file '''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) rx_input = re.compile(r'^input (\w*).*$', re.MULTILINE)
def settherionfileinfo(filetuple): 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 thtype, therionfile = filetuple
@@ -199,7 +199,7 @@ def settherionfileinfo(filetuple):
therionfile.save() therionfile.save()
# scan and look for survex blocks that might have been included, and image scans (as for tunnel drawings) # 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: # in .th2 files:
# ##XTHERION## xth_me_image_insert {500 1 1.0} {1700 {}} ../../../expofiles/surveyscans/2014/01popped_elev1.jpeg 0 {} # ##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_skpath = re.compile(rb'<skpath')
rx_pcpath = re.compile(rb'<pcarea area_signal="frame".*?sfsketch="([^"]*)" sfstyle="([^"]*)"') rx_pcpath = re.compile(rb'<pcarea area_signal="frame".*?sfsketch="([^"]*)" sfstyle="([^"]*)"')
def settunnelfileinfo(tunnelfile): def setdwgfileinfo(dwgfile):
'''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
Should try to read the date too e.g. tunneldate="2010-08-16 22:51:57 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. then we could display on the master calendar per expo.
''' '''
ff = os.path.join(settings.TUNNEL_DATA, tunnelfile.tunnelpath) ff = os.path.join(settings.TUNNEL_DATA, dwgfile.tunnelpath)
tunnelfile.filesize = os.stat(ff)[stat.ST_SIZE] dwgfile.filesize = os.stat(ff)[stat.ST_SIZE]
if tunnelfile.filesize <= 0: if dwgfile.filesize <= 0:
message = "! Zero length xml file {}".format(ff) message = "! Zero length xml file {}".format(ff)
print(message) print(message)
DataIssue.objects.create(parser='Drawings', message=message) DataIssue.objects.create(parser='Drawings', message=message)
@@ -240,20 +240,20 @@ def settunnelfileinfo(tunnelfile):
ttext = fin.read() ttext = fin.read()
fin.close() fin.close()
tunnelfile.npaths = len(rx_skpath.findall(ttext)) dwgfile.npaths = len(rx_skpath.findall(ttext))
tunnelfile.save() dwgfile.save()
# example drawing file in Tunnel format. # example drawing file in Tunnel format.
# <tunnelxml tunnelversion="version2009-06-21 Matienzo" tunnelproject="ireby" tunneluser="goatchurch" tunneldate="2009-06-29 23:22:17"> # <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"> # <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): 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 # 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(): def load_drawings_files():
@@ -261,7 +261,7 @@ def load_drawings_files():
''' '''
all_xml = [] all_xml = []
drawdatadir = settings.TUNNEL_DATA drawdatadir = settings.TUNNEL_DATA
TunnelFile.objects.all().delete() DrawingFile.objects.all().delete()
DataIssue.objects.filter(parser='Drawings').delete() DataIssue.objects.filter(parser='Drawings').delete()
DataIssue.objects.filter(parser='Therion').delete() DataIssue.objects.filter(parser='Therion').delete()
DataIssue.objects.filter(parser='Tunnel').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! drawingsdirs.append(lf) # lunatic! adding to list in middle of list while loop!
elif f[-4:] == ".xml": elif f[-4:] == ".xml":
# Always creates new # Always creates new
tunnelfile = TunnelFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1]) dwgfile = DrawingFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1])
tunnelfile.save() dwgfile.save()
all_xml.append(('xml',tunnelfile)) all_xml.append(('xml',dwgfile))
elif f[-3:] == ".th": elif f[-3:] == ".th":
# Always creates new # Always creates new
tunnelfile = TunnelFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1]) dwgfile = DrawingFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1])
tunnelfile.save() dwgfile.save()
all_xml.append(('th',tunnelfile)) all_xml.append(('th',dwgfile))
elif f[-4:] == ".th2": elif f[-4:] == ".th2":
# Always creates new # Always creates new
tunnelfile = TunnelFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1]) dwgfile = DrawingFile(tunnelpath=lf, tunnelname=os.path.split(f[:-4])[1])
tunnelfile.save() dwgfile.save()
all_xml.append(('th2',tunnelfile)) all_xml.append(('th2',dwgfile))
print(f' - {len(all_xml)} Drawings files found') print(f' - {len(all_xml)} Drawings files found')
for d in all_xml: for d in all_xml:
if d[0] == '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 # important to import .th2 files before .th so that we can assign them when found in .th files
if d[0] == 'th2': if d[0] == 'th2':
settherionfileinfo(d) settherionfileinfo(d)
if d[0] == 'th': if d[0] == 'th':
settherionfileinfo(d) settherionfileinfo(d)
# for drawfile in TunnelFile.objects.all(): # for drawfile in DrawingFile.objects.all():
# SetTunnelfileInfo(drawfile) # SetTunnelfileInfo(drawfile)

View File

@@ -10,27 +10,27 @@
<table style="font-size: 85%" width=95%> <table style="font-size: 85%" width=95%>
<tr><th>File</th><th>Size</th><th>Paths</th><th>Scans folder</th><th>Scan files</th><th>Frames</th></tr> <tr><th>File</th><th>Size</th><th>Paths</th><th>Scans folder</th><th>Scan files</th><th>Frames</th></tr>
{% for tunnelfile in tunnelfiles %} {% for dwgfile in dwgfiles %}
<tr> <tr>
<td><a href="{% url "dwgfilesingle" tunnelfile.tunnelpath %}">{{tunnelfile.tunnelpath}}</a></td> <td><a href="{% url "dwgfilesingle" dwgfile.tunnelpath %}">{{dwgfile.tunnelpath}}</a></td>
<td align="right" style="padding:2px">{{tunnelfile.filesize}}</td> <td align="right" style="padding:2px">{{dwgfile.filesize}}</td>
<td align="right" style="padding:2px">{{tunnelfile.npaths}}</td> <td align="right" style="padding:2px">{{dwgfile.npaths}}</td>
<td style="padding:2px"> <td style="padding:2px">
{% for scansfolder in tunnelfile.manyscansfolders.all %} {% for scansfolder in dwgfile.manyscansfolders.all %}
<a href="{{scansfolder.get_absolute_url}}">{{scansfolder.walletname}}</a> <a href="{{scansfolder.get_absolute_url}}">{{scansfolder.walletname}}</a>
{% endfor %} {% endfor %}
</td> </td>
<td style="padding:2px"> <td style="padding:2px">
{% for singlescan in tunnelfile.scans.all %} {% for singlescan in dwgfile.scans.all %}
<a href="{{singlescan.get_absolute_url}}">{{singlescan.name}}</a> <a href="{{singlescan.get_absolute_url}}">{{singlescan.name}}</a>
{% endfor %} {% endfor %}
</td> </td>
<td style="padding:2px"> <td style="padding:2px">
{% for rtunnelfile in tunnelfile.tunnelcontains.all %} {% for rdwgfile in dwgfile.tunnelcontains.all %}
<a href="{% url "dwgfilesingle" rtunnelfile.tunnelpath %}">{{rtunnelfile.tunnelpath}}</a> <a href="{% url "dwgfilesingle" rdwgfile.tunnelpath %}">{{rdwgfile.tunnelpath}}</a>
{% endfor %} {% endfor %}
</td> </td>
</tr> </tr>