-
Notifications
You must be signed in to change notification settings - Fork 4
/
flushcache.py
31 lines (22 loc) · 799 Bytes
/
flushcache.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import shutil
import logging
from pathlib import Path
from main import RUNNING
from f1.config import CACHE_DIR
"""Delete the contents of the ./cache directory.
Ensure the bot is not running. A new cache will be built when starting the bot.
"""
logger = logging.getLogger("f1-bot")
if __name__ == "__main__":
if RUNNING:
logger.warning("Bot is running. Exit the process or use /stop command.")
exit()
if Path.exists(CACHE_DIR):
logger.warning("Removing cache directory...")
try:
shutil.rmtree(CACHE_DIR)
except Exception as err:
logger.error(f"Error removing cache\n{err}")
exit()
logger.info("Cache removed successfully!\nStart the bot with python -m main.py to build a new cache.")
exit()