main
Bob Mottram 2020-12-08 14:09:54 +00:00
parent c68ae15402
commit 11f218d532
3 changed files with 15 additions and 15 deletions

View File

@ -326,12 +326,12 @@ parser.add_argument('--image', '--background', dest='backgroundImage',
parser.add_argument('--archive', dest='archive', type=str,
default=None,
help='Archive old files to the given directory')
parser.add_argument('--archiveweeks', dest='archiveWeeks', type=str,
default=None,
parser.add_argument('--archiveweeks', dest='archiveWeeks', type=int,
default=4,
help='Specify the number of weeks after which ' +
'data will be archived')
parser.add_argument('--maxposts', dest='archiveMaxPosts', type=str,
default=None,
'media will be archived')
parser.add_argument('--maxposts', dest='archiveMaxPosts', type=int,
default=32000,
help='Maximum number of posts in in/outbox')
parser.add_argument('--minimumvotes', dest='minimumvotes', type=int,
default=1,
@ -1574,13 +1574,6 @@ if args.changepassword:
print('Passwords file not found')
sys.exit()
archiveWeeks = 4
if args.archiveWeeks:
archiveWeeks = args.archiveWeeks
archiveMaxPosts = 32000
if args.archiveMaxPosts:
archiveMaxPosts = args.archiveMaxPosts
if args.archive:
if args.archive.lower().endswith('null') or \
args.archive.lower().endswith('delete') or \
@ -1589,8 +1582,8 @@ if args.archive:
print('Archiving with deletion of old posts...')
else:
print('Archiving to ' + args.archive + '...')
archiveMedia(baseDir, args.archive, archiveWeeks)
archivePosts(baseDir, httpPrefix, args.archive, {}, archiveMaxPosts)
archiveMedia(baseDir, args.archive, args.archiveWeeks)
archivePosts(baseDir, httpPrefix, args.archive, {}, args.archiveMaxPosts)
print('Archiving complete')
sys.exit()

View File

@ -199,9 +199,12 @@ def attachMedia(baseDir: str, httpPrefix: str, domain: str, port: int,
def archiveMedia(baseDir: str, archiveDirectory: str, maxWeeks=4) -> None:
"""Any media older than the given number of weeks gets archived
"""
if maxWeeks == 0:
return
currTime = datetime.datetime.utcnow()
weeksSinceEpoch = int((currTime - datetime.datetime(1970, 1, 1)).days/7)
minWeek = weeksSinceEpoch-maxWeeks
minWeek = weeksSinceEpoch - maxWeeks
if archiveDirectory:
if not os.path.isdir(archiveDirectory):

View File

@ -3144,9 +3144,13 @@ def archivePosts(baseDir: str, httpPrefix: str, archiveDir: str,
maxPostsInBox=32000) -> None:
"""Archives posts for all accounts
"""
if maxPostsInBox == 0:
return
if archiveDir:
if not os.path.isdir(archiveDir):
os.mkdir(archiveDir)
if archiveDir:
if not os.path.isdir(archiveDir + '/accounts'):
os.mkdir(archiveDir + '/accounts')