diff options
author | Philip Sargent <philip.sargent@gmail.com> | 2024-12-27 22:57:34 +0000 |
---|---|---|
committer | Philip Sargent <philip.sargent@gmail.com> | 2024-12-27 22:57:34 +0000 |
commit | 8dbad16ece1ebbe4f65b56bbc26c7be526bbe328 (patch) | |
tree | 29632ed7327fa35d385e37773d8b152541ac746b /core/utils.py | |
parent | 60d24dc48ed7a32752b2292e4e8670903fad8638 (diff) | |
download | troggle-8dbad16ece1ebbe4f65b56bbc26c7be526bbe328.tar.gz troggle-8dbad16ece1ebbe4f65b56bbc26c7be526bbe328.tar.bz2 troggle-8dbad16ece1ebbe4f65b56bbc26c7be526bbe328.zip |
Editor field & cookie working for survex online edits
Diffstat (limited to 'core/utils.py')
-rw-r--r-- | core/utils.py | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/core/utils.py b/core/utils.py index a251ba0..161a7f6 100644 --- a/core/utils.py +++ b/core/utils.py @@ -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 |