summaryrefslogtreecommitdiffstats
path: root/core/views/uploads.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@klebos.com>2022-04-06 20:43:26 +0300
committerPhilip Sargent <philip.sargent@klebos.com>2022-04-06 20:43:26 +0300
commit18c28929678e8ea2b675c7e0f6531a574adeb4a8 (patch)
treedb29d5adff3afbf162dc66e12ade7822a687edc9 /core/views/uploads.py
parent71ed0815cc2393f68a9c2e8eeeadbe0bed619feb (diff)
downloadtroggle-18c28929678e8ea2b675c7e0f6531a574adeb4a8.tar.gz
troggle-18c28929678e8ea2b675c7e0f6531a574adeb4a8.tar.bz2
troggle-18c28929678e8ea2b675c7e0f6531a574adeb4a8.zip
Make more robust to WSL chmod failures for tests
Diffstat (limited to 'core/views/uploads.py')
-rw-r--r--core/views/uploads.py48
1 files changed, 32 insertions, 16 deletions
diff --git a/core/views/uploads.py b/core/views/uploads.py
index f572e8f..255b2b6 100644
--- a/core/views/uploads.py
+++ b/core/views/uploads.py
@@ -46,7 +46,6 @@ todo = '''
https://stackoverflow.com/questions/889333/how-to-check-if-a-file-is-a-valid-image-file
- Enable folder creation in dwguploads or as a separate form
-
- Register uploaded filenames in the Django db without needing to wait for a reset & bulk file import
'''
@@ -200,9 +199,15 @@ def scanupload(request, path=None):
actual_saved = []
if multiple:
for f in multiple:
- actual_saved.append( fs.save(f.name, content=f) )
- # print(f'! - FORM scanupload multiple {actual_saved}')
- filesaved = True
+ try: # crashes in Django os.chmod call if on WSL, but does save file!
+ saved_filename = fs.save(f.name, content=f)
+ except:
+ print(f'\n !! Permissions failure ?! on attempting to save file {f.name}')
+ if 'saved_filename' in locals():
+ if saved_filename.is_file():
+ actual_saved.append(saved_filename)
+ # print(f'! - FORM scanupload multiple {actual_saved}')
+ filesaved = True
if not contents_path.is_file(): # double-check
with open(contents_path, "w") as json_file:
@@ -367,8 +372,14 @@ def photoupload(request, folder=None):
actual_saved = []
if multiple:
for f in multiple:
- actual_saved.append( fs.save(f.name, content=f) )
- filesaved = True
+ try: # crashes in Django os.chmod call if on WSL, but does save file!
+ saved_filename = fs.save(f.name, content=f)
+ except:
+ print(f'\n !! Permissions failure ?! on attempting to save file {f.name}')
+ if 'saved_filename' in locals():
+ if saved_filename.is_file():
+ actual_saved.append(saved_filename)
+ filesaved = True
files = []
dirs = []
try:
@@ -456,16 +467,21 @@ def dwgupload(request, folder=None, gitdisable='no'):
if multiple:
for f in multiple:
if dwgvalid(f.name):
- saved_filename = fs.save(f.name, content=f)
- actual_saved.append(saved_filename)
- if gitdisable != 'yes':
- dr_add = subprocess.run([git, "add", saved_filename], cwd=dirpath, capture_output=True, text=True)
- if dr_add.returncode != 0:
- msgdata = 'Ask a nerd to fix this.\n\n' + dr_add.stderr + '\n\n' + dr_add.stdout + '\n\nreturn code: ' + str(dr_add.returncode)
- message = f'CANNOT git on server for this file {saved_filename}. Edits saved but not added to git.\n\n' + msgdata
- return render(request,'errors/generic.html', {'message': message})
- dwgfile, created = DrawingFile.objects.get_or_create(dwgpath=saved_filename, dwgname=Path(f.name).stem, filesize=f.size)
- dwgfile.save()
+ try: # crashes in Django os.chmod call if on WSL, but does save file!
+ saved_filename = fs.save(f.name, content=f)
+ except:
+ print(f'\n !! Permissions failure ?! on attempting to save file {f.name}')
+ if 'saved_filename' in locals():
+ if saved_filename.is_file():
+ actual_saved.append(saved_filename)
+ if gitdisable != 'yes':
+ dr_add = subprocess.run([git, "add", saved_filename], cwd=dirpath, capture_output=True, text=True)
+ if dr_add.returncode != 0:
+ msgdata = 'Ask a nerd to fix this.\n\n' + dr_add.stderr + '\n\n' + dr_add.stdout + '\n\nreturn code: ' + str(dr_add.returncode)
+ message = f'CANNOT git on server for this file {saved_filename}. Edits saved but not added to git.\n\n' + msgdata
+ return render(request,'errors/generic.html', {'message': message})
+ dwgfile, created = DrawingFile.objects.get_or_create(dwgpath=saved_filename, dwgname=Path(f.name).stem, filesize=f.size)
+ dwgfile.save()
else:
refused.append(f.name)
print(f'REFUSED {f.name}')