2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2025-01-31 15:32:35 +00:00

Removed encoding of file paths as encoding now correct

This commit is contained in:
Martin Green 2022-06-22 09:08:01 +01:00
parent 836387057a
commit ea880915b0

View File

@ -19,8 +19,6 @@ from troggle.core.models.caves import Cave
import troggle.core.views.caves import troggle.core.views.caves
import troggle.settings as settings import troggle.settings as settings
import sys
sysdefaultencoding = sys.getdefaultencoding()
'''Formerly a separate package called 'flatpages' written by Martin Green 2011. '''Formerly a separate package called 'flatpages' written by Martin Green 2011.
This was NOT django.contrib.flatpages which stores HTML in the database, so the name was changed to expopages. This was NOT django.contrib.flatpages which stores HTML in the database, so the name was changed to expopages.
@ -223,7 +221,7 @@ def expopage(request, path):
return render(request, 'dirnotfound.html', {'path': path, 'subpath': path[0:-1]}) return render(request, 'dirnotfound.html', {'path': path, 'subpath': path[0:-1]})
# So it must be a file in /expoweb/ but not .htm or .html probably an image # So it must be a file in /expoweb/ but not .htm or .html probably an image
filetobeopened = os.path.normpath(expowebpath / path) filetobeopened = expowebpath / path
try: try:
content = open(filetobeopened, "rb") content = open(filetobeopened, "rb")
@ -282,7 +280,7 @@ def editexpopage(request, path):
try: try:
filepath = Path(settings.EXPOWEB) / path filepath = Path(settings.EXPOWEB) / path
o = open(os.path.normpath(filepath).encode(sysdefaultencoding), "r", encoding="utf8") o = open(filepath, "r", encoding="utf8")
html = o.read() html = o.read()
autogeneratedmatch = re.search(r"\<\!--\s*(.*?(Do not edit|It is auto-generated).*?)\s*--\>", html, re.DOTALL + re.IGNORECASE) autogeneratedmatch = re.search(r"\<\!--\s*(.*?(Do not edit|It is auto-generated).*?)\s*--\>", html, re.DOTALL + re.IGNORECASE)
if autogeneratedmatch: if autogeneratedmatch:
@ -367,7 +365,7 @@ def write_and_commit(filepath, content):
# GIT see also core/views/uploads.py dwgupload() # GIT see also core/views/uploads.py dwgupload()
try: try:
with open(os.path.normpath(filepath).encode(sysdefaultencoding), "w", encoding="utf8") as f: with open(filepath, "w", encoding="utf8") as f:
print(f'WRITING{cwd}---{filename} ') print(f'WRITING{cwd}---{filename} ')
# as the wsgi process www-data, we have group write-access but are not owner, so cannot chmod. # as the wsgi process www-data, we have group write-access but are not owner, so cannot chmod.
# os.chmod(filepath, 0o664) # set file permissions to rw-rw-r-- # os.chmod(filepath, 0o664) # set file permissions to rw-rw-r--
@ -377,14 +375,13 @@ def write_and_commit(filepath, content):
raise WriteAndCommitError(message) raise WriteAndCommitError(message)
try: try:
encoded_filename = filename.encode(sysdefaultencoding) cp_add = subprocess.run([git, "add", filename], cwd=cwd, capture_output=True, text=True)
cp_add = subprocess.run([git, "add", encoded_filename], cwd=cwd, capture_output=True, text=True)
if cp_add.returncode != 0: if cp_add.returncode != 0:
msgdata = 'Ask a nerd to fix this.\n\n' + cp_add.stderr + '\n\n' + cp_add.stdout + '\n\nreturn code: ' + str(cp_add.returncode) msgdata = 'Ask a nerd to fix this.\n\n' + cp_add.stderr + '\n\n' + cp_add.stdout + '\n\nreturn code: ' + str(cp_add.returncode)
message = f'CANNOT git on server for this file {filename}. Edits saved but not added to git.\n\n' + msgdata message = f'CANNOT git on server for this file {filename}. Edits saved but not added to git.\n\n' + msgdata
raise WriteAndCommitError(message) raise WriteAndCommitError(message)
cp_commit = subprocess.run([git, "commit", "-m", f'Troggle online: Edit this page - {encoded_filename}'], cwd=cwd, capture_output=True, text=True) cp_commit = subprocess.run([git, "commit", "-m", f'Troggle online: Edit this page - {filename}'], cwd=cwd, capture_output=True, text=True)
# This produces return code = 1 if it commits OK, but when the repo still needs to be pushed to origin/expoweb # This produces return code = 1 if it commits OK, but when the repo still needs to be pushed to origin/expoweb
if cp_commit.returncode != 0 and cp_commit.stdout != 'nothing to commit, working tree clean': if cp_commit.returncode != 0 and cp_commit.stdout != 'nothing to commit, working tree clean':
msgdata = 'Ask a nerd to fix this.\n\n' + cp_commit.stderr + '\n\n' + cp_commit.stdout + '\n\nreturn code: ' + str(cp_commit.returncode) msgdata = 'Ask a nerd to fix this.\n\n' + cp_commit.stderr + '\n\n' + cp_commit.stdout + '\n\nreturn code: ' + str(cp_commit.returncode)