2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-12-15 21:17:07 +00:00

fix side effects in tests: git and file upload

This commit is contained in:
2021-10-31 19:25:45 +02:00
parent 252fcc4716
commit 2869f228d4
5 changed files with 61 additions and 77 deletions

View File

@@ -103,7 +103,7 @@ def scanupload(request, wallet=None):
{'form': form, 'wallet': wallet, **context, 'files': files, 'dirs': dirs, 'filesaved': filesaved, 'actual_saved': actual_saved})
@login_required_if_public
def dwgupload(request, folder=None):
def dwgupload(request, folder=None, gitdisable='no'):
'''Upload DRAWING files (tunnel or therion) into the upload folder in :drawings:
This does NOT use a Django model linked to a Django form. Just a simple Django form.
@@ -115,14 +115,14 @@ def dwgupload(request, folder=None):
if name in [ '.gitignore', '.hgignore', ]:
return False
if Path(name).suffix.lower() in ['.xml', '.th', '.th2', '', '.svg', '.jpg', '.pdf', 'jpeg']:
return True
return True # dangerous, we should check the actual file binary signature
return False
filesaved = False
actual_saved = []
refused = []
doesnotexist = ''
#print(f'! - FORM dwgupload - start "{folder}"')
# print(f'! - FORM dwgupload - start "{folder}" - gitdisable "{gitdisable}"')
if folder is None:
folder = "" # improve this later
dirpath = Path(settings.DRAWINGS_DATA)
@@ -144,28 +144,31 @@ def dwgupload(request, folder=None):
actual_saved = []
refused = []
git = settings.GIT
if gitdisable != 'yes': # set in url 'dwguploadnogit/'
git = settings.GIT
else:
git = 'echo'
if multiple:
for f in multiple:
if dwgvalid(f.name):
saved_filename = fs.save(f.name, content=f)
actual_saved.append(saved_filename)
subprocess.call([git, "add", saved_filename], cwd=dirpath)
# dwgfile = DrawingFile(dwgpath=f.name, dwgname=Path(f.name).stem, filesize=f.size)
if gitdisable != 'yes':
subprocess.call([git, "add", saved_filename], cwd=dirpath)
dwgfile, created = DrawingFile.objects.get_or_create(dwgpath=saved_filename, dwgname=Path(f.name).stem, filesize=f.size)
# if not created:
# print(f'FAILED to create {saved_filename} in {dirpath}')
# else:
# print(f'{dwgfile}')
dwgfile.save()
else:
refused.append(f.name)
# print(f'! - FORM dwgupload multiple {actual_saved}')
filesaved = True
subprocess.call([git, "commit", "-m", 'dwgupload'], cwd=dirpath)
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)
files = []
dirs = []
#print(f'! - FORM dwgupload - start {folder} \n"{dirpath}" \n"{dirpath.parent}" \n"{dirpath.exists()}"')
# print(f'! - FORM dwgupload - start {folder} \n"{dirpath}" \n"{dirpath.parent}" \n"{dirpath.exists()}"')
try:
for f in dirpath.iterdir():
if f.is_dir():