diff options
Diffstat (limited to 'core/utils.py')
-rw-r--r-- | core/utils.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/core/utils.py b/core/utils.py index 50746eb..6086b60 100644 --- a/core/utils.py +++ b/core/utils.py @@ -233,19 +233,19 @@ nothing to commit, working tree clean f"CANNOT git COMMIT on server for this file {filename}. Subprocess error. Edits not saved.\nAsk a nerd to fix this." ) -def g_string(author_string): +def git_string(author_string): # Regular expression for a git-compatible author string # valid example "John Doe <john.doe@example.com>" - author_regex = re.compile(r'^[a-zA-Z][\w\s\.\-]* <[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}>$') + author_regex = re.compile(r'^[a-zA-Z][\w\s\_\.\-]* <[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-_]+\.[a-zA-Z]{2,}>$') if author_regex.match(author_string): - print(f"Valid git-compatible author string: {author_string}") + print(f"Valid git-compatible author string: '{author_string}'") return author_string else: editor = author_string.replace("@","_at_") - editor = re.sub('[^0-9a-zA-Z_]+', '*', editor) + editor = re.sub('[^0-9a-zA-Z_\.]+', '*', editor) editor += f" <{editor}@potatohut.expo>" print(f"Not git-compatible author string, replacing as '{editor}'") return editor @@ -258,7 +258,7 @@ def write_and_commit(files, message, editor=None): git = settings.GIT commands = [] if editor: - editor = g_string(editor) + editor = git_string(editor) else: # cannot happen as form verification has this as an obligatory field editor = "Automatic <automaton@potatohut.expo>" @@ -373,6 +373,10 @@ class WriteAndCommitError(Exception): def writetrogglefile(filepath, filecontent, commit_msg=None): """ REPLACE with call to write_and_commit + any necessary setup + used only by cave editor in + core/models/caves.py + and by + make_new_expo_dir(year) Commit the new saved file to git Callers to cave.writeDataFile() or entrance.writeDataFile() should handle the exception PermissionsError explicitly |