Snake case

main
Bob Mottram 2021-12-25 23:41:17 +00:00
parent 2f7ea9084a
commit f087b8589c
4 changed files with 40 additions and 40 deletions

View File

@ -18845,10 +18845,10 @@ def runDaemon(content_license_url: str,
print('Creating avatars cache') print('Creating avatars cache')
os.mkdir(base_dir + '/cache/avatars') os.mkdir(base_dir + '/cache/avatars')
archiveDir = base_dir + '/archive' archive_dir = base_dir + '/archive'
if not os.path.isdir(archiveDir): if not os.path.isdir(archive_dir):
print('Creating archive') print('Creating archive')
os.mkdir(archiveDir) os.mkdir(archive_dir)
if not os.path.isdir(base_dir + '/sharefiles'): if not os.path.isdir(base_dir + '/sharefiles'):
print('Creating shared item files directory') print('Creating shared item files directory')
@ -18865,7 +18865,7 @@ def runDaemon(content_license_url: str,
threadWithTrace(target=expireCache, threadWithTrace(target=expireCache,
args=(base_dir, httpd.person_cache, args=(base_dir, httpd.person_cache,
httpd.http_prefix, httpd.http_prefix,
archiveDir, archive_dir,
httpd.maxPostsInBox), daemon=True) httpd.maxPostsInBox), daemon=True)
httpd.thrCache.start() httpd.thrCache.start()

View File

@ -365,7 +365,7 @@ def attachMedia(base_dir: str, http_prefix: str,
return postJson return postJson
def archiveMedia(base_dir: str, archiveDirectory: str, maxWeeks: int) -> None: def archiveMedia(base_dir: str, archive_directory: str, maxWeeks: int) -> None:
"""Any media older than the given number of weeks gets archived """Any media older than the given number of weeks gets archived
""" """
if maxWeeks == 0: if maxWeeks == 0:
@ -375,18 +375,18 @@ def archiveMedia(base_dir: str, archiveDirectory: str, maxWeeks: int) -> None:
weeksSinceEpoch = int((currTime - datetime.datetime(1970, 1, 1)).days/7) weeksSinceEpoch = int((currTime - datetime.datetime(1970, 1, 1)).days/7)
minWeek = weeksSinceEpoch - maxWeeks minWeek = weeksSinceEpoch - maxWeeks
if archiveDirectory: if archive_directory:
if not os.path.isdir(archiveDirectory): if not os.path.isdir(archive_directory):
os.mkdir(archiveDirectory) os.mkdir(archive_directory)
if not os.path.isdir(archiveDirectory + '/media'): if not os.path.isdir(archive_directory + '/media'):
os.mkdir(archiveDirectory + '/media') os.mkdir(archive_directory + '/media')
for subdir, dirs, files in os.walk(base_dir + '/media'): for subdir, dirs, files in os.walk(base_dir + '/media'):
for weekDir in dirs: for weekDir in dirs:
if int(weekDir) < minWeek: if int(weekDir) < minWeek:
if archiveDirectory: if archive_directory:
move(os.path.join(base_dir + '/media', weekDir), move(os.path.join(base_dir + '/media', weekDir),
archiveDirectory + '/media') archive_directory + '/media')
else: else:
# archive to /dev/null # archive to /dev/null
rmtree(os.path.join(base_dir + '/media', weekDir), rmtree(os.path.join(base_dir + '/media', weekDir),

View File

@ -841,9 +841,9 @@ def runNewswireDaemon(base_dir: str, httpd,
print('Newswire feed converted to ActivityPub') print('Newswire feed converted to ActivityPub')
if httpd.max_news_posts > 0: if httpd.max_news_posts > 0:
archiveDir = base_dir + '/archive' archive_dir = base_dir + '/archive'
archiveSubdir = \ archiveSubdir = \
archiveDir + '/accounts/news@' + domain + '/outbox' archive_dir + '/accounts/news@' + domain + '/outbox'
print('Archiving news posts') print('Archiving news posts')
archivePostsForPerson(http_prefix, 'news', archivePostsForPerson(http_prefix, 'news',
domain, base_dir, 'outbox', domain, base_dir, 'outbox',

View File

@ -3876,7 +3876,7 @@ def _createBoxIndexed(recentPostsCache: {},
def expireCache(base_dir: str, person_cache: {}, def expireCache(base_dir: str, person_cache: {},
http_prefix: str, archiveDir: str, http_prefix: str, archive_dir: str,
recentPostsCache: {}, recentPostsCache: {},
maxPostsInBox=32000): maxPostsInBox=32000):
"""Thread used to expire actors from the cache and archive old posts """Thread used to expire actors from the cache and archive old posts
@ -3885,11 +3885,11 @@ def expireCache(base_dir: str, person_cache: {},
# once per day # once per day
time.sleep(60 * 60 * 24) time.sleep(60 * 60 * 24)
expirePersonCache(person_cache) expirePersonCache(person_cache)
archivePosts(base_dir, http_prefix, archiveDir, recentPostsCache, archivePosts(base_dir, http_prefix, archive_dir, recentPostsCache,
maxPostsInBox) maxPostsInBox)
def archivePosts(base_dir: str, http_prefix: str, archiveDir: str, def archivePosts(base_dir: str, http_prefix: str, archive_dir: str,
recentPostsCache: {}, recentPostsCache: {},
maxPostsInBox=32000) -> None: maxPostsInBox=32000) -> None:
"""Archives posts for all accounts """Archives posts for all accounts
@ -3897,13 +3897,13 @@ def archivePosts(base_dir: str, http_prefix: str, archiveDir: str,
if maxPostsInBox == 0: if maxPostsInBox == 0:
return return
if archiveDir: if archive_dir:
if not os.path.isdir(archiveDir): if not os.path.isdir(archive_dir):
os.mkdir(archiveDir) os.mkdir(archive_dir)
if archiveDir: if archive_dir:
if not os.path.isdir(archiveDir + '/accounts'): if not os.path.isdir(archive_dir + '/accounts'):
os.mkdir(archiveDir + '/accounts') os.mkdir(archive_dir + '/accounts')
for subdir, dirs, files in os.walk(base_dir + '/accounts'): for subdir, dirs, files in os.walk(base_dir + '/accounts'):
for handle in dirs: for handle in dirs:
@ -3911,24 +3911,24 @@ def archivePosts(base_dir: str, http_prefix: str, archiveDir: str,
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
domain = handle.split('@')[1] domain = handle.split('@')[1]
archiveSubdir = None archiveSubdir = None
if archiveDir: if archive_dir:
if not os.path.isdir(archiveDir + '/accounts/' + handle): if not os.path.isdir(archive_dir + '/accounts/' + handle):
os.mkdir(archiveDir + '/accounts/' + handle) os.mkdir(archive_dir + '/accounts/' + handle)
if not os.path.isdir(archiveDir + '/accounts/' + if not os.path.isdir(archive_dir + '/accounts/' +
handle + '/inbox'): handle + '/inbox'):
os.mkdir(archiveDir + '/accounts/' + os.mkdir(archive_dir + '/accounts/' +
handle + '/inbox') handle + '/inbox')
if not os.path.isdir(archiveDir + '/accounts/' + if not os.path.isdir(archive_dir + '/accounts/' +
handle + '/outbox'): handle + '/outbox'):
os.mkdir(archiveDir + '/accounts/' + os.mkdir(archive_dir + '/accounts/' +
handle + '/outbox') handle + '/outbox')
archiveSubdir = archiveDir + '/accounts/' + \ archiveSubdir = archive_dir + '/accounts/' + \
handle + '/inbox' handle + '/inbox'
archivePostsForPerson(http_prefix, nickname, domain, base_dir, archivePostsForPerson(http_prefix, nickname, domain, base_dir,
'inbox', archiveSubdir, 'inbox', archiveSubdir,
recentPostsCache, maxPostsInBox) recentPostsCache, maxPostsInBox)
if archiveDir: if archive_dir:
archiveSubdir = archiveDir + '/accounts/' + \ archiveSubdir = archive_dir + '/accounts/' + \
handle + '/outbox' handle + '/outbox'
archivePostsForPerson(http_prefix, nickname, domain, base_dir, archivePostsForPerson(http_prefix, nickname, domain, base_dir,
'outbox', archiveSubdir, 'outbox', archiveSubdir,
@ -3938,7 +3938,7 @@ def archivePosts(base_dir: str, http_prefix: str, archiveDir: str,
def archivePostsForPerson(http_prefix: str, nickname: str, domain: str, def archivePostsForPerson(http_prefix: str, nickname: str, domain: str,
base_dir: str, base_dir: str,
boxname: str, archiveDir: str, boxname: str, archive_dir: str,
recentPostsCache: {}, recentPostsCache: {},
maxPostsInBox=32000) -> None: maxPostsInBox=32000) -> None:
"""Retain a maximum number of posts within the given box """Retain a maximum number of posts within the given box
@ -3946,9 +3946,9 @@ def archivePostsForPerson(http_prefix: str, nickname: str, domain: str,
""" """
if boxname != 'inbox' and boxname != 'outbox': if boxname != 'inbox' and boxname != 'outbox':
return return
if archiveDir: if archive_dir:
if not os.path.isdir(archiveDir): if not os.path.isdir(archive_dir):
os.mkdir(archiveDir) os.mkdir(archive_dir)
boxDir = createPersonDir(nickname, domain, base_dir, boxname) boxDir = createPersonDir(nickname, domain, base_dir, boxname)
postsInBox = os.scandir(boxDir) postsInBox = os.scandir(boxDir)
noOfPosts = 0 noOfPosts = 0
@ -4014,8 +4014,8 @@ def archivePostsForPerson(http_prefix: str, nickname: str, domain: str,
filePath = os.path.join(boxDir, postFilename) filePath = os.path.join(boxDir, postFilename)
if not os.path.isfile(filePath): if not os.path.isfile(filePath):
continue continue
if archiveDir: if archive_dir:
archivePath = os.path.join(archiveDir, postFilename) archivePath = os.path.join(archive_dir, postFilename)
os.rename(filePath, archivePath) os.rename(filePath, archivePath)
extensions = ('replies', 'votes', 'arrived', 'muted') extensions = ('replies', 'votes', 'arrived', 'muted')
@ -4048,7 +4048,7 @@ def archivePostsForPerson(http_prefix: str, nickname: str, domain: str,
removeCtr += 1 removeCtr += 1
if noOfPosts <= maxPostsInBox: if noOfPosts <= maxPostsInBox:
break break
if archiveDir: if archive_dir:
print('Archived ' + str(removeCtr) + ' ' + boxname + print('Archived ' + str(removeCtr) + ' ' + boxname +
' posts for ' + nickname + '@' + domain) ' posts for ' + nickname + '@' + domain)
else: else: