Archive to directory

master
Bob Mottram 2019-07-12 20:55:23 +01:00
parent cf2dbe8d26
commit b89dea3c69
1 changed files with 7 additions and 3 deletions

View File

@ -17,6 +17,7 @@ import datetime
from auth import createPassword from auth import createPassword
from shutil import copyfile from shutil import copyfile
from shutil import rmtree from shutil import rmtree
from shutil import move
def getImageHash(imageFilename: str) -> str: def getImageHash(imageFilename: str) -> str:
return blurencode(numpy.array(Image.open(imageFilename).convert("RGB"))) return blurencode(numpy.array(Image.open(imageFilename).convert("RGB")))
@ -97,7 +98,7 @@ def removeAttachment(baseDir: str,httpPrefix: str,domain: str,postJson: {}):
os.remove(mediaFilename) os.remove(mediaFilename)
postJson['attachment']=[] postJson['attachment']=[]
def archiveMedia(baseDir: str,maxWeeks=4) -> None: def archiveMedia(baseDir: str,archiveDirectory: str,maxWeeks=4) -> None:
"""Any media older than the given number of weeks gets archived """Any media older than the given number of weeks gets archived
""" """
currTime=datetime.datetime.utcnow() currTime=datetime.datetime.utcnow()
@ -107,5 +108,8 @@ def archiveMedia(baseDir: str,maxWeeks=4) -> None:
for subdir, dirs, files in os.walk(baseDir+'/media'): for subdir, dirs, files in os.walk(baseDir+'/media'):
for weekDir in dirs: for weekDir in dirs:
if int(weekDir)<minWeek: if int(weekDir)<minWeek:
# in this case archived to /dev/null if archiveDirectory:
move(os.path.join(baseDir+'/media', weekDir),archiveDirectory)
else:
# archive to /dev/null
rmtree(os.path.join(baseDir+'/media', weekDir)) rmtree(os.path.join(baseDir+'/media', weekDir))