fix bugs made visible by py 3.11

This commit is contained in:
2022-11-23 21:59:42 +00:00
parent b06d1dae42
commit 1eab261b30
8 changed files with 84 additions and 28 deletions

View File

@@ -152,9 +152,12 @@ class SubprocessTest(TestCase):
TROGGLE_PATH = Path(settings.REPOS_ROOT_PATH) / "troggle"
for cwd in [settings.SURVEX_DATA, settings.EXPOWEB, settings.DRAWINGS_DATA, TROGGLE_PATH]:
sp = subprocess.run([settings.GIT, "status"], cwd=cwd, capture_output=True, text=True)
print(f'git output: {cwd}:\n # {sp.stderr=}\n # {sp.stdout=} \n # return code: {str(sp.returncode)}')
out = str(sp.stdout)
if len(out) > 160:
out = out[:75] + "\n <Long output curtailed>\n" + out[-75:]
print(f'git output: {cwd}:\n # {sp.stderr=}\n # sp.stdout={out} \n # return code: {str(sp.returncode)}')
if sp.returncode != 0:
print(f'git output: {cwd}:\n # {sp.stderr=}\n # {sp.stdout=} \n # return code: {str(sp.returncode)}')
print(f'git output: {cwd}:\n # {sp.stderr=}\n # sp.stdout={out} \n # return code: {str(sp.returncode)}')
self.assertTrue( sp.returncode == 0, f'{cwd} - git is unhappy')
@@ -180,9 +183,12 @@ class SubprocessTest(TestCase):
cwd = settings.SURVEX_DATA
for survey in ["1623.svx", "1626.svx"]:
sp = subprocess.run([settings.CAVERN, survey], cwd=cwd, capture_output=True, text=True)
print(f'survex output: {cwd}:\n # {sp.stderr=}\n # {sp.stdout=} \n # return code: {str(sp.returncode)}')
out = str(sp.stdout)
if len(out) > 160:
out = out[:75] + "\n <Long output curtailed>\n" + out[-75:]
# print(f'survex output: {cwd}:\n # {sp.stderr=}\n # sp.stdout={out} \n # return code: {str(sp.returncode)}')
if sp.returncode != 0:
print(f'survex output: {cwd}:\n # {sp.stderr=}\n # {sp.stdout=} \n # return code: {str(sp.returncode)}')
print(f'survex output: {cwd}:\n # {sp.stderr=}\n # sp.stdout={out} \n # return code: {str(sp.returncode)}')
self.assertTrue( sp.returncode == 0, f'{cwd} - survex is unhappy')

View File

@@ -180,11 +180,17 @@ def writetrogglefile(filepath, filecontent):
#os.chmod(filepath, 0o664) # set file permissions to rw-rw-r--
sp = subprocess.run([git, "add", filename], cwd=cwd, capture_output=True, check=True, text=True)
if sp.returncode != 0:
print(f'git ADD {cwd}:\n\n' + str(sp.stderr) + '\n\n' + str(sp.stdout) + '\n\nreturn code: ' + str(sp.returncode))
out = sp.stdout
if len(out) > 160:
out = out[:75] + "\n <Long output curtailed>\n" + out[-75:]
print(f'git ADD {cwd}:\n\n' + str(sp.stderr) + '\n\n' + out + '\n\nreturn code: ' + str(sp.returncode))
sp = subprocess.run([git, "commit", "-m", f'Troggle online: cave or entrance edit -{filename}'], cwd=cwd, capture_output=True, check=True, text=True)
if sp.returncode != 0:
print(f'git COMMIT {cwd}:\n\n' + str(sp.stderr) + '\n\n' + str(sp.stdout) + '\n\nreturn code: ' + str(sp.returncode))
out = sp.stdout
if len(out) > 160:
out = out[:75] + "\n <Long output curtailed>\n" + out[-75:]
print(f'git COMMIT {cwd}:\n\n' + str(sp.stderr) + '\n\n' + out + '\n\nreturn code: ' + str(sp.returncode))
# not catching and re-raising any exceptions yet, inc. the stderr etc.,. We should do that.

View File

