mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-15 02:37:14 +00:00
Detect unwriteable file permissions earlier
This commit is contained in:
@@ -42,7 +42,8 @@ def writetrogglefile(filepath, filecontent):
|
||||
'''Set permissions to rw-rw-r-- and commit the new saved file to git
|
||||
Callers to cave.writeDataFile() or entrance.writeDataFile() should handle the exception PermissionsError explicitly
|
||||
'''
|
||||
# see also core/views/expo.py editexpopage()
|
||||
# GIT see also core/views/expo.py editexpopage()
|
||||
# GIT see also core/views/uploads.py dwgupload()
|
||||
filepath = Path(filepath)
|
||||
cwd = filepath.parent
|
||||
filename = filepath.name
|
||||
@@ -56,7 +57,7 @@ def writetrogglefile(filepath, filecontent):
|
||||
#os.chmod(filepath, 0o664) # set file permissions to rw-rw-r--
|
||||
# should replace .call with .run and capture_output=True
|
||||
call([git, "add", filename], cwd=cwd)
|
||||
call([git, "commit", "-m", 'Troggle online cave or entrance edit'], cwd=cwd)
|
||||
call([git, "commit", "-m", f'Troggle online: cave or entrance edit -{filename}'], cwd=cwd)
|
||||
|
||||
|
||||
class Area(TroggleModel):
|
||||
|
||||
@@ -142,7 +142,7 @@ def expowebpage(request, expowebpath, path):
|
||||
if m:
|
||||
editable = False
|
||||
else:
|
||||
editable = True
|
||||
editable = os.access(Path(expowebpath / path), os.W_OK) # are file permissions writeable?
|
||||
|
||||
has_menu = False
|
||||
menumatch = re.match(r'(.*)<div id="menu">', body, re.DOTALL + re.IGNORECASE)
|
||||
@@ -253,7 +253,7 @@ def getmimetype(path):
|
||||
@ensure_csrf_cookie
|
||||
def editexpopage(request, path):
|
||||
'''Manages the 'Edit this Page' capability for expo handbook and other html pages.
|
||||
Relies on javascript to provide the in-browser editing environment.
|
||||
Relies on HTML5 or javascript to provide the in-browser editing environment.
|
||||
'''
|
||||
try:
|
||||
# if a cave not a webpage at all.
|
||||
@@ -310,7 +310,8 @@ def editexpopage(request, path):
|
||||
cwd = filepath.parent
|
||||
filename = filepath.name
|
||||
git = settings.GIT
|
||||
# see also core/models/cave.py writetrogglefile()
|
||||
# GIT see also core/models/cave.py writetrogglefile()
|
||||
# GIT see also core/views/uploads.py dwgupload()
|
||||
try:
|
||||
with open(filepath, "w") as f:
|
||||
print(f'WRITING{cwd}---{filename} ')
|
||||
@@ -328,11 +329,11 @@ def editexpopage(request, path):
|
||||
message = f'CANNOT git on server for this file {filename}. Edits saved but not added to git.\n\n' + msgdata
|
||||
return render(request,'errors/generic.html', {'message': message})
|
||||
|
||||
cp_commit = subprocess.run([git, "commit", "-m", 'Edit this page'], cwd=cwd, capture_output=True, text=True)
|
||||
# This produces return code = 1 if it commits OK, but if the repo still needs to be pushed to origin/expoweb
|
||||
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)
|
||||
message = f'Eror code with git on server for this file {filename}. Edits saved, added to git but NOT committed.\n\n' + msgdata
|
||||
message = f'Error code with git on server for this file {filename}. Edits saved, added to git, but NOT committed.\n\n' + msgdata
|
||||
return render(request,'errors/generic.html', {'message': message})
|
||||
|
||||
except subprocess.SubprocessError:
|
||||
|
||||
@@ -144,6 +144,9 @@ def dwgupload(request, folder=None, gitdisable='no'):
|
||||
|
||||
actual_saved = []
|
||||
refused = []
|
||||
|
||||
# GIT see also core/views/expo.py editexpopage()
|
||||
# GIT see also core/models/cave.py writetrogglefile()
|
||||
if gitdisable != 'yes': # set in url 'dwguploadnogit/'
|
||||
git = settings.GIT
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user