|
1 | | -import os |
| 1 | +import shutil |
| 2 | +import subprocess |
2 | 3 | import sys |
| 4 | +from pathlib import Path |
3 | 5 |
|
4 | 6 | from app.supports.config import VERSION, YEAR, AUTHOR |
5 | 7 |
|
6 | | -if sys.platform == "win32": |
7 | | - args = [ |
8 | | - 'nuitka', |
9 | | - '--standalone', # Following all imports is the default for standalone mode and need not be specified. |
10 | | - '--windows-console-mode=disable', |
11 | | - '--plugin-enable=pyside6', |
12 | | - '--include-package=urllib3', |
13 | | - '--include-package=qrcode', |
14 | | - '--include-package=winrt', |
15 | | - '--include-module=app.supports.sysio', |
16 | | - '--assume-yes-for-downloads', |
17 | | - '--msvc=latest', # Use MSVC |
18 | | - # '--mingw64', # Use MinGW |
19 | | - # '--show-memory' , |
20 | | - # '--show-progress' , |
21 | | - '--windows-icon-from-ico=app/assets/logo.ico', |
22 | | - '--company-name=XiaoYouChR', |
23 | | - '--product-name="Ghost Downloader"', |
24 | | - f'--file-version={VERSION}', |
25 | | - f'--product-version={VERSION}', |
26 | | - '--file-description="Ghost Downloader"', |
27 | | - f'--copyright="Copyright(C) {YEAR} {AUTHOR}"', |
28 | | - '--output-dir=dist', |
29 | | - 'Ghost-Downloader-3.py', |
30 | | - ] |
| 8 | +FEATURES_ROOT = Path("features") |
| 9 | +FEATURE_PACK_BLACKLIST = {"jack_yao"} |
| 10 | +COMMON_INCLUDE_PACKAGES = [ |
| 11 | + "urllib3", |
| 12 | + "qrcode", |
| 13 | + "libtorrent" |
| 14 | +] |
| 15 | +PLATFORM_INCLUDE_PACKAGES = { |
| 16 | + "win32": [ |
| 17 | + "winrt", |
| 18 | + ], |
| 19 | +} |
| 20 | +INCLUDE_MODULES = [ |
| 21 | + "app.supports.sysio", |
| 22 | +] |
31 | 23 |
|
32 | | - if "--onefile" in sys.argv: |
33 | | - args.pop(args.index("--standalone")) |
34 | | - args.insert(1, "--onefile") |
35 | | - args.insert(1, "--onefile-cache-mode=cached") |
36 | 24 |
|
37 | | -elif sys.platform == "darwin": |
38 | | - args = [ |
39 | | - 'python3 -m nuitka', |
40 | | - '--standalone', |
41 | | - '--plugin-enable=pyside6', |
42 | | - '--include-package=urllib3', |
43 | | - '--include-package=qrcode', |
44 | | - '--include-module=app.supports.sysio', |
45 | | - # '--show-memory', |
46 | | - # '--show-progress', |
47 | | - '--static-libpython=no', |
48 | | - "--macos-create-app-bundle", |
49 | | - "--assume-yes-for-download", |
50 | | - "--macos-app-mode=gui", |
51 | | - f"--macos-app-version={VERSION}", |
52 | | - "--macos-app-icon=app/assets/logo.icns", |
53 | | - f'--copyright="Copyright(C) {YEAR} {AUTHOR}"', |
54 | | - '--output-dir=dist', |
55 | | - 'Ghost-Downloader-3.py', |
| 25 | +def build_include_args() -> list[str]: |
| 26 | + include_packages = COMMON_INCLUDE_PACKAGES + PLATFORM_INCLUDE_PACKAGES.get(sys.platform, []) |
| 27 | + return [ |
| 28 | + *[f"--include-package={package}" for package in include_packages], |
| 29 | + *[f"--include-module={module}" for module in INCLUDE_MODULES], |
56 | 30 | ] |
57 | | -else: |
58 | | - args = [ |
59 | | - 'nuitka', |
| 31 | + |
| 32 | + |
| 33 | +def build_args() -> list[str]: |
| 34 | + nuitka_command = f'"{sys.executable}" -m nuitka' |
| 35 | + |
| 36 | + if sys.platform == "win32": |
| 37 | + return [ |
| 38 | + nuitka_command, |
| 39 | + '--standalone', # Following all imports is the default for standalone mode and need not be specified. |
| 40 | + '--windows-console-mode=disable', |
| 41 | + '--plugin-enable=pyside6', |
| 42 | + *build_include_args(), |
| 43 | + '--assume-yes-for-downloads', |
| 44 | + '--msvc=latest', # Use MSVC |
| 45 | + # '--mingw64', # Use MinGW |
| 46 | + # '--show-memory' , |
| 47 | + # '--show-progress' , |
| 48 | + '--windows-icon-from-ico=app/assets/logo.ico', |
| 49 | + '--company-name=XiaoYouChR', |
| 50 | + '--product-name="Ghost Downloader"', |
| 51 | + f'--file-version={VERSION}', |
| 52 | + f'--product-version={VERSION}', |
| 53 | + '--file-description="Ghost Downloader"', |
| 54 | + f'--copyright="Copyright(C) {YEAR} {AUTHOR}"', |
| 55 | + '--output-dir=dist', |
| 56 | + 'Ghost-Downloader-3.py', |
| 57 | + ] |
| 58 | + |
| 59 | + if sys.platform == "darwin": |
| 60 | + return [ |
| 61 | + nuitka_command, |
| 62 | + '--standalone', |
| 63 | + '--plugin-enable=pyside6', |
| 64 | + *build_include_args(), |
| 65 | + # '--show-memory', |
| 66 | + # '--show-progress', |
| 67 | + '--static-libpython=no', |
| 68 | + "--macos-create-app-bundle", |
| 69 | + "--assume-yes-for-download", |
| 70 | + "--macos-app-mode=gui", |
| 71 | + f"--macos-app-version={VERSION}", |
| 72 | + "--macos-app-icon=app/assets/logo.icns", |
| 73 | + f'--copyright="Copyright(C) {YEAR} {AUTHOR}"', |
| 74 | + '--output-dir=dist', |
| 75 | + 'Ghost-Downloader-3.py', |
| 76 | + ] |
| 77 | + |
| 78 | + return [ |
| 79 | + nuitka_command, |
60 | 80 | '--standalone', |
61 | 81 | '--plugin-enable=pyside6', |
62 | | - '--include-package=urllib3', |
63 | | - '--include-package=qrcode', |
64 | | - '--include-module=app.supports.sysio', |
| 82 | + *build_include_args(), |
65 | 83 | '--include-qt-plugins=platforms', |
66 | 84 | '--assume-yes-for-downloads', |
67 | 85 | # '--show-memory', |
|
71 | 89 | 'Ghost-Downloader-3.py', |
72 | 90 | ] |
73 | 91 |
|
74 | | -print(args) |
75 | | -os.system(' '.join(args)) |
| 92 | + |
| 93 | +def get_feature_pack_sources() -> list[Path]: |
| 94 | + if not FEATURES_ROOT.is_dir(): |
| 95 | + raise FileNotFoundError(f"FeaturePacks source directory not found: {FEATURES_ROOT}") |
| 96 | + |
| 97 | + return sorted( |
| 98 | + ( |
| 99 | + item |
| 100 | + for item in FEATURES_ROOT.iterdir() |
| 101 | + if item.is_dir() |
| 102 | + and item.name not in FEATURE_PACK_BLACKLIST |
| 103 | + and (item / "manifest.toml").is_file() |
| 104 | + ), |
| 105 | + key=lambda item: item.name, |
| 106 | + ) |
| 107 | + |
| 108 | + |
| 109 | +def get_feature_pack_target_root() -> Path: |
| 110 | + if sys.platform == "darwin": |
| 111 | + return Path("dist") / "Ghost-Downloader-3.app" / "Contents" / "MacOS" / "features" |
| 112 | + return Path("dist") / "Ghost-Downloader-3.dist" / "features" |
| 113 | + |
| 114 | + |
| 115 | +def copy_feature_packs() -> None: |
| 116 | + feature_pack_sources = get_feature_pack_sources() |
| 117 | + if not feature_pack_sources: |
| 118 | + raise RuntimeError("No feature packs were found to copy.") |
| 119 | + |
| 120 | + target_root = get_feature_pack_target_root() |
| 121 | + if not target_root.parent.exists(): |
| 122 | + raise FileNotFoundError(f"FeaturePacks target directory does not exist: {target_root.parent}") |
| 123 | + |
| 124 | + if target_root.exists(): |
| 125 | + shutil.rmtree(target_root) |
| 126 | + target_root.mkdir(parents=True, exist_ok=True) |
| 127 | + |
| 128 | + for source in feature_pack_sources: |
| 129 | + shutil.copytree(source, target_root / source.name) |
| 130 | + |
| 131 | + print(f"Copied FeaturePacks to {target_root}: {[source.name for source in feature_pack_sources]}") |
| 132 | + |
| 133 | + |
| 134 | +def main() -> int: |
| 135 | + args = build_args() |
| 136 | + command = ' '.join(args) |
| 137 | + |
| 138 | + print(command) |
| 139 | + result = subprocess.run(command, shell=True) |
| 140 | + if result.returncode != 0: |
| 141 | + return result.returncode |
| 142 | + |
| 143 | + copy_feature_packs() |
| 144 | + |
| 145 | + return 0 |
| 146 | + |
| 147 | + |
| 148 | +if __name__ == "__main__": |
| 149 | + raise SystemExit(main()) |
0 commit comments