@@ -273,7 +273,7 @@ def svx(request, survex_file):
difflist.insert(0, message)
#print [ form.data['code'] ]
svxincludes = re.findall(r'\*include\s+(\S+)(?i)', form.data['code'] or "")
svxincludes = re.findall(r'(?i)\*include\s+(\S+)', form.data['code'] or "")
vmap = {'settings': settings,
'warning': warning,

View File

@@ -471,7 +471,7 @@ def scanupload(request, path=None):
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}')
print(f'\n !! Permissions failure ?! on attempting to save scanfile {f.name}')
if 'saved_filename' in locals():
if saved_filename.is_file():
actual_saved.append(saved_filename)
@@ -757,7 +757,13 @@ def photoupload(request, folder=None):
formd = TextForm(request.POST)
if formd.is_valid():
newphotographer = request.POST["photographer"]
(yearpath / newphotographer).mkdir(exist_ok=True)
try:
(yearpath / newphotographer).mkdir(exist_ok=True)
except:
message =f'\n !! Permissions failure ?! 0 attempting to mkdir "{(yearpath / newphotographer)}"'
print(message)
return render(request,'errors/generic.html', {'message': message})
else:
form = FilesRenameForm(request.POST,request.FILES)
if form.is_valid():
@@ -775,7 +781,7 @@ def photoupload(request, folder=None):
try: # crashes in Django os.chmod call if on WSL, but does save file!
saved_filename = fs.save(renameto, content=f)
except:
print(f'\n !! Permissions failure ?! on attempting to save file {f.name}')
print(f'\n !! Permissions failure ?! 1 attempting to save "{f.name}" in "{dirpath}" {renameto=}')
if 'saved_filename' in locals():
if saved_filename.is_file():
actual_saved.append(saved_filename)
@@ -784,17 +790,17 @@ def photoupload(request, folder=None):
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}')
print(f'\n !! Permissions failure ?! 2 attempting to save "{f.name}" in "{dirpath}" {renameto=}')
if 'saved_filename' in locals():
if saved_filename.is_file():
actual_saved.append(saved_filename)
filesaved = True
else: # multiole is a list of content
else: # multiple is a list of content
for f in multiple:
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}')
print(f'\n !! Permissions failure ?! 3 attempting to save "{f.name}" in "{dirpath}" {renameto=}')
if 'saved_filename' in locals():
if saved_filename.is_file():
actual_saved.append(saved_filename)
@@ -872,7 +878,8 @@ def dwgupload(request, folder=None, gitdisable='no'):
# print(f'! - FORM dwgupload - POST valid: "{request.FILES["uploadfiles"]}" ')
f = request.FILES["uploadfiles"]
multiple = request.FILES.getlist('uploadfiles')
fs = FileSystemStorage(os.path.join(settings.DRAWINGS_DATA, folder))
savepath = Path(settings.DRAWINGS_DATA, folder)
fs = FileSystemStorage(savepath)
actual_saved = []
refused = []
@@ -892,7 +899,7 @@ def dwgupload(request, folder=None, gitdisable='no'):
try: # crashes in Django os.chmod call if on WSL without metadata drvfs, but does save file!
saved_filename = fs.save(f.name, content=f)
except:
print(f'! - FORM dwgupload - \n!! Permissions failure ?! on attempting to save file {f.name}. Attempting to continue..')
print(f'! - FORM dwgupload - \n!! Permissions failure ?! on attempting to save file "{f.name}" in "{savepath}". Attempting to continue..')
if 'saved_filename' in locals():
if Path(dirpath, saved_filename).is_file():
actual_saved.append(saved_filename)
@@ -912,7 +919,7 @@ def dwgupload(request, folder=None, gitdisable='no'):
message = f'! - FORM dwgupload - NOT A FILE {Path(dirpath, saved_filename)=}. '
print(message)
else:
message = f'! - FORM dwgupload - Save failure for {saved_filename}. Changes NOT saved.'
message = f'! - FORM dwgupload - Save failure for {f.name}. Changes NOT saved.'
print(message)
return render(request,'errors/generic.html', {'message': message})