cleanup.py (507B)
1 #!/usr/bin/env python3 2 3 import os, sys, time, datetime 4 from fhost import app 5 6 os.chdir(os.path.dirname(sys.argv[0])) 7 os.chdir(app.config["FHOST_STORAGE_PATH"]) 8 9 files = [f for f in os.listdir(".")] 10 11 maxs = app.config["MAX_CONTENT_LENGTH"] 12 mind = 30 13 maxd = 365 14 15 for f in files: 16 stat = os.stat(f) 17 systime = time.time() 18 age = datetime.timedelta(seconds = systime - stat.st_mtime).days 19 20 maxage = mind + (-maxd + mind) * (stat.st_size / maxs - 1) ** 3 21 22 if age >= maxage: 23 os.remove(f)