From d7ad3733ffdceffea85047b7677ae1005f0a8ced Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 25 Jun 2021 19:02:05 +0100 Subject: [PATCH] Checking account directories --- blog.py | 19 ++++--------------- migrate.py | 7 ++----- theme.py | 7 ++----- utils.py | 7 ++----- webapp_moderation.py | 7 ++----- webapp_search.py | 13 +++---------- 6 files changed, 15 insertions(+), 45 deletions(-) diff --git a/blog.py b/blog.py index 0822aa64a..cbb2574c8 100644 --- a/blog.py +++ b/blog.py @@ -16,6 +16,7 @@ from webapp_utils import htmlHeaderWithBlogMarkup from webapp_utils import htmlFooter from webapp_utils import getPostAttachmentsAsHtml from webapp_media import addEmbeddedElements +from utils import isAccountDir from utils import removeHtml from utils import getConfigParam from utils import getFullDomain @@ -643,11 +644,7 @@ def _noOfBlogAccounts(baseDir: str) -> int: ctr = 0 for subdir, dirs, files in os.walk(baseDir + '/accounts'): for acct in dirs: - if '@' not in acct: - continue - if acct.startswith('inbox@'): - continue - elif acct.startswith('news@'): + if not isAccountDir(acct): continue accountDir = os.path.join(baseDir + '/accounts', acct) blogsIndex = accountDir + '/tlblogs.index' @@ -662,11 +659,7 @@ def _singleBlogAccountNickname(baseDir: str) -> str: """ for subdir, dirs, files in os.walk(baseDir + '/accounts'): for acct in dirs: - if '@' not in acct: - continue - if acct.startswith('inbox@'): - continue - elif acct.startswith('news@'): + if not isAccountDir(acct): continue accountDir = os.path.join(baseDir + '/accounts', acct) blogsIndex = accountDir + '/tlblogs.index' @@ -704,11 +697,7 @@ def htmlBlogView(authorized: bool, for subdir, dirs, files in os.walk(baseDir + '/accounts'): for acct in dirs: - if '@' not in acct: - continue - if acct.startswith('inbox@'): - continue - elif acct.startswith('news@'): + if not isAccountDir(acct): continue accountDir = os.path.join(baseDir + '/accounts', acct) blogsIndex = accountDir + '/tlblogs.index' diff --git a/migrate.py b/migrate.py index 4cca4b0e8..b36002a41 100644 --- a/migrate.py +++ b/migrate.py @@ -8,6 +8,7 @@ __status__ = "Production" __module_group__ = "Core" import os +from utils import isAccountDir from utils import getNicknameFromActor from utils import getDomainFromActor from webfinger import webfingerHandle @@ -186,11 +187,7 @@ def migrateAccounts(baseDir: str, session, ctr = 0 for subdir, dirs, files in os.walk(baseDir + '/accounts'): for handle in dirs: - if '@' not in handle: - continue - if handle.startswith('inbox@'): - continue - if handle.startswith('news@'): + if not isAccountDir(handle): continue nickname = handle.split('@')[0] domain = handle.split('@')[1] diff --git a/theme.py b/theme.py index def0348ce..4223bb121 100644 --- a/theme.py +++ b/theme.py @@ -7,6 +7,7 @@ __email__ = "bob@freedombone.net" __status__ = "Production" import os +from utils import isAccountDir from utils import loadJson from utils import saveJson from utils import getImageExtensions @@ -623,11 +624,7 @@ def _setThemeImages(baseDir: str, name: str) -> None: for subdir, dirs, files in os.walk(baseDir + '/accounts'): for acct in dirs: - if '@' not in acct: - continue - if acct.startswith('inbox@'): - continue - elif acct.startswith('news@'): + if not isAccountDir(acct): continue accountDir = \ os.path.join(baseDir + '/accounts', acct) diff --git a/utils.py b/utils.py index 5fc58d025..33454cf14 100644 --- a/utils.py +++ b/utils.py @@ -5,7 +5,7 @@ __version__ = "1.2.0" __maintainer__ = "Bob Mottram" __email__ = "bob@freedombone.net" __status__ = "Production" -__module_group__ = "Core" +__module_group__ = "ActivityPu" import os import re @@ -1454,10 +1454,7 @@ def noOfActiveAccountsMonthly(baseDir: str, months: int) -> bool: monthSeconds = int(60*60*24*30*months) for subdir, dirs, files in os.walk(baseDir + '/accounts'): for account in dirs: - if '@' not in account: - continue - if account.startswith('inbox@') or \ - account.startswith('news@'): + if not isAccountDir(account): continue lastUsedFilename = \ baseDir + '/accounts/' + account + '/.lastUsed' diff --git a/webapp_moderation.py b/webapp_moderation.py index 4e79f9f4d..01bddd2ad 100644 --- a/webapp_moderation.py +++ b/webapp_moderation.py @@ -8,6 +8,7 @@ __status__ = "Production" __module_group__ = "Web Interface" import os +from utils import isAccountDir from utils import getFullDomain from utils import isEditor from utils import loadJson @@ -270,11 +271,7 @@ def htmlModerationInfo(cssCache: {}, translate: {}, accounts = [] for subdir, dirs, files in os.walk(baseDir + '/accounts'): for acct in dirs: - if '@' not in acct: - continue - if acct.startswith('inbox@'): - continue - elif acct.startswith('news@'): + if not isAccountDir(acct): continue accounts.append(acct) break diff --git a/webapp_search.py b/webapp_search.py index e6beb6c18..22221ea1c 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -11,6 +11,7 @@ import os from shutil import copyfile import urllib.parse from datetime import datetime +from utils import isAccountDir from utils import getConfigParam from utils import getFullDomain from utils import isEditor @@ -407,11 +408,7 @@ def htmlSkillsSearch(actor: str, for f in files: if not f.endswith('.json'): continue - if '@' not in f: - continue - if f.startswith('inbox@'): - continue - elif f.startswith('news@'): + if not isAccountDir(f): continue actorFilename = os.path.join(subdir, f) actorJson = loadJson(actorFilename) @@ -446,11 +443,7 @@ def htmlSkillsSearch(actor: str, for f in files: if not f.endswith('.json'): continue - if '@' not in f: - continue - if f.startswith('inbox@'): - continue - elif f.startswith('news@'): + if not isAccountDir(f): continue actorFilename = os.path.join(subdir, f) cachedActorJson = loadJson(actorFilename)