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,95 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
from unifypy.core.plugin import BasePlugin
|
|
8
|
+
from unifypy.core.event_bus import EventBus
|
|
9
|
+
from unifypy.core.events import BUILD_EXECUTABLE
|
|
10
|
+
from unifypy.pyinstaller.config_builder import PyInstallerConfigBuilder
|
|
11
|
+
from unifypy.utils.progress_callback_factory import ProgressCallbackFactory
|
|
12
|
+
from unifypy.utils.info_plist_updater import InfoPlistUpdater
|
|
13
|
+
from unifypy.utils.macos_codesign import MacOSCodeSigner
|
|
14
|
+
from unifypy.platforms.macos.post_processor import MacOSPostProcessor
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class PyInstallerPlugin(BasePlugin):
|
|
18
|
+
name = "pyinstaller"
|
|
19
|
+
priority = 50
|
|
20
|
+
|
|
21
|
+
def register(self, bus: EventBus):
|
|
22
|
+
bus.subscribe(BUILD_EXECUTABLE, self.build_executable, priority=self.priority)
|
|
23
|
+
|
|
24
|
+
def build_executable(self, ctx):
|
|
25
|
+
if getattr(ctx.args, "skip_exe", False):
|
|
26
|
+
return
|
|
27
|
+
|
|
28
|
+
stage = "PyInstaller打包"
|
|
29
|
+
if ctx.progress:
|
|
30
|
+
ctx.progress.start_stage(stage, "使用PyInstaller生成可执行文件")
|
|
31
|
+
|
|
32
|
+
# 进度回调
|
|
33
|
+
cb = ProgressCallbackFactory.create_callback(ctx.progress, verbose=getattr(ctx.args, "verbose", False))
|
|
34
|
+
|
|
35
|
+
# 构建器与 macOS 处理器
|
|
36
|
+
builder = PyInstallerConfigBuilder(current_platform=ctx.config.current_platform, verbose=getattr(ctx.args, "verbose", False), progress_callback=cb)
|
|
37
|
+
info_plist_updater = InfoPlistUpdater(verbose=getattr(ctx.args, "verbose", False))
|
|
38
|
+
mac_codesigner = MacOSCodeSigner(verbose=getattr(ctx.args, "verbose", False))
|
|
39
|
+
mac_processor = MacOSPostProcessor(info_plist_updater, mac_codesigner, builder, verbose=getattr(ctx.args, "verbose", False))
|
|
40
|
+
|
|
41
|
+
# macOS: 预处理 entitlements 并合并 pyinstaller 配置
|
|
42
|
+
if mac_processor.is_macos():
|
|
43
|
+
if ctx.progress:
|
|
44
|
+
ctx.progress.update_stage(stage, 5, "检查 macOS 权限配置")
|
|
45
|
+
updated = mac_processor.prepare_entitlements_config(ctx.config, ctx.project_dir, ctx.args)
|
|
46
|
+
if updated and updated != ctx.config.raw_config:
|
|
47
|
+
if "pyinstaller" in updated:
|
|
48
|
+
if "pyinstaller" not in ctx.config.merged_config:
|
|
49
|
+
ctx.config.merged_config["pyinstaller"] = {}
|
|
50
|
+
ctx.config.merged_config["pyinstaller"].update(updated["pyinstaller"])
|
|
51
|
+
|
|
52
|
+
# 生成命令并执行
|
|
53
|
+
py_cfg = ctx.config.get_pyinstaller_config()
|
|
54
|
+
entry = str((ctx.project_dir / ctx.config.get("entry")).resolve())
|
|
55
|
+
command = builder.build_command(py_cfg, entry)
|
|
56
|
+
|
|
57
|
+
# 在项目根目录执行命令(使用 cwd 参数,避免全局 chdir)
|
|
58
|
+
if ctx.progress:
|
|
59
|
+
ctx.progress.update_stage(stage, 20, "执行 PyInstaller", absolute=True)
|
|
60
|
+
success = ctx.runner.run_command(
|
|
61
|
+
command,
|
|
62
|
+
stage=stage,
|
|
63
|
+
step_description="运行 PyInstaller",
|
|
64
|
+
step_weight=60,
|
|
65
|
+
capture_output=True,
|
|
66
|
+
shell=False,
|
|
67
|
+
cwd=str(ctx.project_dir),
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
if not success:
|
|
71
|
+
raise RuntimeError("PyInstaller打包失败")
|
|
72
|
+
|
|
73
|
+
if ctx.progress:
|
|
74
|
+
ctx.progress.update_stage(stage, 90, "验证输出文件", absolute=True)
|
|
75
|
+
|
|
76
|
+
# 验证输出
|
|
77
|
+
self._verify_output(ctx)
|
|
78
|
+
|
|
79
|
+
# macOS 后处理
|
|
80
|
+
if mac_processor.is_macos():
|
|
81
|
+
app_name = ctx.config.get("name")
|
|
82
|
+
mac_processor.process_built_app(app_name, ctx.dist_dir, ctx.config, ctx.project_dir)
|
|
83
|
+
|
|
84
|
+
if ctx.progress:
|
|
85
|
+
ctx.progress.complete_stage(stage)
|
|
86
|
+
|
|
87
|
+
def _verify_output(self, ctx):
|
|
88
|
+
app_name = ctx.config.get("name")
|
|
89
|
+
onefile = ctx.config.get_pyinstaller_config().get("onefile")
|
|
90
|
+
if onefile:
|
|
91
|
+
exe_path = ctx.dist_dir / f"{app_name}{ctx.file_ops.get_executable_extension()}"
|
|
92
|
+
else:
|
|
93
|
+
exe_path = ctx.dist_dir / app_name / f"{app_name}{ctx.file_ops.get_executable_extension()}"
|
|
94
|
+
if not exe_path.exists():
|
|
95
|
+
raise RuntimeError(f"PyInstaller输出文件不存在: {exe_path}")
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
from unifypy.core.plugin import BasePlugin
|
|
5
|
+
from unifypy.core.event_bus import EventBus
|
|
6
|
+
from unifypy.core.events import HANDLE_ROLLBACK_COMMANDS
|
|
7
|
+
from unifypy.utils.rollback import RollbackManager
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class RollbackPlugin(BasePlugin):
|
|
11
|
+
name = "rollback"
|
|
12
|
+
priority = 15
|
|
13
|
+
|
|
14
|
+
def register(self, bus: EventBus):
|
|
15
|
+
bus.subscribe(HANDLE_ROLLBACK_COMMANDS, self.handle_commands, priority=self.priority)
|
|
16
|
+
|
|
17
|
+
def handle_commands(self, ctx):
|
|
18
|
+
# 列出回滚会话
|
|
19
|
+
if getattr(ctx.args, "list_rollback", False):
|
|
20
|
+
rb = RollbackManager(ctx.project_dir, ctx.progress)
|
|
21
|
+
sessions = rb.list_rollback_sessions()
|
|
22
|
+
if not sessions:
|
|
23
|
+
print("没有可用的回滚会话")
|
|
24
|
+
ctx.exit_code = 0
|
|
25
|
+
ctx.should_exit = True
|
|
26
|
+
return
|
|
27
|
+
print("可用的回滚会话:")
|
|
28
|
+
print("-" * 60)
|
|
29
|
+
for session_id in sessions:
|
|
30
|
+
info = rb.get_session_info(session_id)
|
|
31
|
+
if info:
|
|
32
|
+
import datetime
|
|
33
|
+
start_time = datetime.datetime.fromtimestamp(info["start_time"]) if info.get("start_time") else None
|
|
34
|
+
print(f"会话ID: {session_id}")
|
|
35
|
+
if start_time:
|
|
36
|
+
print(f" 时间: {start_time.strftime('%Y-%m-%d %H:%M:%S')}")
|
|
37
|
+
print(f" 操作数: {info.get('operation_count', 0)}")
|
|
38
|
+
print(f" 回滚命令: python main.py . --rollback {session_id}")
|
|
39
|
+
print()
|
|
40
|
+
ctx.exit_code = 0
|
|
41
|
+
ctx.should_exit = True
|
|
42
|
+
return
|
|
43
|
+
|
|
44
|
+
# 执行回滚
|
|
45
|
+
if getattr(ctx.args, "rollback", None):
|
|
46
|
+
session_id = ctx.args.rollback
|
|
47
|
+
rb = RollbackManager(ctx.project_dir, ctx.progress)
|
|
48
|
+
if not rb.load_operations(session_id):
|
|
49
|
+
print(f"错误: 会话 {session_id} 不存在或无法加载")
|
|
50
|
+
ctx.exit_code = 1
|
|
51
|
+
ctx.should_exit = True
|
|
52
|
+
return
|
|
53
|
+
print(f"正在回滚会话: {session_id}")
|
|
54
|
+
success = rb.rollback()
|
|
55
|
+
if success:
|
|
56
|
+
print("✅ 回滚成功完成")
|
|
57
|
+
rb.cleanup()
|
|
58
|
+
ctx.exit_code = 0
|
|
59
|
+
else:
|
|
60
|
+
print("❌ 回滚过程中发生错误")
|
|
61
|
+
ctx.exit_code = 1
|
|
62
|
+
ctx.should_exit = True
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
from unifypy.core.plugin import BasePlugin
|
|
5
|
+
from unifypy.core.event_bus import EventBus
|
|
6
|
+
from unifypy.core.events import ON_SUCCESS
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SummaryPlugin(BasePlugin):
|
|
10
|
+
name = "summary"
|
|
11
|
+
priority = 90
|
|
12
|
+
|
|
13
|
+
def register(self, bus: EventBus):
|
|
14
|
+
bus.subscribe(ON_SUCCESS, self.on_success, priority=self.priority)
|
|
15
|
+
|
|
16
|
+
def on_success(self, ctx):
|
|
17
|
+
output_info = {}
|
|
18
|
+
app_name = ctx.config.get("name")
|
|
19
|
+
|
|
20
|
+
# 可执行文件
|
|
21
|
+
if not getattr(ctx.args, "skip_exe", False):
|
|
22
|
+
if ctx.config.get_pyinstaller_config().get("onefile"):
|
|
23
|
+
exe_path = ctx.dist_dir / f"{app_name}{ctx.file_ops.get_executable_extension()}"
|
|
24
|
+
else:
|
|
25
|
+
exe_path = ctx.dist_dir / app_name
|
|
26
|
+
if exe_path.exists():
|
|
27
|
+
output_info["可执行文件"] = str(exe_path)
|
|
28
|
+
|
|
29
|
+
# 安装包
|
|
30
|
+
if not getattr(ctx.args, "skip_installer", False) and ctx.installer_dir.exists():
|
|
31
|
+
installer_files = [str(p) for p in ctx.installer_dir.iterdir() if p.is_file()]
|
|
32
|
+
if installer_files:
|
|
33
|
+
output_info["安装包"] = installer_files[0] if len(installer_files) == 1 else installer_files
|
|
34
|
+
|
|
35
|
+
if ctx.progress:
|
|
36
|
+
ctx.progress.show_success(output_info)
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from unifypy.core.plugin import BasePlugin
|
|
8
|
+
from unifypy.core.event_bus import EventBus
|
|
9
|
+
from unifypy.core.events import ENVIRONMENT_CHECK
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class WindowsLanguagePlugin(BasePlugin):
|
|
13
|
+
name = "windows_language"
|
|
14
|
+
# 在 environment(30) 之后、prepare(40) 之前
|
|
15
|
+
priority = 32
|
|
16
|
+
|
|
17
|
+
def register(self, bus: EventBus):
|
|
18
|
+
bus.subscribe(ENVIRONMENT_CHECK, self.ensure_chinese_language, priority=self.priority)
|
|
19
|
+
|
|
20
|
+
def ensure_chinese_language(self, ctx):
|
|
21
|
+
try:
|
|
22
|
+
# 仅在 Windows 平台且未跳过安装器时处理
|
|
23
|
+
if ctx.config.current_platform != "windows" or getattr(ctx.args, "skip_installer", False):
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
# 检查是否启用中文语言
|
|
27
|
+
win_cfg = ctx.config.get("platforms", {}).get("windows", {}) or {}
|
|
28
|
+
inno_cfg = win_cfg.get("inno_setup", {}) or {}
|
|
29
|
+
langs = inno_cfg.get("languages", []) or []
|
|
30
|
+
enable_cn = any(l in ["chinesesimplified", "chinese"] for l in langs)
|
|
31
|
+
if not enable_cn:
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
# 延迟导入避免循环
|
|
35
|
+
from unifypy.platforms.windows.inno_setup import InnoSetupPackager
|
|
36
|
+
|
|
37
|
+
# 构建临时 packager 用于复用其检测与生成逻辑
|
|
38
|
+
packager = InnoSetupPackager(
|
|
39
|
+
ctx.progress,
|
|
40
|
+
ctx.runner,
|
|
41
|
+
ctx.tool_manager,
|
|
42
|
+
ctx.config.merged_config,
|
|
43
|
+
getattr(ctx.config, "config_path", None) or "build.json",
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# 定位 Inno Setup 编译器并推导 Languages 目录
|
|
47
|
+
iscc = packager._find_inno_setup_compiler()
|
|
48
|
+
if not iscc:
|
|
49
|
+
# 工具不可用时不报错,只提示(环境插件已做校验)
|
|
50
|
+
if ctx.progress:
|
|
51
|
+
ctx.progress.warning("未找到 Inno Setup,跳过中文语言文件准备")
|
|
52
|
+
return
|
|
53
|
+
|
|
54
|
+
lang_dir = os.path.join(os.path.dirname(iscc), "Languages")
|
|
55
|
+
os.makedirs(lang_dir, exist_ok=True)
|
|
56
|
+
target = os.path.join(lang_dir, "ChineseSimplified.isl")
|
|
57
|
+
|
|
58
|
+
# 若项目自带中文语言文件,则复制到 Languages 目录(确保缓存 ISS 可用)
|
|
59
|
+
proj_cn = getattr(packager, "_project_chinese_file", None)
|
|
60
|
+
if proj_cn and os.path.exists(proj_cn):
|
|
61
|
+
try:
|
|
62
|
+
if not os.path.exists(target):
|
|
63
|
+
from shutil import copy2
|
|
64
|
+
copy2(proj_cn, target)
|
|
65
|
+
if ctx.progress:
|
|
66
|
+
ctx.progress.info(f"✅ 已复制项目中文语言文件到: {target}")
|
|
67
|
+
else:
|
|
68
|
+
if ctx.progress:
|
|
69
|
+
ctx.progress.info("🔁 语言文件已存在,跳过复制")
|
|
70
|
+
return
|
|
71
|
+
except Exception as e:
|
|
72
|
+
if ctx.progress:
|
|
73
|
+
ctx.progress.warning(f"复制中文语言文件失败: {e}")
|
|
74
|
+
|
|
75
|
+
# 否则:确保 Languages 目录内存在中文语言文件(模板优先)
|
|
76
|
+
if not os.path.exists(target):
|
|
77
|
+
ok = packager._create_basic_chinese_language_file(target)
|
|
78
|
+
if ok and ctx.progress:
|
|
79
|
+
ctx.progress.info(f"✅ 已准备中文语言文件: {target}")
|
|
80
|
+
elif not ok and ctx.progress:
|
|
81
|
+
ctx.progress.warning("⚠️ 无法准备中文语言文件,将仅支持英文界面")
|
|
82
|
+
|
|
83
|
+
except Exception as e:
|
|
84
|
+
if ctx.progress:
|
|
85
|
+
ctx.progress.warning(f"Windows 中文语言预设失败: {e}")
|