summaryrefslogtreecommitdiffstats
path: root/core/views/expo.py
diff options
context:
space:
mode:
authorMartin Green <martin.speleo@gmail.com>2022-06-22 09:08:01 +0100
committerMartin Green <martin.speleo@gmail.com>2022-06-22 09:08:01 +0100
commitea880915b0eb728e0d666a828ffa360c6d59c200 (patch)
treef19c38269181c8a7e9928ba2368509cbc56aebc8 /core/views/expo.py
parent836387057a9be58e990325c9461db0923127fa6d (diff)
downloadtroggle-ea880915b0eb728e0d666a828ffa360c6d59c200.tar.gz
troggle-ea880915b0eb728e0d666a828ffa360c6d59c200.tar.bz2
troggle-ea880915b0eb728e0d666a828ffa360c6d59c200.zip
Removed encoding of file paths as encoding now correct
Diffstat (limited to 'core/views/expo.py')
-rw-r--r--core/views/expo.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/core/views/expo.py b/core/views/expo.py
index b419e48..885eafd 100644
--- a/core/views/expo.py
+++ b/core/views/expo.py
@@ -19,8 +19,6 @@ from troggle.core.models.caves import Cave
import troggle.core.views.caves
import troggle.settings as settings
-import sys
-sysdefaultencoding = sys.getdefaultencoding()
'''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.
@@ -223,7 +221,7 @@ def expopage(request, path):
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
- filetobeopened = os.path.normpath(expowebpath / path)
+ filetobeopened = expowebpath / path
try:
content = open(filetobeopened, "rb")
@@ -282,7 +280,7 @@ def editexpopage(request, path):
try:
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()
autogeneratedmatch = re.search(r"\<\!--\s*(.*?(Do not edit|It is auto-generated).*?)\s*--\>", html, re.DOTALL + re.IGNORECASE)
if autogeneratedmatch:
@@ -367,7 +365,7 @@ def write_and_commit(filepath, content):
# GIT see also core/views/uploads.py dwgupload()
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} ')
# 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--
@@ -377,14 +375,13 @@ def write_and_commit(filepath, content):
raise WriteAndCommitError(message)
try:
- encoded_filename = filename.encode(sysdefaultencoding)
- cp_add = subprocess.run([git, "add", encoded_filename], cwd=cwd, capture_output=True, text=True)
+ cp_add = subprocess.run([git, "add", filename], cwd=cwd, capture_output=True, text=True)
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)
message = f'CANNOT git on server for this file {filename}. Edits saved but not added to git.\n\n' + msgdata
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
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)