From 03f88377dd2cfa120c2b9cd1481e27ebada39300 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 2 May 2020 17:06:13 +0000 Subject: [PATCH] Removing html formatting from patch --- git.py | 16 ++++++++++++---- inbox.py | 9 +++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/git.py b/git.py index 7fc91f6be..ca43f16ee 100644 --- a/git.py +++ b/git.py @@ -9,6 +9,17 @@ __status__ = "Production" import os +def gitFormatContent(content) -> str: + """ replace html formatting, so that it's more + like the original patch file + """ + contentStr = content.replace('
', '\n').replace('
', '\n') + contentStr = contentStr.replace('

', '').replace('

', '\n') + if 'From ' in contentStr: + contentStr = contentStr.split('From ', 1)[1] + return contentStr + + def getGitProjectName(baseDir: str, nickname: str, domain: str, subject: str) -> str: """Returns the project name for a git patch @@ -76,10 +87,7 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str, subject, content): return False - # replace html formatting, so that it's more - # like the original patch file - contentStr = content.replace('
', '\n').replace('
', '\n') - contentStr = contentStr.replace('

', '').replace('

', '\n') + contentStr = gitFormatContent(content) patchLines = contentStr.split('\n') patchFilename = None diff --git a/inbox.py b/inbox.py index 204aeb1b3..d783d812e 100644 --- a/inbox.py +++ b/inbox.py @@ -60,7 +60,7 @@ from question import questionUpdateVotes from media import replaceYouTube from git import isGitPatch from git import receiveGitPatch - +from git import gitFormatContent def storeHashTags(baseDir: str, nickname: str, postJsonObject: {}) -> None: """Extracts hashtags from an incoming post and updates the @@ -1708,12 +1708,9 @@ def gitPatchNotify(baseDir: str, handle: str, patchFile = accountDir + '/.newPatch' with open(patchFile, 'w') as fp: fp.write(subject) - contentStr = content.replace('
', '\n').replace('
', '\n') - contentStr = contentStr.replace('

', '').replace('

', '\n') - if 'From ' in contentStr: - contentStr = contentStr.split('From ', 1)[1] + with open(patchFile + 'Content', 'w') as fp: - fp.write(contentStr) + fp.write(gitFormatContent(content)) def groupHandle(baseDir: str, handle: str) -> bool: