diff --git a/epicyon.py b/epicyon.py index 6bdd2cd4..e4f0fb9f 100644 --- a/epicyon.py +++ b/epicyon.py @@ -504,7 +504,7 @@ if args.archive: else: print('Archiving to '+args.archive+'...') archiveMedia(baseDir,args.archive,archiveWeeks) - archivePosts(baseDir,args.archive,archiveMaxPosts) + archivePosts(baseDir,httpPrefix,args.archive,archiveMaxPosts) print('Archiving complete') sys.exit() diff --git a/inbox.py b/inbox.py index 238e3a8c..1404bd08 100644 --- a/inbox.py +++ b/inbox.py @@ -536,7 +536,7 @@ def receiveDelete(session,handle: str,baseDir: str, \ print('DEBUG: delete post not found in inbox or outbox') print(messageJson['object']) return True - deletePost(baseDir,handle.split('@')[0],handle.split('@')[1],postFilename,debug) + deletePost(baseDir,httpPrefix,handle.split('@')[0],handle.split('@')[1],postFilename,debug) if debug: print('DEBUG: post deleted - '+postFilename) return True diff --git a/posts.py b/posts.py index 08ae9263..154fd946 100644 --- a/posts.py +++ b/posts.py @@ -948,7 +948,7 @@ def createBoxBase(baseDir: str,boxname: str, \ return boxHeader return boxItems -def archivePosts(baseDir: str,archiveDir: str,maxPostsInBox=256) -> None: +def archivePosts(baseDir: str,httpPrefix: str,archiveDir: str,maxPostsInBox=256) -> None: """Archives posts for all accounts """ if archiveDir: @@ -972,16 +972,16 @@ def archivePosts(baseDir: str,archiveDir: str,maxPostsInBox=256) -> None: if not os.path.isdir(archiveDir+'/accounts/'+handle+'/outbox'): os.mkdir(archiveDir+'/accounts/'+handle+'/outbox') archiveSubdir=archiveDir+'/accounts/'+handle+'/inbox' - archivePostsForPerson(nickname,domain,baseDir, \ + archivePostsForPerson(httpPrefix,nickname,domain,baseDir, \ 'inbox',archiveSubdir, \ maxPostsInBox) if archiveDir: archiveSubdir=archiveDir+'/accounts/'+handle+'/outbox' - archivePostsForPerson(nickname,domain,baseDir, \ + archivePostsForPerson(httpPrefix,nickname,domain,baseDir, \ 'outbox',archiveSubdir, \ maxPostsInBox) -def archivePostsForPerson(nickname: str,domain: str,baseDir: str, \ +def archivePostsForPerson(httpPrefix: str,nickname: str,domain: str,baseDir: str, \ boxname: str,archiveDir: str,maxPostsInBox=256) -> None: """Retain a maximum number of posts within the given box Move any others to an archive directory @@ -1007,7 +1007,7 @@ def archivePostsForPerson(nickname: str,domain: str,baseDir: str, \ if os.path.isfile(repliesPath): os.rename(repliesPath,archivePath) else: - deletePost(baseDir,nickname,domain,filePath,False) + deletePost(baseDir,httpPrefix,nickname,domain,filePath,False) noOfPosts -= 1 if noOfPosts <= maxPostsInBox: break diff --git a/utils.py b/utils.py index ecc63027..e2c2ae9f 100644 --- a/utils.py +++ b/utils.py @@ -8,6 +8,7 @@ __status__ = "Production" import os import datetime +import commentjson def getStatusNumber() -> (str,str): """Returns the status number and published date @@ -158,11 +159,15 @@ def removeAttachment(baseDir: str,httpPrefix: str,domain: str,postJson: {}): os.remove(mediaFilename) postJson['attachment']=[] -def deletePost(baseDir: str,nickname: str,domain: str,postFilename: str,debug: bool): +def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilename: str,debug: bool): """Recursively deletes a post and its replies and attachments """ + # remove any attachment with open(postFilename, 'r') as fp: postJsonObject=commentjson.load(fp) + removeAttachment(baseDir,httpPrefix,domain,postJsonObject) + + # remove any replies repliesFilename=postFilename.replace('.json','.replies') if os.path.isfile(repliesFilename): if debug: @@ -173,6 +178,7 @@ def deletePost(baseDir: str,nickname: str,domain: str,postFilename: str,debug: b if replyFile: if os.path.isfile(replyFile): deletePost(baseDir,nickname,domain,replyFile,debug) - # remove the replies file itself + # remove the replies file os.remove(repliesFilename) + # finally, remove the post itself os.remove(postFilename)