Skip to content

The only downloader you need. 下载器的集大成者。

refactor(build): 移除重复的FeaturePacks复制逻辑并优化部署脚本

XiaoYouChR202e13ef9068
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index a7026936..d5b8320b 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -38,21 +38,6 @@ jobs:
python deploy.py
mv dist/Ghost-Downloader-3.dist dist/Ghost-Downloader-3-Unsigned.dist
- - name: Copy FeaturePacks
- shell: pwsh
- run: |
- $targetRoot = "dist/Ghost-Downloader-3-Unsigned.dist/features"
- New-Item -ItemType Directory -Force -Path $targetRoot | Out-Null
-
- foreach ($pack in @("http_pack", "bili_pack", "ffmpeg_pack")) {
- $source = Join-Path "features" $pack
- $target = Join-Path $targetRoot $pack
- if (Test-Path $target) {
- Remove-Item -Recurse -Force $target
- }
- Copy-Item -Recurse -Force $source $target
- }
-
- name: upload-unsigned-artifact
id: upload-unsigned-artifact
uses: actions/upload-artifact@v4
@@ -135,16 +120,6 @@ jobs:
mv "dist/Ghost-Downloader-3.app" "dist/Ghost Downloader.app"
mv "app/assets/修复软件损坏" "dist/修复软件损坏"
- - name: Copy FeaturePacks
- run: |
- target_root="dist/Ghost Downloader.app/Contents/MacOS/features"
- mkdir -p "$target_root"
-
- for pack in http_pack bili_pack ffmpeg_pack; do
- rm -rf "$target_root/$pack"
- cp -R "features/$pack" "$target_root/$pack"
- done
-
- name: Create DMG
run: |
ln -s /Applications dist/Applications
@@ -209,16 +184,6 @@ jobs:
mv "dist/Ghost-Downloader-3.app" "dist/Ghost Downloader.app"
mv "app/assets/修复软件损坏" "dist/修复软件损坏"
- - name: Copy FeaturePacks
- run: |
- target_root="dist/Ghost Downloader.app/Contents/MacOS/features"
- mkdir -p "$target_root"
-
- for pack in http_pack bili_pack ffmpeg_pack; do
- rm -rf "$target_root/$pack"
- cp -R "features/$pack" "$target_root/$pack"
- done
-
- name: Reinstall openssl libs
run: |
brew install openssl@3
@@ -266,16 +231,6 @@ jobs:
python deploy.py
chmod +x "dist/Ghost-Downloader-3.dist/Ghost-Downloader-3.bin"
- - name: Copy FeaturePacks
- run: |
- target_root="dist/Ghost-Downloader-3.dist/features"
- mkdir -p "$target_root"
-
- for pack in http_pack bili_pack ffmpeg_pack; do
- rm -rf "$target_root/$pack"
- cp -R "features/$pack" "$target_root/$pack"
- done
-
- name: Tar the contents of Ghost-Downloader
shell: pwsh
run: |
diff --git a/.github/workflows/build_Linux.yml b/.github/workflows/build_Linux.yml
index 34196a21..24a58ab2 100644
--- a/.github/workflows/build_Linux.yml
+++ b/.github/workflows/build_Linux.yml
@@ -34,16 +34,6 @@ jobs:
rm -rf version.txt
python deploy.py
- - name: Copy FeaturePacks
- run: |
- target_root="dist/Ghost-Downloader-3.dist/features"
- mkdir -p "$target_root"
-
- for pack in http_pack bili_pack ffmpeg_pack; do
- rm -rf "$target_root/$pack"
- cp -R "features/$pack" "$target_root/$pack"
- done
-
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
diff --git a/.github/workflows/build_Windows.yml b/.github/workflows/build_Windows.yml
index 6340e759..2c5dd852 100644
--- a/.github/workflows/build_Windows.yml
+++ b/.github/workflows/build_Windows.yml
@@ -50,21 +50,6 @@ jobs:
del version.txt
python deploy.py
- - name: Copy FeaturePacks
- shell: pwsh
- run: |
- $targetRoot = "dist/Ghost-Downloader-3.dist/features"
- New-Item -ItemType Directory -Force -Path $targetRoot | Out-Null
-
- foreach ($pack in @("http_pack", "bili_pack", "ffmpeg_pack")) {
- $source = Join-Path "features" $pack
- $target = Join-Path $targetRoot $pack
- if (Test-Path $target) {
- Remove-Item -Recurse -Force $target
- }
- Copy-Item -Recurse -Force $source $target
- }
-
- name: Prepare For Sign
if: ${{ github.event.inputs.sign_artifact == 'true' }}
run: |
diff --git a/.github/workflows/build_macOS.yml b/.github/workflows/build_macOS.yml
index 4c41cd43..9166ec93 100644
--- a/.github/workflows/build_macOS.yml
+++ b/.github/workflows/build_macOS.yml
@@ -37,16 +37,6 @@ jobs:
mv "dist/Ghost-Downloader-3.app" "dist/Ghost Downloader.app"
mv "app/assets/修复软件损坏" "dist/修复软件损坏"
- - name: Copy FeaturePacks
- run: |
- target_root="dist/Ghost Downloader.app/Contents/MacOS/features"
- mkdir -p "$target_root"
-
- for pack in http_pack bili_pack ffmpeg_pack; do
- rm -rf "$target_root/$pack"
- cp -R "features/$pack" "$target_root/$pack"
- done
-
- name: Create DMG
run: |
ln -s /Applications dist/Applications
@@ -111,16 +101,6 @@ jobs:
mv "dist/Ghost-Downloader-3.app" "dist/Ghost Downloader.app"
mv "app/assets/修复软件损坏" "dist/修复软件损坏"
- - name: Copy FeaturePacks
- run: |
- target_root="dist/Ghost Downloader.app/Contents/MacOS/features"
- mkdir -p "$target_root"
-
- for pack in http_pack bili_pack ffmpeg_pack; do
- rm -rf "$target_root/$pack"
- cp -R "features/$pack" "$target_root/$pack"
- done
-
- name: Reinstall openssl libs
run: |
brew install openssl@3
diff --git a/deploy.py b/deploy.py
index 46913342..2de20a1b 100644
--- a/deploy.py
+++ b/deploy.py
@@ -1,67 +1,85 @@
-import os
+import shutil
+import subprocess
import sys
+from pathlib import Path
from app.supports.config import VERSION, YEAR, AUTHOR
-if sys.platform == "win32":
- args = [
- 'nuitka',
- '--standalone', # Following all imports is the default for standalone mode and need not be specified.
- '--windows-console-mode=disable',
- '--plugin-enable=pyside6',
- '--include-package=urllib3',
- '--include-package=qrcode',
- '--include-package=winrt',
- '--include-module=app.supports.sysio',
- '--assume-yes-for-downloads',
- '--msvc=latest', # Use MSVC
- # '--mingw64', # Use MinGW
- # '--show-memory' ,
- # '--show-progress' ,
- '--windows-icon-from-ico=app/assets/logo.ico',
- '--company-name=XiaoYouChR',
- '--product-name="Ghost Downloader"',
- f'--file-version={VERSION}',
- f'--product-version={VERSION}',
- '--file-description="Ghost Downloader"',
- f'--copyright="Copyright(C) {YEAR} {AUTHOR}"',
- '--output-dir=dist',
- 'Ghost-Downloader-3.py',
- ]
+FEATURES_ROOT = Path("features")
+FEATURE_PACK_BLACKLIST = {"jack_yao"}
+COMMON_INCLUDE_PACKAGES = [
+ "urllib3",
+ "qrcode",
+ "libtorrent"
+]
+PLATFORM_INCLUDE_PACKAGES = {
+ "win32": [
+ "winrt",
+ ],
+}
+INCLUDE_MODULES = [
+ "app.supports.sysio",
+]
- if "--onefile" in sys.argv:
- args.pop(args.index("--standalone"))
- args.insert(1, "--onefile")
- args.insert(1, "--onefile-cache-mode=cached")
-elif sys.platform == "darwin":
- args = [
- 'python3 -m nuitka',
- '--standalone',
- '--plugin-enable=pyside6',
- '--include-package=urllib3',
- '--include-package=qrcode',
- '--include-module=app.supports.sysio',
- # '--show-memory',
- # '--show-progress',
- '--static-libpython=no',
- "--macos-create-app-bundle",
- "--assume-yes-for-download",
- "--macos-app-mode=gui",
- f"--macos-app-version={VERSION}",
- "--macos-app-icon=app/assets/logo.icns",
- f'--copyright="Copyright(C) {YEAR} {AUTHOR}"',
- '--output-dir=dist',
- 'Ghost-Downloader-3.py',
+def build_include_args() -> list[str]:
+ include_packages = COMMON_INCLUDE_PACKAGES + PLATFORM_INCLUDE_PACKAGES.get(sys.platform, [])
+ return [
+ *[f"--include-package={package}" for package in include_packages],
+ *[f"--include-module={module}" for module in INCLUDE_MODULES],
]
-else:
- args = [
- 'nuitka',
+
+
+def build_args() -> list[str]:
+ nuitka_command = f'"{sys.executable}" -m nuitka'
+
+ if sys.platform == "win32":
+ return [
+ nuitka_command,
+ '--standalone', # Following all imports is the default for standalone mode and need not be specified.
+ '--windows-console-mode=disable',
+ '--plugin-enable=pyside6',
+ *build_include_args(),
+ '--assume-yes-for-downloads',
+ '--msvc=latest', # Use MSVC
+ # '--mingw64', # Use MinGW
+ # '--show-memory' ,
+ # '--show-progress' ,
+ '--windows-icon-from-ico=app/assets/logo.ico',
+ '--company-name=XiaoYouChR',
+ '--product-name="Ghost Downloader"',
+ f'--file-version={VERSION}',
+ f'--product-version={VERSION}',
+ '--file-description="Ghost Downloader"',
+ f'--copyright="Copyright(C) {YEAR} {AUTHOR}"',
+ '--output-dir=dist',
+ 'Ghost-Downloader-3.py',
+ ]
+
+ if sys.platform == "darwin":
+ return [
+ nuitka_command,
+ '--standalone',
+ '--plugin-enable=pyside6',
+ *build_include_args(),
+ # '--show-memory',
+ # '--show-progress',
+ '--static-libpython=no',
+ "--macos-create-app-bundle",
+ "--assume-yes-for-download",
+ "--macos-app-mode=gui",
+ f"--macos-app-version={VERSION}",
+ "--macos-app-icon=app/assets/logo.icns",
+ f'--copyright="Copyright(C) {YEAR} {AUTHOR}"',
+ '--output-dir=dist',
+ 'Ghost-Downloader-3.py',
+ ]
+
+ return [
+ nuitka_command,
'--standalone',
'--plugin-enable=pyside6',
- '--include-package=urllib3',
- '--include-package=qrcode',
- '--include-module=app.supports.sysio',
+ *build_include_args(),
'--include-qt-plugins=platforms',
'--assume-yes-for-downloads',
# '--show-memory',
@@ -71,5 +89,61 @@ else:
'Ghost-Downloader-3.py',
]
-print(args)
-os.system(' '.join(args))
+
+def get_feature_pack_sources() -> list[Path]:
+ if not FEATURES_ROOT.is_dir():
+ raise FileNotFoundError(f"FeaturePacks source directory not found: {FEATURES_ROOT}")
+
+ return sorted(
+ (
+ item
+ for item in FEATURES_ROOT.iterdir()
+ if item.is_dir()
+ and item.name not in FEATURE_PACK_BLACKLIST
+ and (item / "manifest.toml").is_file()
+ ),
+ key=lambda item: item.name,
+ )
+
+
+def get_feature_pack_target_root() -> Path:
+ if sys.platform == "darwin":
+ return Path("dist") / "Ghost-Downloader-3.app" / "Contents" / "MacOS" / "features"
+ return Path("dist") / "Ghost-Downloader-3.dist" / "features"
+
+
+def copy_feature_packs() -> None:
+ feature_pack_sources = get_feature_pack_sources()
+ if not feature_pack_sources:
+ raise RuntimeError("No feature packs were found to copy.")
+
+ target_root = get_feature_pack_target_root()
+ if not target_root.parent.exists():
+ raise FileNotFoundError(f"FeaturePacks target directory does not exist: {target_root.parent}")
+
+ if target_root.exists():
+ shutil.rmtree(target_root)
+ target_root.mkdir(parents=True, exist_ok=True)
+
+ for source in feature_pack_sources:
+ shutil.copytree(source, target_root / source.name)
+
+ print(f"Copied FeaturePacks to {target_root}: {[source.name for source in feature_pack_sources]}")
+
+
+def main() -> int:
+ args = build_args()
+ command = ' '.join(args)
+
+ print(command)
+ result = subprocess.run(command, shell=True)
+ if result.returncode != 0:
+ return result.returncode
+
+ copy_feature_packs()
+
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())