Skip to content

Commit

Permalink
✨ feat: delete old meipass
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinNitroG committed Mar 21, 2024
1 parent 0187b79 commit d800f98
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
10 changes: 5 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@
Login,
PrintIntro,
UserOptions,
delete_old_meipass,
create_directory,
pause,
print_title,
)
from src.constants import DOWNLOAD_DIR


ToolLogger().setup()
urllib3_disable_warnings(InsecureRequestWarning)


def main() -> None:
"""Main function to run VNULIB Downloader."""
logger: Logger = getLogger(__name__)
delete_old_meipass(time_threshold=300)

PrintIntro()

Expand Down Expand Up @@ -73,5 +71,7 @@ def main() -> None:


if __name__ == "__main__":
freeze_support() # For pyinstaller to fix multiprocessing in Windows
freeze_support() # For pyinstaller to fix multiprocessing in Windows due to freeze scheme
ToolLogger().setup()
urllib3_disable_warnings(InsecureRequestWarning)
main()
1 change: 1 addition & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
create_directory,
pause,
print_title,
delete_old_meipass,
)
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
BUNDLE_DIR = ""


VERSION: str = "1.15"
VERSION: str = "1.16.1-beta"
AUTHORS: str = "KevinNitroG & NTGNguyen"
BANNER_FILE: str = f"{BUNDLE_DIR}assets/utils/ascii_banner.txt"
with open(BANNER_FILE, encoding="utf-8") as banner_content:
Expand Down
2 changes: 1 addition & 1 deletion src/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

from .logger import ToolLogger, logger_listener, get_subprocess_logger
from .prints import print_title
from .utils import pause, create_directory, datetime_name, slugify
from .utils import pause, create_directory, datetime_name, slugify, delete_old_meipass
24 changes: 24 additions & 0 deletions src/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
from __future__ import annotations

import re
import sys
import unicodedata
from glob import glob
from datetime import datetime
from time import time
from os import makedirs, path
from shutil import rmtree
from logging import getLogger
Expand All @@ -14,6 +17,27 @@
logger = getLogger(__name__)


def delete_old_meipass(time_threshold=3600) -> None: # Default setting: Remove after 1 hour, time_threshold in seconds
"""Clean old _MEIPASS folder (Windows only I think).
This code is from: https://stackoverflow.com/a/61909248/23173098
Args:
time_threshold (int, optional): Delete old _MEIPASS older than time_threshold (s). Defaults to 3600.
"""
try:
base_path = sys._MEIPASS # type: ignore # skipcq: PYL-W0212 # pylint: disable=protected-access # nopep8
except Exception:
logger.debug("No MEIPASS found")
return # Not being ran as OneFile Folder -> Return
temp_path = path.abspath(path.join(base_path, "..")) # Go to parent folder of MEIPASS
# Search all MEIPASS folders...
mei_folders = glob(path.join(temp_path, "_MEI*"))
for item in mei_folders:
if (time() - path.getctime(item)) > time_threshold:
rmtree(item)
logger.debug("Deleted: %s", item)


def pause() -> None:
"""Pause the terminal until user hits Enter"""
_: str = input("Press Enter to continue . . .")
Expand Down

0 comments on commit d800f98

Please sign in to comment.