forked from expo/troggle
Drawings uploads git works
This commit is contained in:
@@ -114,10 +114,19 @@ def dwgupload(request, folder=None, gitdisable='no'):
|
||||
def dwgvalid(name):
|
||||
if name in [ '.gitignore', ]:
|
||||
return False
|
||||
if Path(name).suffix.lower() in ['.xml', '.th', '.th2', '', '.svg', '.jpg', '.pdf', '.jpeg', '.txt']:
|
||||
if Path(name).suffix.lower() in ['.xml', '.th', '.th2', '', '.svg', '.txt']:
|
||||
return True # dangerous, we should check the actual file binary signature
|
||||
return False
|
||||
|
||||
|
||||
def dwgvaliddisp(name):
|
||||
'''OK to display, even if we are not going to allow a new one to be uploaded
|
||||
'''
|
||||
if name in [ '.gitignore', ]:
|
||||
return False
|
||||
if Path(name).suffix.lower() in ['.xml', '.th', '.th2', '', '.svg', '.txt', '.jpg', '.jpeg', '.png', '.pdf']:
|
||||
return True # dangerous, we should check the actual file binary signature
|
||||
return False
|
||||
|
||||
filesaved = False
|
||||
actual_saved = []
|
||||
refused = []
|
||||
@@ -158,7 +167,11 @@ def dwgupload(request, folder=None, gitdisable='no'):
|
||||
saved_filename = fs.save(f.name, content=f)
|
||||
actual_saved.append(saved_filename)
|
||||
if gitdisable != 'yes':
|
||||
subprocess.call([git, "add", saved_filename], cwd=dirpath)
|
||||
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:
|
||||
@@ -166,9 +179,17 @@ def dwgupload(request, folder=None, gitdisable='no'):
|
||||
print(f'REFUSED {f.name}')
|
||||
if actual_saved: # maybe all were refused by the suffix test in dwgvalid()
|
||||
filesaved = True
|
||||
if len(actual_saved) > 1:
|
||||
dots = "..."
|
||||
else:
|
||||
dots = ""
|
||||
if gitdisable != 'yes':
|
||||
subprocess.call([git, "commit", "-m", f'Drawings upload - {list(multiple)}'], cwd=dirpath)
|
||||
|
||||
dr_commit = subprocess.run([git, "commit", "-m", f'Drawings upload - {actual_saved[0]}{dots}'], cwd=dirpath, capture_output=True, text=True)
|
||||
# This produces return code = 1 if it commits OK
|
||||
if dr_commit.returncode != 0:
|
||||
msgdata = 'Ask a nerd to fix this.\n\n' + dr_commit.stderr + '\n\n' + dr_commit.stdout + '\n\nreturn code: ' + str(dr_commit.returncode)
|
||||
message = f'Error code with git on server for this {actual_saved[0]}{dots}. Edits saved, added to git, but NOT committed.\n\n' + msgdata
|
||||
return render(request,'errors/generic.html', {'message': message})
|
||||
|
||||
files = []
|
||||
dirs = []
|
||||
@@ -180,7 +201,7 @@ def dwgupload(request, folder=None, gitdisable='no'):
|
||||
dirs.append(f.name)
|
||||
continue
|
||||
if f.is_file():
|
||||
if dwgvalid(f.name):
|
||||
if dwgvaliddisp(f.name):
|
||||
files.append(f.name)
|
||||
continue
|
||||
except FileNotFoundError:
|
||||
|
||||
Reference in New Issue
Block a user