diff --git a/blocking.py b/blocking.py index 7498ae081..d2361a584 100644 --- a/blocking.py +++ b/blocking.py @@ -9,6 +9,7 @@ __status__ = "Production" import os import json from datetime import datetime +from utils import isAccountDir from utils import getCachedPostFilename from utils import loadJson from utils import saveJson @@ -660,9 +661,7 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None: followFiles = ('following.txt', 'followers.txt') for subdir, dirs, files in os.walk(baseDir + '/accounts'): for acct in dirs: - if '@' not in acct: - continue - if 'inbox@' in acct or 'news@' in acct: + if not isAccountDir(acct): continue accountDir = os.path.join(baseDir + '/accounts', acct) for followFileType in followFiles: diff --git a/daemon.py b/daemon.py index 24233f648..62b2560a0 100644 --- a/daemon.py +++ b/daemon.py @@ -203,6 +203,7 @@ from shares import addShare from shares import removeShare from shares import expireShares from categories import setHashtagCategory +from utils import isAccountDir from utils import getOccupationSkills from utils import getOccupationName from utils import setOccupationName @@ -5700,9 +5701,7 @@ class PubServer(BaseHTTPRequestHandler): msg = '' for subdir, dirs, files in os.walk(baseDir + '/accounts'): for acct in dirs: - if '@' not in acct: - continue - if 'inbox@' in acct or 'news@' in acct: + if not isAccountDir(acct): continue nickname = acct.split('@')[0] domain = acct.split('@')[1] diff --git a/follow.py b/follow.py index 7f88b8ebd..9cc72617c 100644 --- a/follow.py +++ b/follow.py @@ -22,6 +22,7 @@ from posts import sendSignedJson from posts import getPersonBox from utils import loadJson from utils import saveJson +from utils import isAccountDir from acceptreject import createAccept from acceptreject import createReject from webfinger import webfingerHandle @@ -37,9 +38,7 @@ def createInitialLastSeen(baseDir: str, httpPrefix: str) -> None: """ for subdir, dirs, files in os.walk(baseDir + '/accounts'): for acct in dirs: - if '@' not in acct: - continue - if 'inbox@' in acct or 'news@' in acct: + if not isAccountDir(acct): continue accountDir = os.path.join(baseDir + '/accounts', acct) followingFilename = accountDir + '/following.txt' diff --git a/metadata.py b/metadata.py index 99f252225..7add87590 100644 --- a/metadata.py +++ b/metadata.py @@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net" __status__ = "Production" import os +from utils import isAccountDir from utils import loadJson from utils import noOfAccounts from utils import noOfActiveAccountsMonthly @@ -19,9 +20,7 @@ def _getStatusCount(baseDir: str) -> int: accountsDir = baseDir + '/accounts' for subdir, dirs, files in os.walk(accountsDir): for acct in dirs: - if '@' not in acct: - continue - if 'inbox@' in acct or 'news@' in acct: + if not isAccountDir(acct): continue acctDir = os.path.join(accountsDir, acct + '/outbox') for subdir2, dirs2, files2 in os.walk(acctDir): diff --git a/utils.py b/utils.py index 428a6c5f3..cb731bfd7 100644 --- a/utils.py +++ b/utils.py @@ -2400,3 +2400,13 @@ def setOccupationSkillsList(actorJson: {}, skillsList: []) -> bool: occupationItem['skills'] = skillsList return True return False + + +def isAccountDir(dirName: str) -> bool: + """Is the given directory an account within /accounts ? + """ + if '@' not in dirName: + return False + if 'inbox@' in dirName or 'news@' in dirName: + return False + return True diff --git a/webapp_accesskeys.py b/webapp_accesskeys.py index 59634ecb9..7a88b4e60 100644 --- a/webapp_accesskeys.py +++ b/webapp_accesskeys.py @@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net" __status__ = "Production" import os +from utils import isAccountDir from utils import loadJson from utils import getConfigParam from webapp_utils import htmlHeaderWithExternalStyle @@ -19,9 +20,7 @@ def loadAccessKeysForAccounts(baseDir: str, keyShortcuts: {}, """ for subdir, dirs, files in os.walk(baseDir + '/accounts'): for acct in dirs: - if '@' not in acct: - continue - if 'inbox@' in acct or 'news@' in acct: + if not isAccountDir(acct): continue accountDir = os.path.join(baseDir + '/accounts', acct) accessKeysFilename = accountDir + '/accessKeys.json'