From f4cb24490af06bf2088df5223bdbc3f91035db1d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 6 Oct 2020 09:58:44 +0100 Subject: [PATCH] Tidying --- config.py | 46 ------------------------------------------- daemon.py | 6 +++--- epicyon.py | 4 ++-- newswire.py | 13 +++---------- person.py | 21 ++------------------ posts.py | 2 +- utils.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ webinterface.py | 2 +- 8 files changed, 64 insertions(+), 82 deletions(-) delete mode 100644 config.py diff --git a/config.py b/config.py deleted file mode 100644 index b290797b..00000000 --- a/config.py +++ /dev/null @@ -1,46 +0,0 @@ -__filename__ = "config.py" -__author__ = "Bob Mottram" -__license__ = "AGPL3+" -__version__ = "1.1.0" -__maintainer__ = "Bob Mottram" -__email__ = "bob@freedombone.net" -__status__ = "Production" - -import os -from utils import loadJson -from utils import saveJson - - -def createConfig(baseDir: str) -> None: - """Creates a configuration file - """ - configFilename = baseDir + '/config.json' - if os.path.isfile(configFilename): - return - configJson = { - } - saveJson(configJson, configFilename) - - -def setConfigParam(baseDir: str, variableName: str, variableValue) -> None: - """Sets a configuration value - """ - createConfig(baseDir) - configFilename = baseDir + '/config.json' - configJson = {} - if os.path.isfile(configFilename): - configJson = loadJson(configFilename) - configJson[variableName] = variableValue - saveJson(configJson, configFilename) - - -def getConfigParam(baseDir: str, variableName: str): - """Gets a configuration value - """ - createConfig(baseDir) - configFilename = baseDir + '/config.json' - configJson = loadJson(configFilename) - if configJson: - if configJson.get(variableName): - return configJson[variableName] - return None diff --git a/daemon.py b/daemon.py index 2b242ed2..f159f9e9 100644 --- a/daemon.py +++ b/daemon.py @@ -54,7 +54,6 @@ from person import registerAccount from person import personLookup from person import personBoxJson from person import createSharedInbox -from person import isSuspended from person import suspendAccount from person import unsuspendAccount from person import removeAccount @@ -101,8 +100,6 @@ from blocking import removeGlobalBlock from blocking import isBlockedHashtag from blocking import isBlockedDomain from blocking import getDomainBlocklist -from config import setConfigParam -from config import getConfigParam from roles import setRole from roles import clearModeratorStatus from blog import htmlBlogPageRSS2 @@ -159,6 +156,8 @@ from shares import getSharesFeedForPerson from shares import addShare from shares import removeShare from shares import expireShares +from utils import setConfigParam +from utils import getConfigParam from utils import removeIdEnding from utils import updateLikesCollection from utils import undoLikesCollectionEntry @@ -174,6 +173,7 @@ from utils import getStatusNumber from utils import urlPermitted from utils import loadJson from utils import saveJson +from utils import isSuspended from manualapprove import manualDenyFollowRequest from manualapprove import manualApproveFollowRequest from announce import createAnnounce diff --git a/epicyon.py b/epicyon.py index 55cb19c7..1c0912c6 100644 --- a/epicyon.py +++ b/epicyon.py @@ -45,10 +45,10 @@ from tests import testPostMessageBetweenServers from tests import testFollowBetweenServers from tests import testClientToServer from tests import runAllTests -from config import setConfigParam -from config import getConfigParam from auth import storeBasicCredentials from auth import createPassword +from utils import setConfigParam +from utils import getConfigParam from utils import getDomainFromActor from utils import getNicknameFromActor from utils import followPerson diff --git a/newswire.py b/newswire.py index bda5e8b0..b2d08f4d 100644 --- a/newswire.py +++ b/newswire.py @@ -15,6 +15,7 @@ from datetime import datetime from collections import OrderedDict from utils import locatePost from utils import loadJson +from utils import isSuspended def rss2Header(httpPrefix: str, @@ -245,16 +246,8 @@ def addLocalBlogsToNewswire(baseDir: str, newswire: {}, # has this account been suspended? nickname = handle.split('@')[0] - if os.path.isfile(suspendedFilename): - with open(suspendedFilename, "r") as f: - lines = f.readlines() - foundSuspended = False - for nick in lines: - if nick == nickname + '\n': - foundSuspended = True - break - if foundSuspended: - continue + if isSuspended(baseDir, nickname): + continue # is there a blogs timeline for this account? blogsIndex = accountDir + '/tlblogs.index' diff --git a/person.py b/person.py index d0072429..19e8243d 100644 --- a/person.py +++ b/person.py @@ -37,8 +37,8 @@ from utils import validNickname from utils import noOfAccounts from utils import loadJson from utils import saveJson -from config import setConfigParam -from config import getConfigParam +from utils import setConfigParam +from utils import getConfigParam def generateRSAKey() -> (str, str): @@ -754,23 +754,6 @@ def setBio(baseDir: str, nickname: str, domain: str, bio: str) -> bool: return True -def isSuspended(baseDir: str, nickname: str) -> bool: - """Returns true if the given nickname is suspended - """ - adminNickname = getConfigParam(baseDir, 'admin') - if nickname == adminNickname: - return False - - suspendedFilename = baseDir + '/accounts/suspended.txt' - if os.path.isfile(suspendedFilename): - with open(suspendedFilename, "r") as f: - lines = f.readlines() - for suspended in lines: - if suspended.strip('\n').strip('\r') == nickname: - return True - return False - - def unsuspendAccount(baseDir: str, nickname: str) -> None: """Removes an account suspention """ diff --git a/posts.py b/posts.py index 53c5d3ba..37d94737 100644 --- a/posts.py +++ b/posts.py @@ -45,6 +45,7 @@ from utils import validNickname from utils import locatePost from utils import loadJson from utils import saveJson +from utils import getConfigParam from media import attachMedia from media import replaceYouTube from content import removeHtml @@ -53,7 +54,6 @@ from content import addHtmlTags from content import replaceEmojiFromTags from content import removeTextFormatting from auth import createBasicAuthHeader -from config import getConfigParam from blocking import isBlocked from filters import isFiltered from git import convertPostToPatch diff --git a/utils.py b/utils.py index ce3f7012..a3881df9 100644 --- a/utils.py +++ b/utils.py @@ -19,6 +19,58 @@ from calendar import monthrange from followingCalendar import addPersonToCalendar +def createConfig(baseDir: str) -> None: + """Creates a configuration file + """ + configFilename = baseDir + '/config.json' + if os.path.isfile(configFilename): + return + configJson = { + } + saveJson(configJson, configFilename) + + +def setConfigParam(baseDir: str, variableName: str, variableValue) -> None: + """Sets a configuration value + """ + createConfig(baseDir) + configFilename = baseDir + '/config.json' + configJson = {} + if os.path.isfile(configFilename): + configJson = loadJson(configFilename) + configJson[variableName] = variableValue + saveJson(configJson, configFilename) + + +def getConfigParam(baseDir: str, variableName: str): + """Gets a configuration value + """ + createConfig(baseDir) + configFilename = baseDir + '/config.json' + configJson = loadJson(configFilename) + if configJson: + if configJson.get(variableName): + return configJson[variableName] + return None + + +def isSuspended(baseDir: str, nickname: str) -> bool: + """Returns true if the given nickname is suspended + """ + adminNickname = getConfigParam(baseDir, 'admin') + if nickname == adminNickname: + return False + + suspendedFilename = baseDir + '/accounts/suspended.txt' + if os.path.isfile(suspendedFilename): + with open(suspendedFilename, "r") as f: + lines = f.readlines() + for suspended in lines: + if suspended.strip('\n').strip('\r') == nickname: + return True + return False + + def getFollowersList(baseDir: str, nickname: str, domain: str, followFile='following.txt') -> []: diff --git a/webinterface.py b/webinterface.py index 3afe1c2d..68c7bb7b 100644 --- a/webinterface.py +++ b/webinterface.py @@ -41,6 +41,7 @@ from utils import getDisplayName from utils import getCachedPostDirectory from utils import getCachedPostFilename from utils import loadJson +from utils import getConfigParam from follow import isFollowingActor from webfinger import webfingerHandle from posts import isDM @@ -67,7 +68,6 @@ from content import addHtmlTags from content import replaceEmojiFromTags from content import removeLongWords from content import removeHtml -from config import getConfigParam from skills import getSkills from cache import getPersonFromCache from cache import storePersonInCache