26 lines
718 B
Python
26 lines
718 B
Python
"""手动/定时清理过期文件与孤儿缓存文件。"""
|
|
import logging
|
|
import time
|
|
|
|
import auth
|
|
import storage
|
|
|
|
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
|
|
log = logging.getLogger("lzwlab-cleanup")
|
|
|
|
|
|
def main() -> int:
|
|
cfg = auth.load_config()
|
|
files_dir = cfg["files_dir"]
|
|
db_path = cfg["database_path"]
|
|
storage.init_db(db_path)
|
|
now = int(time.time())
|
|
removed = storage.cleanup_expired(db_path, files_dir, now=now)
|
|
orphans = storage.cleanup_orphans(db_path, files_dir, now=now)
|
|
log.info("清理完成:过期文件 %d 个,孤儿缓存 %d 个", removed, orphans)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|