mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-03-30 06:09:51 +01:00
Editor field & cookie working for survex online edits
This commit is contained in:
@@ -42,7 +42,7 @@ Read this now: https://nerderati.com/a-python-epoch-timestamp-timezone-trap/
|
||||
TROG = {"pagecache": {"expedition": {}}, "caves": {"gcavelookup": {}, "gcavecount": {}}}
|
||||
alphabet = []
|
||||
sha = hashlib.new('sha256')
|
||||
|
||||
COOKIE_MAX_AGE = 12*60*60 # seconds
|
||||
throw = 35.0
|
||||
|
||||
class DatabaseResetOngoing(Exception):
|
||||
@@ -191,22 +191,31 @@ def parse_aliases(aliasfile):
|
||||
return [(None, None)], "Fail on file reading"
|
||||
return aliases, report
|
||||
|
||||
def only_commit(fname, message):
|
||||
def only_commit(fname, message, editor=None):
|
||||
"""Only used to commit a survex file edited and saved in view/survex.py"""
|
||||
git = settings.GIT
|
||||
cwd = fname.parent
|
||||
filename = fname.name
|
||||
# print(f'{fname=} ')
|
||||
|
||||
if editor:
|
||||
editor = git_string(editor)
|
||||
else:
|
||||
# cannot happen as form verification has this as an obligatory field
|
||||
editor = "Anathema Device <a.device@potatohut.expo>"
|
||||
|
||||
try:
|
||||
print(f"git add {filename}")
|
||||
cp_add = subprocess.run([git, "add", filename], cwd=cwd, capture_output=True, text=True)
|
||||
if cp_add.returncode != 0:
|
||||
msgdata = f"Ask a nerd to fix this problem in only_commit().\n--{cp_add.stderr}\n--{cp_add.stdout}\n--return code:{str(cp_add.returncode)}"
|
||||
raise WriteAndCommitError(
|
||||
f"CANNOT git ADD on server for this file {filename}. Edits saved but not added to git.\n\n" + msgdata
|
||||
)
|
||||
|
||||
cp_commit = subprocess.run([git, "commit", "-m", message], cwd=cwd, capture_output=True, text=True)
|
||||
print(f"git commit {filename}")
|
||||
print(f"Committing:\n{message=}\n{editor=}")
|
||||
cmd_commit = [git, "commit", "-m", message, "--author", f"{editor}"]
|
||||
|
||||
cp_commit = subprocess.run(cmd_commit, cwd=cwd, capture_output=True, text=True)
|
||||
# This produces return code = 1 if it commits OK, but when the local repo still needs to be pushed to origin/loser
|
||||
# which will be the case when running a test troggle system on a development machine
|
||||
devok_text = """On branch master
|
||||
@@ -229,9 +238,10 @@ nothing to commit, working tree clean
|
||||
)
|
||||
|
||||
except subprocess.SubprocessError:
|
||||
raise WriteAndCommitError(
|
||||
f"CANNOT git COMMIT on server for this file {filename}. Subprocess error. Edits not saved.\nAsk a nerd to fix this."
|
||||
)
|
||||
msg = f"CANNOT git COMMIT on server for this file {filename}. Subprocess error. Edits not saved.\nAsk a nerd to fix this."
|
||||
print(msg)
|
||||
raise WriteAndCommitError(msg)
|
||||
|
||||
|
||||
def git_string(author_string):
|
||||
"""Rewrites the supplied editor string intoa git-complient author string
|
||||
|
||||
Reference in New Issue
Block a user