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.
Files changed (78) hide show
  1. unifypy/__init__.py +7 -0
  2. unifypy/__main__.py +21 -0
  3. unifypy/cli/__init__.py +10 -0
  4. unifypy/cli/argument_parser.py +209 -0
  5. unifypy/core/__init__.py +8 -0
  6. unifypy/core/config.py +491 -0
  7. unifypy/core/context.py +36 -0
  8. unifypy/core/engine.py +93 -0
  9. unifypy/core/environment.py +509 -0
  10. unifypy/core/event_bus.py +37 -0
  11. unifypy/core/events.py +16 -0
  12. unifypy/core/platforms.py +58 -0
  13. unifypy/core/plugin.py +65 -0
  14. unifypy/core/validators/__init__.py +10 -0
  15. unifypy/core/validators/tool_validator.py +144 -0
  16. unifypy/platforms/__init__.py +10 -0
  17. unifypy/platforms/base.py +127 -0
  18. unifypy/platforms/linux/__init__.py +10 -0
  19. unifypy/platforms/linux/deb_packager.py +289 -0
  20. unifypy/platforms/linux/rpm_packager.py +332 -0
  21. unifypy/platforms/macos/__init__.py +10 -0
  22. unifypy/platforms/macos/dmg_packager.py +477 -0
  23. unifypy/platforms/macos/post_processor.py +272 -0
  24. unifypy/platforms/registry.py +108 -0
  25. unifypy/platforms/windows/__init__.py +9 -0
  26. unifypy/platforms/windows/inno_setup.py +715 -0
  27. unifypy/plugins/__init__.py +3 -0
  28. unifypy/plugins/auto_rollback_plugin.py +156 -0
  29. unifypy/plugins/cleanup_plugin.py +22 -0
  30. unifypy/plugins/config_plugin.py +42 -0
  31. unifypy/plugins/dry_run_plugin.py +22 -0
  32. unifypy/plugins/environment_plugin.py +61 -0
  33. unifypy/plugins/external_plugins_loader.py +42 -0
  34. unifypy/plugins/packaging_plugin.py +125 -0
  35. unifypy/plugins/prepare_plugin.py +89 -0
  36. unifypy/plugins/progress_plugin.py +32 -0
  37. unifypy/plugins/pyinstaller_plugin.py +95 -0
  38. unifypy/plugins/rollback_plugin.py +62 -0
  39. unifypy/plugins/summary_plugin.py +36 -0
  40. unifypy/plugins/windows_language_plugin.py +85 -0
  41. unifypy/pyinstaller/__init__.py +7 -0
  42. unifypy/pyinstaller/config_builder.py +908 -0
  43. unifypy/templates/ChineseSimplified.isl.template +403 -0
  44. unifypy/templates/setup.iss.template +51 -0
  45. unifypy/tools/create-dmg/.this-is-the-create-dmg-repo +3 -0
  46. unifypy/tools/create-dmg/LICENSE +22 -0
  47. unifypy/tools/create-dmg/Makefile +33 -0
  48. unifypy/tools/create-dmg/README.md +126 -0
  49. unifypy/tools/create-dmg/builder/create-dmg.builder +26 -0
  50. unifypy/tools/create-dmg/create-dmg +621 -0
  51. unifypy/tools/create-dmg/doc-project/Developer Notes.md +35 -0
  52. unifypy/tools/create-dmg/doc-project/Release Checklist.md +10 -0
  53. unifypy/tools/create-dmg/examples/01-main-example/installer_background.png +0 -0
  54. unifypy/tools/create-dmg/examples/01-main-example/sample +30 -0
  55. unifypy/tools/create-dmg/examples/01-main-example/source_folder/Application.app +0 -0
  56. unifypy/tools/create-dmg/support/eula-resources-template.xml +105 -0
  57. unifypy/tools/create-dmg/support/template.applescript +74 -0
  58. unifypy/tools/create-dmg/tests/007-space-in-dir-name/my files/hello.txt +1 -0
  59. unifypy/tools/create-dmg/tests/007-space-in-dir-name/run-test +5 -0
  60. unifypy/utils/__init__.py +10 -0
  61. unifypy/utils/cache_manager.py +957 -0
  62. unifypy/utils/command_runner.py +195 -0
  63. unifypy/utils/entitlements_generator.py +450 -0
  64. unifypy/utils/file_ops.py +333 -0
  65. unifypy/utils/icon_converter.py +144 -0
  66. unifypy/utils/info_plist_updater.py +247 -0
  67. unifypy/utils/macos_codesign.py +225 -0
  68. unifypy/utils/parallel_builder.py +355 -0
  69. unifypy/utils/progress.py +371 -0
  70. unifypy/utils/progress_callback_factory.py +56 -0
  71. unifypy/utils/rollback.py +484 -0
  72. unifypy/utils/tool_manager.py +701 -0
  73. unifypy-2.0.2.dist-info/METADATA +609 -0
  74. unifypy-2.0.2.dist-info/RECORD +78 -0
  75. unifypy-2.0.2.dist-info/WHEEL +5 -0
  76. unifypy-2.0.2.dist-info/entry_points.txt +2 -0
  77. unifypy-2.0.2.dist-info/licenses/LICENSE +21 -0
  78. unifypy-2.0.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,332 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ Linux RPM 打包器 创建RedHat/CentOS/Fedora格式的安装包.
