From 03f88377dd2cfa120c2b9cd1481e27ebada39300 Mon Sep 17 00:00:00 2001 From: Bob Mottram <bob@freedombone.net> 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 7fc91f6b..ca43f16e 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('<br>', '\n').replace('<br \>', '\n') + contentStr = contentStr.replace('<p>', '').replace('</p>', '\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('<br>', '\n').replace('<br />', '\n') - contentStr = contentStr.replace('<p>', '').replace('</p>', '\n') + contentStr = gitFormatContent(content) patchLines = contentStr.split('\n') patchFilename = None diff --git a/inbox.py b/inbox.py index 204aeb1b..d783d812 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('<br>', '\n').replace('<br \>', '\n') - contentStr = contentStr.replace('<p>', '').replace('</p>', '\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: