2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-01-19 09:22:32 +00:00

Make more robust to WSL chmod failures for tests

This commit is contained in:
Philip Sargent 2022-04-06 20:43:26 +03:00
parent 71ed0815cc
commit 18c2892967

View File

@ -46,7 +46,6 @@ todo = '''
https://stackoverflow.com/questions/889333/how-to-check-if-a-file-is-a-valid-image-file 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 - 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 - 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 = [] actual_saved = []
if multiple: if multiple:
for f in multiple: for f in multiple:
actual_saved.append( fs.save(f.name, content=f) ) try: # crashes in Django os.chmod call if on WSL, but does save file!
# print(f'! - FORM scanupload multiple {actual_saved}') saved_filename = fs.save(f.name, content=f)
filesaved = True 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 if not contents_path.is_file(): # double-check
with open(contents_path, "w") as json_file: with open(contents_path, "w") as json_file:
@ -367,8 +372,14 @@ def photoupload(request, folder=None):
actual_saved = [] actual_saved = []
if multiple: if multiple:
for f in multiple: for f in multiple:
actual_saved.append( fs.save(f.name, content=f) ) try: # crashes in Django os.chmod call if on WSL, but does save file!
filesaved = True 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 = [] files = []
dirs = [] dirs = []
try: try:
@ -456,16 +467,21 @@ def dwgupload(request, folder=None, gitdisable='no'):
if multiple: if multiple:
for f in multiple: for f in multiple:
if dwgvalid(f.name): if dwgvalid(f.name):
saved_filename = fs.save(f.name, content=f) try: # crashes in Django os.chmod call if on WSL, but does save file!
actual_saved.append(saved_filename) saved_filename = fs.save(f.name, content=f)
if gitdisable != 'yes': except:
dr_add = subprocess.run([git, "add", saved_filename], cwd=dirpath, capture_output=True, text=True) print(f'\n !! Permissions failure ?! on attempting to save file {f.name}')
if dr_add.returncode != 0: if 'saved_filename' in locals():
msgdata = 'Ask a nerd to fix this.\n\n' + dr_add.stderr + '\n\n' + dr_add.stdout + '\n\nreturn code: ' + str(dr_add.returncode) if saved_filename.is_file():
message = f'CANNOT git on server for this file {saved_filename}. Edits saved but not added to git.\n\n' + msgdata actual_saved.append(saved_filename)
return render(request,'errors/generic.html', {'message': message}) if gitdisable != 'yes':
dwgfile, created = DrawingFile.objects.get_or_create(dwgpath=saved_filename, dwgname=Path(f.name).stem, filesize=f.size) dr_add = subprocess.run([git, "add", saved_filename], cwd=dirpath, capture_output=True, text=True)
dwgfile.save() 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: else:
refused.append(f.name) refused.append(f.name)
print(f'REFUSED {f.name}') print(f'REFUSED {f.name}')