5
+ """
6
+
7
+ import os
8
+ import shutil
9
+ import tempfile
10
+ from pathlib import Path
11
+ from typing import Any, Dict, List
12
+
13
+ from ..base import BasePackager
14
+
15
+
16
+ class RPMPackager(BasePackager):
17
+ """
18
+ RPM 打包器.
19
+ """
20
+
21
+ def get_supported_formats(self) -> List[str]:
22
+ """
23
+ 获取支持的打包格式.
24
+ """
25
+ return ["rpm"]
26
+
27
+ def can_package_format(self, format_type: str) -> bool:
28
+ """
29
+ 检查是否支持指定格式.
30
+ """
31
+ return format_type in self.get_supported_formats()
32
+
33
+ def package(self, format_type: str, source_path: Path, output_path: Path) -> bool:
34
+ """执行RPM打包.
35
+
36
+ Args:
37
+ format_type: 打包格式 (rpm)
38
+ source_path: PyInstaller生成的应用路径
39
+ output_path: 输出RPM文件路径
40
+
41
+ Returns:
42
+ bool: 打包是否成功
43
+ """
44
+ if not self.can_package_format(format_type):
45
+ self.progress.on_error(
46
+ Exception(f"不支持的格式: {format_type}"), "Linux RPM打包"
47
+ )
48
+ return False
49
+
50
+ # 获取RPM配置
51
+ rpm_config = self.get_format_config("rpm")
52
+
53
+ # 创建临时构建目录
54
+ with tempfile.TemporaryDirectory() as temp_dir:
55
+ build_root = Path(temp_dir)
56
+
57
+ # 创建RPM构建目录结构
58
+ rpmbuild_dir = build_root / "rpmbuild"
59
+ for subdir in ["BUILD", "RPMS", "SOURCES", "SPECS", "SRPMS"]:
60
+ (rpmbuild_dir / subdir).mkdir(parents=True)
61
+
62
+ # 准备源文件
63
+ sources_dir = rpmbuild_dir / "SOURCES"
64
+ self._prepare_sources(source_path, sources_dir, rpm_config)
65
+
66
+ # 创建spec文件
67
+ spec_file = (
68
+ rpmbuild_dir / "SPECS" / f"{self.config.get('name', 'myapp')}.spec"
69
+ )
70
+ self._create_spec_file(spec_file, rpm_config, sources_dir)
71
+
72
+ # 构建RPM包
73
+ success = self._build_rpm_package(rpmbuild_dir, spec_file, output_path)
74
+
75
+ return success
76
+
77
+ def _prepare_sources(
78
+ self, source_path: Path, sources_dir: Path, config: Dict[str, Any]
79
+ ):
80
+ """
81
+ 准备源文件.
82
+ """
83
+ app_name = self.config.get("name", "myapp")
84
+ version = self.config.get("version", "1.0.0")
85
+
86
+ # 创建源码目录
87
+ source_tarball = sources_dir / f"{app_name}-{version}.tar.gz"
88
+
89
+ # 创建临时目录用于打包
90
+ with tempfile.TemporaryDirectory() as temp_source_dir:
91
+ app_source_dir = Path(temp_source_dir) / f"{app_name}-{version}"
92
+ app_source_dir.mkdir()
93
+
94
+ if source_path.is_file():
95
+ # 单个可执行文件
96
+ shutil.copy2(source_path, app_source_dir / app_name)
97
+ else:
98
+ # 目录 - 复制所有内容
99
+ for item in source_path.iterdir():
100
+ if item.is_file():
101
+ shutil.copy2(item, app_source_dir)
102
+ else:
103
+ shutil.copytree(item, app_source_dir / item.name)
104
+
105
+ # 创建tar.gz文件
106
+ import tarfile
107
+
108
+ with tarfile.open(source_tarball, "w:gz") as tar:
109
+ tar.add(app_source_dir, arcname=f"{app_name}-{version}")
110
+
111
+ # 复制其他源文件
112
+ extra_sources = config.get("extra_sources", [])
113
+ for extra_source in extra_sources:
114
+ if os.path.exists(extra_source):
115
+ shutil.copy2(extra_source, sources_dir)
116
+
117
+ def _create_spec_file(
118
+ self, spec_file: Path, config: Dict[str, Any], sources_dir: Path
119
+ ):
120
+ """
121
+ 创建RPM spec文件.
122
+ """
123
+ app_name = self.config.get("name", "myapp")
124
+ version = self.config.get("version", "1.0.0")
125
+ release = config.get("release", "1")
126
+
127
+ # 使用环境管理器获取标准化的架构信息
128
+ arch = self.env_manager.get_arch_for_format("rpm")
129
+
130
+ spec_content = f"""Name: {app_name}
131
+ Version: {version}
132
+ Release: {release}%{{?dist}}
133
+ Summary: {config.get('summary', self.config.get('display_name', app_name))}
134
+
135
+ License: {config.get('license', 'Unknown')}
136
+ URL: {config.get('url', '')}
137
+ Source0: %{{name}}-%{{version}}.tar.gz
138
+
139
+ BuildArch: {arch}
140
+ """
141
+
142
+ # 添加依赖
143
+ requires = config.get("requires", [])
144
+ if requires:
145
+ for req in requires:
146
+ spec_content += f"Requires: {req}\n"
147
+
148
+ build_requires = config.get("build_requires", [])
149
+ if build_requires:
150
+ for req in build_requires:
151
+ spec_content += f"BuildRequires: {req}\n"
152
+
153
+ # 描述部分
154
+ spec_content += f"""
155
+ %description
156
+ {config.get('description', self.config.get('display_name', app_name))}
157
+
158
+ %prep
159
+ %setup -q
160
+
161
+ %build
162
+ # 不需要编译步骤,因为我们使用的是预编译的二进制文件
163
+
164
+ %install
165
+ rm -rf $RPM_BUILD_ROOT
166
+ mkdir -p $RPM_BUILD_ROOT/opt/{app_name}
167
+ mkdir -p $RPM_BUILD_ROOT/usr/local/bin
168
+ """
169
+
170
+ # 安装文件
171
+ spec_content += f"""
172
+ # 复制应用文件
173
+ cp -r * $RPM_BUILD_ROOT/opt/{app_name}/
174
+
175
+ # 创建启动脚本
176
+ cat > $RPM_BUILD_ROOT/usr/local/bin/{app_name} << 'EOF'
177
+ #!/bin/bash
178
+ cd /opt/{app_name}
179
+ exec ./{app_name} "$@"
180
+ EOF
181
+ chmod +x $RPM_BUILD_ROOT/usr/local/bin/{app_name}
182
+ """
183
+
184
+ # 桌面文件
185
+ if config.get("create_desktop_file", True):
186
+ spec_content += f"""
187
+ # 创建桌面文件
188
+ mkdir -p $RPM_BUILD_ROOT/usr/share/applications
189
+ cat > $RPM_BUILD_ROOT/usr/share/applications/{app_name}.desktop << 'EOF'
190
+ [Desktop Entry]
191
+ Type=Application
192
+ Name={self.config.get('display_name', app_name)}
193
+ Exec={app_name}
194
+ Icon={app_name}
195
+ Comment={config.get('description', self.config.get('display_name', app_name))}
196
+ Categories={config.get('categories', 'Utility;')}
197
+ Terminal={str(config.get('terminal', False)).lower()}
198
+ EOF
199
+ """
200
+
201
+ # 图标文件
202
+ icon_path = config.get("icon") or self.config.get("icon")
203
+ if icon_path and os.path.exists(icon_path):
204
+ icon_ext = Path(icon_path).suffix
205
+ spec_content += f"""
206
+ # 复制图标文件
207
+ mkdir -p $RPM_BUILD_ROOT/usr/share/pixmaps
208
+ cp {sources_dir / Path(icon_path).name} $RPM_BUILD_ROOT/usr/share/pixmaps/{app_name}{icon_ext}
209
+ """
210
+
211
+ # 文件列表
212
+ spec_content += f"""
213
+ %files
214
+ %defattr(-,root,root,-)
215
+ /opt/{app_name}/*
216
+ /usr/local/bin/{app_name}
217
+ """
218
+
219
+ if config.get("create_desktop_file", True):
220
+ spec_content += f"/usr/share/applications/{app_name}.desktop\n"
221
+
222
+ if icon_path and os.path.exists(icon_path):
223
+ icon_ext = Path(icon_path).suffix
224
+ spec_content += f"/usr/share/pixmaps/{app_name}{icon_ext}\n"
225
+
226
+ # 脚本部分
227
+ scripts = ["pre", "post", "preun", "postun"]
228
+ for script in scripts:
229
+ script_content = config.get(f"{script}_script")
230
+ if script_content:
231
+ spec_content += f"""
232
+ %{script}
233
+ {script_content}
234
+ """
235
+
236
+ # 变更日志
237
+ spec_content += f"""
238
+ %changelog
239
+ * {self._get_current_date()} {config.get('packager', 'Unknown <unknown@example.com>')} - {version}-{release}
240
+ - Initial package
241
+ """
242
+
243
+ # 写入spec文件
244
+ with open(spec_file, "w") as f:
245
+ f.write(spec_content)
246
+
247
+ def _get_current_date(self) -> str:
248
+ """
249
+ 获取当前日期(RPM格式)
250
+ """
251
+ import datetime
252
+ import locale
253
+
254
+ try:
255
+ # 设置为英文locale以确保日期格式正确
256
+ locale.setlocale(locale.LC_TIME, "C")
257
+ except:
258
+ pass
259
+
260
+ return datetime.datetime.now().strftime("%a %b %d %Y")
261
+
262
+ def _build_rpm_package(
263
+ self, rpmbuild_dir: Path, spec_file: Path, output_path: Path
264
+ ) -> bool:
265
+ """
266
+ 构建RPM包.
267
+ """
268
+ # 设置环境变量
269
+ env = os.environ.copy()
270
+ env["HOME"] = str(rpmbuild_dir.parent)
271
+
272
+ # 构建命令
273
+ command = [
274
+ "rpmbuild",
275
+ "--define",
276
+ f"_topdir {rpmbuild_dir}",
277
+ "-bb",
278
+ str(spec_file),
279
+ ]
280
+
281
+ success = self.runner.run_command(
282
+ command, "Linux RPM打包", "正在构建RPM包...", 80, shell=False
283
+ )
284
+
285
+ if success:
286
+ # 查找生成的RPM文件
287
+ rpms_dir = rpmbuild_dir / "RPMS"
288
+ rpm_files = list(rpms_dir.rglob("*.rpm"))
289
+
290
+ if rpm_files:
291
+ # 复制到输出位置
292
+ shutil.copy2(rpm_files[0], output_path)
293
+ return True
294
+ else:
295
+ self.progress.on_error(
296
+ Exception("未找到生成的RPM文件"), "Linux RPM打包"
297
+ )
298
+ return False
299
+ else:
300
+ return False
301
+
302
+ def validate_config(self, format_type: str) -> List[str]:
303
+ """
304
+ 验证RPM配置.
305
+ """
306
+ errors = []
307
+
308
+ config = self.get_format_config("rpm")
309
+
310
+ # 检查必需字段
311
+ required_fields = ["summary", "license"]
312
+ for field in required_fields:
313
+ if not config.get(field):
314
+ errors.append(f"RPM配置缺少必需字段: {field}")
315
+
316
+ # 检查图标文件
317
+ icon_path = config.get("icon") or self.config.get("icon")
318
+ if icon_path and not os.path.exists(icon_path):
319
+ errors.append(f"图标文件不存在: {icon_path}")
320
+
321
+ # 检查rpmbuild工具
322
+ try:
323
+ import shutil
324
+
325
+ if not shutil.which("rpmbuild"):
326
+ errors.append(
327
+ "rpmbuild工具未安装,请安装: sudo yum install rpm-build 或 sudo dnf install rpm-build"
328
+ )
329
+ except:
330
+ errors.append("无法检查rpmbuild工具")
331
+
332
+ return errors
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ macOS平台打包器.
5
+ """
6
+
7
+ from .dmg_packager import DMGPackager
8
+ from .post_processor import MacOSPostProcessor
9
+
10
+ __all__ = ["DMGPackager", "MacOSPostProcessor"]