From a3a65524b86abde3bc924d611620f71f87b7bf36 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Sat, 5 Mar 2022 20:29:01 +0000 Subject: [PATCH] better errors for drawings parsing & upload --- core/views/uploads.py | 9 +++--- parsers/drawings.py | 58 +++++++++++++++++++++++++----------- templates/dwguploadform.html | 5 ++-- 3 files changed, 48 insertions(+), 24 deletions(-) diff --git a/core/views/uploads.py b/core/views/uploads.py index 2f3e053..6819e3d 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -109,12 +109,12 @@ def dwgupload(request, folder=None, gitdisable='no'): We use get_or_create instead of simply creating a new object in case someone uploads the same file several times in one session, and expects them to be overwritten in the database. Although - the actual file will be duplicated in the filesystem with different random name ammendation. + the actual file will be duplicated in the filesystem with different random name ending. ''' def dwgvalid(name): - if name in [ '.gitignore', '.hgignore', ]: + if name in [ '.gitignore', ]: return False - if Path(name).suffix.lower() in ['.xml', '.th', '.th2', '', '.svg', '.jpg', '.pdf', 'jpeg']: + if Path(name).suffix.lower() in ['.xml', '.th', '.th2', '', '.svg', '.jpg', '.pdf', '.jpeg', '.txt']: return True # dangerous, we should check the actual file binary signature return False @@ -163,10 +163,11 @@ def dwgupload(request, folder=None, gitdisable='no'): dwgfile.save() else: refused.append(f.name) + print(f'REFUSED {f.name}') if actual_saved: # maybe all were refused by the suffix test in dwgvalid() filesaved = True if gitdisable != 'yes': - subprocess.call([git, "commit", "-m", 'dwgupload'], cwd=dirpath) + subprocess.call([git, "commit", "-m", f'Drawings upload - {list(multiple)}'], cwd=dirpath) files = [] diff --git a/parsers/drawings.py b/parsers/drawings.py index a8306b1..024ce43 100644 --- a/parsers/drawings.py +++ b/parsers/drawings.py @@ -38,7 +38,7 @@ def find_dwg_file(dwgfile, path): which we have already seen when we imported all the files we could find in the surveyscans direstories ''' wallet, scansfile = None, None - mscansdir = re.search(r"(\d\d\d\d#X?\d+\w?|1995-96kh|92-94Surveybookkh|1991surveybook|smkhs)/(.*?(?:png|jpg|pdf|jpeg|gif))$", path) + mscansdir = re.search(r"(\d\d\d\d#X?\d+\w?|1995-96kh|92-94Surveybookkh|1991surveybook|smkhs)/(.*?(?:png|jpg|pdf|jpeg|gif|txt))$", path) if mscansdir: scanswalletl = Wallet.objects.filter(walletname=mscansdir.group(1)) # This should be chnaged to properly detect if a list of folders is returned and do something sensible, not just pick the first. @@ -66,7 +66,7 @@ def find_dwg_file(dwgfile, path): if scansfile: dwgfile.scans.add(scansfile) - elif path and not re.search(r"\.(?:png|jpg|pdf|jpeg|gif)$(?i)", path): + elif path and not re.search(r"\.(?:png|jpg|pdf|jpeg|gif|txt)$(?i)", path): name = os.path.split(path)[1] rdwgfilel = DrawingFile.objects.filter(dwgname=name) if len(rdwgfilel): @@ -76,7 +76,7 @@ def find_dwg_file(dwgfile, path): plist.append(df.dwgname) message = f"! {len(rdwgfilel)} paths found with same name '{path}' {plist}" print(message) - DataIssue.objects.create(parser='Tunnel', message=message) + DataIssue.objects.create(parser='Tunnel', message=message, url=f'/dwgdataraw/{path}') rdwgfile = rdwgfilel[0] dwgfile.dwgcontains.add(rdwgfile) @@ -106,7 +106,7 @@ def settherionfileinfo(filetuple): if therionfile.filesize <= 0: message = "! Zero length therion file {}".format(ff) print(message) - DataIssue.objects.create(parser='Therion', message=message) + DataIssue.objects.create(parser='Therion', message=message, url=f'/dwgdataraw/{therionfile.dwgpath}') return fin = open(ff,'r') ttext = fin.read() @@ -130,7 +130,7 @@ def settherionfileinfo(filetuple): for xth_me in rx_xth_me.findall(ttext): message = f'! Un-parsed image filename: {therionfile.dwgname} : {xth_me.split()[-3]} - {therionfile.dwgpath}' #print(message) - DataIssue.objects.create(parser='Therion', message=message) + DataIssue.objects.create(parser='xTherion', message=message, url=f'/dwgdataraw/{therionfile.dwgpath}') findimageinsert(therionfile, xth_me) for inp in rx_input.findall(ttext): @@ -138,7 +138,7 @@ def settherionfileinfo(filetuple): # but we would need to disentangle to get the current path properly message = f'! Un-set Therion .th2 input: - {therionfile.dwgname} : {inp} - {therionfile.dwgpath}' #print(message) - DataIssue.objects.create(parser='Therion', message=message) + DataIssue.objects.create(parser='xTherion', message=message, url=f'/dwgdataraw/{therionfile.dwgpath}') findimportinsert(therionfile, inp) therionfile.save() @@ -146,7 +146,7 @@ def settherionfileinfo(filetuple): rx_skpath = re.compile(rb'<No subdirectories> {% endfor %} -

Clicking on a filename only works if the drawing file has been imported into the system as part of a bulk-import - as we are matching it against a file recorded in the database. +

Clicking on a filename only shows the file if the drawing file had already been imported into the system as part of a bulk-import + as we are matching it against a file recorded in the database. If you only just uploaded it, you will get an error message. +

You cannot create folders here, but you can put files into any of the pre-existing folders. {% endif %}