unifypy 2.0.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unifypy/__init__.py +7 -0
- unifypy/__main__.py +21 -0
- unifypy/cli/__init__.py +10 -0
- unifypy/cli/argument_parser.py +209 -0
- unifypy/core/__init__.py +8 -0
- unifypy/core/config.py +491 -0
- unifypy/core/context.py +36 -0
- unifypy/core/engine.py +93 -0
- unifypy/core/environment.py +509 -0
- unifypy/core/event_bus.py +37 -0
- unifypy/core/events.py +16 -0
- unifypy/core/platforms.py +58 -0
- unifypy/core/plugin.py +65 -0
- unifypy/core/validators/__init__.py +10 -0
- unifypy/core/validators/tool_validator.py +144 -0
- unifypy/platforms/__init__.py +10 -0
- unifypy/platforms/base.py +127 -0
- unifypy/platforms/linux/__init__.py +10 -0
- unifypy/platforms/linux/deb_packager.py +289 -0
- unifypy/platforms/linux/rpm_packager.py +332 -0
- unifypy/platforms/macos/__init__.py +10 -0
- unifypy/platforms/macos/dmg_packager.py +477 -0
- unifypy/platforms/macos/post_processor.py +272 -0
- unifypy/platforms/registry.py +108 -0
- unifypy/platforms/windows/__init__.py +9 -0
- unifypy/platforms/windows/inno_setup.py +715 -0
- unifypy/plugins/__init__.py +3 -0
- unifypy/plugins/auto_rollback_plugin.py +156 -0
- unifypy/plugins/cleanup_plugin.py +22 -0
- unifypy/plugins/config_plugin.py +42 -0
- unifypy/plugins/dry_run_plugin.py +22 -0
- unifypy/plugins/environment_plugin.py +61 -0
- unifypy/plugins/external_plugins_loader.py +42 -0
- unifypy/plugins/packaging_plugin.py +125 -0
- unifypy/plugins/prepare_plugin.py +89 -0
- unifypy/plugins/progress_plugin.py +32 -0
- unifypy/plugins/pyinstaller_plugin.py +95 -0
- unifypy/plugins/rollback_plugin.py +62 -0
- unifypy/plugins/summary_plugin.py +36 -0
- unifypy/plugins/windows_language_plugin.py +85 -0
- unifypy/pyinstaller/__init__.py +7 -0
- unifypy/pyinstaller/config_builder.py +908 -0
- unifypy/templates/ChineseSimplified.isl.template +403 -0
- unifypy/templates/setup.iss.template +51 -0
- unifypy/tools/create-dmg/.this-is-the-create-dmg-repo +3 -0
- unifypy/tools/create-dmg/LICENSE +22 -0
- unifypy/tools/create-dmg/Makefile +33 -0
- unifypy/tools/create-dmg/README.md +126 -0
- unifypy/tools/create-dmg/builder/create-dmg.builder +26 -0
- unifypy/tools/create-dmg/create-dmg +621 -0
- unifypy/tools/create-dmg/doc-project/Developer Notes.md +35 -0
- unifypy/tools/create-dmg/doc-project/Release Checklist.md +10 -0
- unifypy/tools/create-dmg/examples/01-main-example/installer_background.png +0 -0
- unifypy/tools/create-dmg/examples/01-main-example/sample +30 -0
- unifypy/tools/create-dmg/examples/01-main-example/source_folder/Application.app +0 -0
- unifypy/tools/create-dmg/support/eula-resources-template.xml +105 -0
- unifypy/tools/create-dmg/support/template.applescript +74 -0
- unifypy/tools/create-dmg/tests/007-space-in-dir-name/my files/hello.txt +1 -0
- unifypy/tools/create-dmg/tests/007-space-in-dir-name/run-test +5 -0
- unifypy/utils/__init__.py +10 -0
- unifypy/utils/cache_manager.py +957 -0
- unifypy/utils/command_runner.py +195 -0
- unifypy/utils/entitlements_generator.py +450 -0
- unifypy/utils/file_ops.py +333 -0
- unifypy/utils/icon_converter.py +144 -0
- unifypy/utils/info_plist_updater.py +247 -0
- unifypy/utils/macos_codesign.py +225 -0
- unifypy/utils/parallel_builder.py +355 -0
- unifypy/utils/progress.py +371 -0
- unifypy/utils/progress_callback_factory.py +56 -0
- unifypy/utils/rollback.py +484 -0
- unifypy/utils/tool_manager.py +701 -0
- unifypy-2.0.2.dist-info/METADATA +609 -0
- unifypy-2.0.2.dist-info/RECORD +78 -0
- unifypy-2.0.2.dist-info/WHEEL +5 -0
- unifypy-2.0.2.dist-info/entry_points.txt +2 -0
- unifypy-2.0.2.dist-info/licenses/LICENSE +21 -0
- unifypy-2.0.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
MacOS Info.plist 更新器 在 PyInstaller 构建完成后,更新 Info.plist 添加权限描述.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import subprocess
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any, Dict
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class InfoPlistUpdater:
|
|
13
|
+
"""
|
|
14
|
+
Info.plist 更新器.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, verbose: bool = False):
|
|
18
|
+
self.verbose = verbose
|
|
19
|
+
|
|
20
|
+
def _print(self, message: str):
|
|
21
|
+
"""
|
|
22
|
+
只在 verbose 模式下打印信息.
|
|
23
|
+
"""
|
|
24
|
+
if self.verbose:
|
|
25
|
+
print(message)
|
|
26
|
+
|
|
27
|
+
# 配置键到 Info.plist 权限描述键的映射
|
|
28
|
+
PERMISSION_MAPPING = {
|
|
29
|
+
"microphone_usage_description": "NSMicrophoneUsageDescription",
|
|
30
|
+
"camera_usage_description": "NSCameraUsageDescription",
|
|
31
|
+
"speech_recognition_usage_description": "NSSpeechRecognitionUsageDescription",
|
|
32
|
+
"local_network_usage_description": "NSLocalNetworkUsageDescription",
|
|
33
|
+
"audio_usage_description": "NSAudioUsageDescription",
|
|
34
|
+
"accessibility_usage_description": "NSAccessibilityUsageDescription",
|
|
35
|
+
"documents_folder_usage_description": "NSDocumentsFolderUsageDescription",
|
|
36
|
+
"downloads_folder_usage_description": "NSDownloadsFolderUsageDescription",
|
|
37
|
+
"desktop_folder_usage_description": "NSDesktopFolderUsageDescription",
|
|
38
|
+
"apple_events_usage_description": "NSAppleEventsUsageDescription",
|
|
39
|
+
"system_administration_usage_description": "NSSystemAdministrationUsageDescription",
|
|
40
|
+
"contacts_usage_description": "NSContactsUsageDescription",
|
|
41
|
+
"calendars_usage_description": "NSCalendarsUsageDescription",
|
|
42
|
+
"reminders_usage_description": "NSRemindersUsageDescription",
|
|
43
|
+
"photo_library_usage_description": "NSPhotoLibraryUsageDescription",
|
|
44
|
+
"photo_library_add_usage_description": "NSPhotoLibraryAddUsageDescription",
|
|
45
|
+
"location_when_in_use_usage_description": "NSLocationWhenInUseUsageDescription",
|
|
46
|
+
"location_always_and_when_in_use_usage_description": "NSLocationAlwaysAndWhenInUseUsageDescription",
|
|
47
|
+
"bluetooth_always_usage_description": "NSBluetoothAlwaysUsageDescription",
|
|
48
|
+
"bluetooth_peripheral_usage_description": "NSBluetoothPeripheralUsageDescription",
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
def update_app_info_plist(
|
|
52
|
+
self, app_path: Path, macos_config: Dict[str, Any]
|
|
53
|
+
) -> bool:
|
|
54
|
+
"""更新 .app 包中的 Info.plist 文件.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
app_path: .app 包路径
|
|
58
|
+
macos_config: macOS 配置字典
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
bool: 更新是否成功
|
|
62
|
+
"""
|
|
63
|
+
if not app_path.exists() or not app_path.name.endswith(".app"):
|
|
64
|
+
print(f"❌ 无效的 .app 包路径: {app_path}") # 错误信息始终显示
|
|
65
|
+
return False
|
|
66
|
+
|
|
67
|
+
info_plist_path = app_path / "Contents" / "Info.plist"
|
|
68
|
+
|
|
69
|
+
if not info_plist_path.exists():
|
|
70
|
+
print(f"❌ Info.plist 不存在: {info_plist_path}") # 错误信息始终显示
|
|
71
|
+
return False
|
|
72
|
+
|
|
73
|
+
self._print(f"🔧 更新 Info.plist 权限描述: {info_plist_path}")
|
|
74
|
+
|
|
75
|
+
# 备份原始文件
|
|
76
|
+
backup_path = info_plist_path.with_suffix(".plist.backup")
|
|
77
|
+
try:
|
|
78
|
+
import shutil
|
|
79
|
+
|
|
80
|
+
shutil.copy2(info_plist_path, backup_path)
|
|
81
|
+
self._print(f"✅ Info.plist 已备份: {backup_path}")
|
|
82
|
+
except Exception as e:
|
|
83
|
+
self._print(f"⚠️ 备份失败: {e}")
|
|
84
|
+
|
|
85
|
+
success_count = 0
|
|
86
|
+
total_permissions = 0
|
|
87
|
+
|
|
88
|
+
# 添加权限描述
|
|
89
|
+
for config_key, description in macos_config.items():
|
|
90
|
+
if config_key in self.PERMISSION_MAPPING and description:
|
|
91
|
+
plist_key = self.PERMISSION_MAPPING[config_key]
|
|
92
|
+
|
|
93
|
+
if self._update_plist_permission(
|
|
94
|
+
info_plist_path, plist_key, description
|
|
95
|
+
):
|
|
96
|
+
success_count += 1
|
|
97
|
+
self._print(f" ✅ {plist_key}: {description[:50]}...")
|
|
98
|
+
else:
|
|
99
|
+
print(f" ❌ {plist_key}: 更新失败") # 错误信息始终显示
|
|
100
|
+
|
|
101
|
+
total_permissions += 1
|
|
102
|
+
|
|
103
|
+
# 添加一些特殊权限
|
|
104
|
+
self._add_special_permissions(info_plist_path, macos_config)
|
|
105
|
+
|
|
106
|
+
self._print(f"📋 权限描述更新完成: {success_count}/{total_permissions}")
|
|
107
|
+
return success_count > 0
|
|
108
|
+
|
|
109
|
+
def _update_plist_permission(
|
|
110
|
+
self, plist_path: Path, key: str, description: str
|
|
111
|
+
) -> bool:
|
|
112
|
+
"""使用 PlistBuddy 更新单个权限描述.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
plist_path: plist 文件路径
|
|
116
|
+
key: 权限键
|
|
117
|
+
description: 权限描述
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
bool: 更新是否成功
|
|
121
|
+
"""
|
|
122
|
+
try:
|
|
123
|
+
# 尝试添加新键值
|
|
124
|
+
add_cmd = [
|
|
125
|
+
"/usr/libexec/PlistBuddy",
|
|
126
|
+
"-c",
|
|
127
|
+
f'Add :{key} string "{description}"',
|
|
128
|
+
str(plist_path),
|
|
129
|
+
]
|
|
130
|
+
|
|
131
|
+
result = subprocess.run(
|
|
132
|
+
add_cmd, capture_output=True, text=True, check=False
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
# 如果添加失败(可能已存在),尝试更新
|
|
136
|
+
if result.returncode != 0:
|
|
137
|
+
set_cmd = [
|
|
138
|
+
"/usr/libexec/PlistBuddy",
|
|
139
|
+
"-c",
|
|
140
|
+
f'Set :{key} "{description}"',
|
|
141
|
+
str(plist_path),
|
|
142
|
+
]
|
|
143
|
+
|
|
144
|
+
result = subprocess.run(
|
|
145
|
+
set_cmd, capture_output=True, text=True, check=False
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
return result.returncode == 0
|
|
149
|
+
|
|
150
|
+
except Exception as e:
|
|
151
|
+
print(f"❌ PlistBuddy 执行异常: {e}") # 错误信息始终显示
|
|
152
|
+
return False
|
|
153
|
+
|
|
154
|
+
def _add_special_permissions(self, plist_path: Path, macos_config: Dict[str, Any]):
|
|
155
|
+
"""
|
|
156
|
+
添加特殊权限配置.
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
# 添加后台音频权限(如果需要音频访问)
|
|
160
|
+
if macos_config.get("audio_usage_description") or macos_config.get(
|
|
161
|
+
"microphone_usage_description"
|
|
162
|
+
):
|
|
163
|
+
try:
|
|
164
|
+
# 创建 UIBackgroundModes 数组
|
|
165
|
+
subprocess.run(
|
|
166
|
+
[
|
|
167
|
+
"/usr/libexec/PlistBuddy",
|
|
168
|
+
"-c",
|
|
169
|
+
"Add :UIBackgroundModes array",
|
|
170
|
+
str(plist_path),
|
|
171
|
+
],
|
|
172
|
+
capture_output=True,
|
|
173
|
+
check=False,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
# 添加 audio 模式
|
|
177
|
+
subprocess.run(
|
|
178
|
+
[
|
|
179
|
+
"/usr/libexec/PlistBuddy",
|
|
180
|
+
"-c",
|
|
181
|
+
'Add :UIBackgroundModes:0 string "audio"',
|
|
182
|
+
str(plist_path),
|
|
183
|
+
],
|
|
184
|
+
capture_output=True,
|
|
185
|
+
check=False,
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
self._print(" ✅ 添加后台音频权限")
|
|
189
|
+
|
|
190
|
+
except Exception:
|
|
191
|
+
pass # 忽略错误,可能已存在
|
|
192
|
+
|
|
193
|
+
# 添加音频会话类别
|
|
194
|
+
if macos_config.get("audio_usage_description"):
|
|
195
|
+
try:
|
|
196
|
+
subprocess.run(
|
|
197
|
+
[
|
|
198
|
+
"/usr/libexec/PlistBuddy",
|
|
199
|
+
"-c",
|
|
200
|
+
"Add :AVAudioSessionCategoryPlayAndRecord bool true",
|
|
201
|
+
str(plist_path),
|
|
202
|
+
],
|
|
203
|
+
capture_output=True,
|
|
204
|
+
check=False,
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
self._print(" ✅ 添加音频会话类别")
|
|
208
|
+
|
|
209
|
+
except Exception:
|
|
210
|
+
pass # 忽略错误,可能已存在
|
|
211
|
+
|
|
212
|
+
def list_app_permissions(self, app_path: Path) -> Dict[str, str]:
|
|
213
|
+
"""列出 .app 包中的所有权限描述.
|
|
214
|
+
|
|
215
|
+
Args:
|
|
216
|
+
app_path: .app 包路径
|
|
217
|
+
|
|
218
|
+
Returns:
|
|
219
|
+
Dict[str, str]: 权限键值对
|
|
220
|
+
"""
|
|
221
|
+
info_plist_path = app_path / "Contents" / "Info.plist"
|
|
222
|
+
|
|
223
|
+
if not info_plist_path.exists():
|
|
224
|
+
return {}
|
|
225
|
+
|
|
226
|
+
permissions = {}
|
|
227
|
+
|
|
228
|
+
for plist_key in self.PERMISSION_MAPPING.values():
|
|
229
|
+
try:
|
|
230
|
+
cmd = [
|
|
231
|
+
"/usr/libexec/PlistBuddy",
|
|
232
|
+
"-c",
|
|
233
|
+
f"Print :{plist_key}",
|
|
234
|
+
str(info_plist_path),
|
|
235
|
+
]
|
|
236
|
+
|
|
237
|
+
result = subprocess.run(
|
|
238
|
+
cmd, capture_output=True, text=True, check=False
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
if result.returncode == 0:
|
|
242
|
+
permissions[plist_key] = result.stdout.strip()
|
|
243
|
+
|
|
244
|
+
except Exception:
|
|
245
|
+
continue
|
|
246
|
+
|
|
247
|
+
return permissions
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
MacOS 代码签名工具 为未签名应用执行 ad-hoc 签名以应用 entitlements.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import subprocess
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Optional
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class MacOSCodeSigner:
|
|
13
|
+
"""
|
|
14
|
+
MacOS 代码签名器.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, verbose: bool = False):
|
|
18
|
+
self.codesign_path = None
|
|
19
|
+
self.verbose = verbose
|
|
20
|
+
|
|
21
|
+
def _print(self, message: str):
|
|
22
|
+
"""
|
|
23
|
+
只在 verbose 模式下打印信息.
|
|
24
|
+
"""
|
|
25
|
+
if self.verbose:
|
|
26
|
+
print(message)
|
|
27
|
+
|
|
28
|
+
def sign_app_with_entitlements(
|
|
29
|
+
self, app_path: Path, entitlements_path: Optional[Path] = None
|
|
30
|
+
) -> bool:
|
|
31
|
+
"""对 .app 包执行 ad-hoc 签名.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
app_path: .app 包路径
|
|
35
|
+
entitlements_path: entitlements.plist 文件路径
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
bool: 签名是否成功
|
|
39
|
+
"""
|
|
40
|
+
if not app_path.exists() or not app_path.name.endswith(".app"):
|
|
41
|
+
print(f"❌ 无效的 .app 包: {app_path}") # 错误信息始终显示
|
|
42
|
+
return False
|
|
43
|
+
|
|
44
|
+
self._print(f"🔐 开始 ad-hoc 代码签名: {app_path.name}")
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
# 移除现有签名(如果有)
|
|
48
|
+
self._print(" 🗑️ 移除现有代码签名...")
|
|
49
|
+
self._remove_existing_signature(app_path)
|
|
50
|
+
|
|
51
|
+
# 执行 ad-hoc 签名
|
|
52
|
+
codesign_cmd = self.codesign_path if self.codesign_path else "codesign"
|
|
53
|
+
cmd = [
|
|
54
|
+
codesign_cmd,
|
|
55
|
+
"--force", # 强制签名
|
|
56
|
+
"--deep", # 深度签名(包含所有内容)
|
|
57
|
+
"--sign",
|
|
58
|
+
"-", # 使用 ad-hoc 签名(-表示本地签名)
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
# 如果有 entitlements 文件,添加到签名中
|
|
62
|
+
if entitlements_path and entitlements_path.exists():
|
|
63
|
+
cmd.extend(["--entitlements", str(entitlements_path)])
|
|
64
|
+
self._print(f" 📜 使用 entitlements: {entitlements_path}")
|
|
65
|
+
else:
|
|
66
|
+
self._print(" ⚠️ 没有 entitlements 文件,使用基础签名")
|
|
67
|
+
|
|
68
|
+
cmd.append(str(app_path))
|
|
69
|
+
|
|
70
|
+
self._print(f" 🚀 执行签名命令: {' '.join(cmd)}")
|
|
71
|
+
|
|
72
|
+
result = subprocess.run(cmd, capture_output=True, text=True, check=False)
|
|
73
|
+
|
|
74
|
+
if result.returncode == 0:
|
|
75
|
+
self._print(" ✅ 代码签名成功")
|
|
76
|
+
|
|
77
|
+
# 验证签名
|
|
78
|
+
if self._verify_signature(app_path):
|
|
79
|
+
self._print(" ✅ 签名验证通过")
|
|
80
|
+
return True
|
|
81
|
+
else:
|
|
82
|
+
self._print(" ⚠️ 签名验证失败,但应用仍可使用")
|
|
83
|
+
return True # 即使验证失败,签名可能还是有效的
|
|
84
|
+
else:
|
|
85
|
+
print(f" ❌ 代码签名失败:") # 错误信息始终显示
|
|
86
|
+
print(f" 错误输出: {result.stderr}")
|
|
87
|
+
|
|
88
|
+
# 尝试基本的可执行权限设置
|
|
89
|
+
self._set_executable_permissions(app_path)
|
|
90
|
+
return False
|
|
91
|
+
|
|
92
|
+
except Exception as e:
|
|
93
|
+
print(f"❌ 代码签名异常: {e}") # 错误信息始终显示
|
|
94
|
+
return False
|
|
95
|
+
|
|
96
|
+
def _remove_existing_signature(self, app_path: Path) -> bool:
|
|
97
|
+
"""
|
|
98
|
+
移除现有的代码签名.
|
|
99
|
+
"""
|
|
100
|
+
try:
|
|
101
|
+
# 找到主可执行文件
|
|
102
|
+
executable_path = self._find_main_executable(app_path)
|
|
103
|
+
if executable_path and executable_path.exists():
|
|
104
|
+
codesign_cmd = (
|
|
105
|
+
self.codesign_path if self.codesign_path else "/usr/bin/codesign"
|
|
106
|
+
)
|
|
107
|
+
cmd = [codesign_cmd, "--remove-signature", str(executable_path)]
|
|
108
|
+
subprocess.run(cmd, capture_output=True, check=False)
|
|
109
|
+
return True
|
|
110
|
+
except Exception:
|
|
111
|
+
return True # 忽略移除签名的错误
|
|
112
|
+
|
|
113
|
+
def _find_main_executable(self, app_path: Path) -> Optional[Path]:
|
|
114
|
+
"""
|
|
115
|
+
查找主可执行文件.
|
|
116
|
+
"""
|
|
117
|
+
try:
|
|
118
|
+
# 从 Info.plist 读取可执行文件名
|
|
119
|
+
info_plist = app_path / "Contents" / "Info.plist"
|
|
120
|
+
if info_plist.exists():
|
|
121
|
+
cmd = [
|
|
122
|
+
"/usr/libexec/PlistBuddy",
|
|
123
|
+
"-c",
|
|
124
|
+
"Print :CFBundleExecutable",
|
|
125
|
+
str(info_plist),
|
|
126
|
+
]
|
|
127
|
+
result = subprocess.run(
|
|
128
|
+
cmd, capture_output=True, text=True, check=False
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
if result.returncode == 0:
|
|
132
|
+
executable_name = result.stdout.strip()
|
|
133
|
+
executable_path = app_path / "Contents" / "MacOS" / executable_name
|
|
134
|
+
if executable_path.exists():
|
|
135
|
+
return executable_path
|
|
136
|
+
|
|
137
|
+
# 如果读取失败,尝试查找 MacOS 目录下的文件
|
|
138
|
+
macos_dir = app_path / "Contents" / "MacOS"
|
|
139
|
+
if macos_dir.exists():
|
|
140
|
+
for file in macos_dir.iterdir():
|
|
141
|
+
if file.is_file() and not file.name.startswith("."):
|
|
142
|
+
return file
|
|
143
|
+
|
|
144
|
+
except Exception:
|
|
145
|
+
pass
|
|
146
|
+
|
|
147
|
+
return None
|
|
148
|
+
|
|
149
|
+
def _verify_signature(self, app_path: Path) -> bool:
|
|
150
|
+
"""
|
|
151
|
+
验证代码签名.
|
|
152
|
+
"""
|
|
153
|
+
try:
|
|
154
|
+
codesign_cmd = (
|
|
155
|
+
self.codesign_path if self.codesign_path else "/usr/bin/codesign"
|
|
156
|
+
)
|
|
157
|
+
cmd = [codesign_cmd, "-dv", "--verbose=4", str(app_path)]
|
|
158
|
+
result = subprocess.run(cmd, capture_output=True, text=True, check=False)
|
|
159
|
+
|
|
160
|
+
# codesign -dv 在成功时返回非零退出码,但输出到 stderr
|
|
161
|
+
if "adhoc" in result.stderr.lower() or "signed" in result.stderr.lower():
|
|
162
|
+
return True
|
|
163
|
+
|
|
164
|
+
return False
|
|
165
|
+
|
|
166
|
+
except Exception:
|
|
167
|
+
return False
|
|
168
|
+
|
|
169
|
+
def _set_executable_permissions(self, app_path: Path):
|
|
170
|
+
"""
|
|
171
|
+
设置可执行权限(fallback)
|
|
172
|
+
"""
|
|
173
|
+
try:
|
|
174
|
+
executable_path = self._find_main_executable(app_path)
|
|
175
|
+
if executable_path and executable_path.exists():
|
|
176
|
+
import os
|
|
177
|
+
|
|
178
|
+
os.chmod(executable_path, 0o755)
|
|
179
|
+
self._print(f" ✅ 设置可执行权限: {executable_path}")
|
|
180
|
+
except Exception as e:
|
|
181
|
+
print(f" ⚠️ 设置可执行权限失败: {e}") # 错误信息始终显示
|
|
182
|
+
|
|
183
|
+
def check_codesign_available(self) -> bool:
|
|
184
|
+
"""
|
|
185
|
+
检查 codesign 工具是否可用.
|
|
186
|
+
"""
|
|
187
|
+
# 尝试多个可能的路径
|
|
188
|
+
codesign_paths = [
|
|
189
|
+
"/usr/bin/codesign", # 系统默认路径
|
|
190
|
+
"codesign", # PATH 中的路径
|
|
191
|
+
]
|
|
192
|
+
|
|
193
|
+
for codesign_path in codesign_paths:
|
|
194
|
+
try:
|
|
195
|
+
# codesign 不支持 --version,使用 --help 或者直接测试可用性
|
|
196
|
+
result = subprocess.run(
|
|
197
|
+
[codesign_path],
|
|
198
|
+
capture_output=True,
|
|
199
|
+
text=True,
|
|
200
|
+
check=False,
|
|
201
|
+
timeout=10,
|
|
202
|
+
)
|
|
203
|
+
# codesign 无参数调用会返回使用说明,退出码通常是 2,但这说明工具可用
|
|
204
|
+
if result.returncode == 2 and "Usage: codesign" in result.stderr:
|
|
205
|
+
self._print(f" ✅ 找到 codesign: {codesign_path}")
|
|
206
|
+
self.codesign_path = codesign_path # 保存找到的路径
|
|
207
|
+
return True
|
|
208
|
+
else:
|
|
209
|
+
self._print(f" ❌ {codesign_path} 返回错误码: {result.returncode}")
|
|
210
|
+
if result.stderr:
|
|
211
|
+
self._print(f" 错误信息: {result.stderr.strip()}")
|
|
212
|
+
except subprocess.TimeoutExpired:
|
|
213
|
+
self._print(f" ⏱️ {codesign_path} 超时")
|
|
214
|
+
continue
|
|
215
|
+
except FileNotFoundError:
|
|
216
|
+
self._print(f" 📁 {codesign_path} 未找到")
|
|
217
|
+
continue
|
|
218
|
+
except Exception as e:
|
|
219
|
+
self._print(f" ❌ {codesign_path} 异常: {e}")
|
|
220
|
+
continue
|
|
221
|
+
|
|
222
|
+
print(
|
|
223
|
+
" ❌ codesign 工具不可用,请安装 Xcode Command Line Tools: xcode-select --install"
|
|
224
|
+
) # 错误信息始终显示
|
|
225
|
+
return False
|