diff --git a/.gitignore b/.gitignore index 1215f87..94c2a63 100644 --- a/.gitignore +++ b/.gitignore @@ -55,6 +55,8 @@ .pytest_cache/ cover/ .idea/ +.build/ +.dist/ # Translations *.mo diff --git a/README.md b/README.md index 61567ec..1cb683c 100644 --- a/README.md +++ b/README.md @@ -64,4 +64,8 @@ - `pipx install thu-learn-downloader` ## test run command -python.exe -m thu_learn_downloader.main \ No newline at end of file +python.exe -m thu_learn_downloader.main + +## exe packing +- run in project root: +.\.venv\Scripts\pyinstaller.exe --onefile --clean --add-data "thu_learn_downloader/openssl.conf;thu_learn_downloader" .\thu_learn_downloader\main.py --runtime-hook .\thu_learn_downloader\hook.py \ No newline at end of file diff --git a/thu_learn_downloader/hook.py b/thu_learn_downloader/hook.py new file mode 100644 index 0000000..683045b --- /dev/null +++ b/thu_learn_downloader/hook.py @@ -0,0 +1,12 @@ +import sys +import os + +# Determine the path for openssl.conf based on whether it's running from the executable or source code +if getattr(sys, 'frozen', False): # If running from the bundled executable + config_path = os.path.join(sys._MEIPASS, 'thu_learn_downloader', 'openssl.conf') +else: + config_path = os.path.join(os.path.dirname(__file__), 'thu_learn_downloader', 'openssl.conf') + +# Now you can use config_path to load the openssl.conf file +print(f"Config file path: {config_path}") +os.environ['OPENSSL_CONF'] = config_path \ No newline at end of file diff --git a/thu_learn_downloader/main.py b/thu_learn_downloader/main.py index dbbb2bc..2e34c4d 100644 --- a/thu_learn_downloader/main.py +++ b/thu_learn_downloader/main.py @@ -1,3 +1,6 @@ +import urllib3 +urllib3.disable_warnings() + import logging from pathlib import Path from typing import Annotated @@ -11,8 +14,6 @@ from thu_learn_downloader.download.downloader import Downloader from thu_learn_downloader.download.selector import Selector from thu_learn_downloader.login import auto as login -# import os -# os.environ['OPENSSL_CONF'] = r'D:\git-repo\thu-learn-downloader\thu_learn_downloader\openssl.conf' app: Typer = Typer(name="tld")