混淆失败则跳过混淆

This commit is contained in:
2026-09-01 10:08:11 +08:00
parent f645c9df65
commit feb1593aba
3 changed files with 33 additions and 13 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ requires = ["hatchling"]
[project] [project]
name = "chongming-cli" name = "chongming-cli"
version = "0.2.4" version = "0.3.0"
description = "chongming 命令脚本集合:构建打包 / 进程插件打包 / 插件脚手架 / 模型生成" description = "chongming 命令脚本集合:构建打包 / 进程插件打包 / 插件脚手架 / 模型生成"
readme = "README.md" readme = "README.md"
requires-python = ">=3.12" requires-python = ">=3.12"
+31 -12
View File
@@ -209,6 +209,23 @@ def _parse_args() -> tuple[str, set[str]]:
# ── 阶段 1: 模块打包 (module-bank) ────────────────────────────────────────── # ── 阶段 1: 模块打包 (module-bank) ──────────────────────────────────────────
def _pack_mbank(output_path: str, source_dir: str, package_name: str, obfuscate: bool) -> str:
"""打包单个 mbank 目标,返回文件大小描述"""
key = Encryption.generate_key()
packer = PythonToSQLite(output_path, key, pyarmor_obfuscate=obfuscate)
packer.pack_directory(source_dir, package_name)
packer.verify_package_structure()
packer.packer_key(key)
packer.delete_source_code(None)
return _format_size(output_path)
def _is_pyarmor_license_error(exc: Exception) -> bool:
"""判断异常是否为 PyArmor 试用版授权额度不足所致"""
msg = str(exc).lower()
return "out of license" in msg or "license" in msg
def _stage_pack_modules(config: Config) -> str: def _stage_pack_modules(config: Config) -> str:
""" """
使用 module-bank 加密打包 Python 模块为 .mbank 文件。 使用 module-bank 加密打包 Python 模块为 .mbank 文件。
@@ -221,18 +238,20 @@ def _stage_pack_modules(config: Config) -> str:
messages = [] messages = []
for output_path, source_dir, package_name in mbank_list: for output_path, source_dir, package_name in mbank_list:
key = Encryption.generate_key() try:
packer = PythonToSQLite( size = _pack_mbank(output_path, source_dir, package_name, obfuscate=True)
output_path, messages.append(f"{Path(output_path).name} ({size})")
key, except Exception as e:
pyarmor_obfuscate=True, if not _is_pyarmor_license_error(e):
) raise
packer.pack_directory(source_dir, package_name) # PyArmor 试用版授权额度耗尽(out of license) → 降级为不混淆重打包
packer.verify_package_structure() Path(output_path).unlink(missing_ok=True)
packer.packer_key(key) size = _pack_mbank(output_path, source_dir, package_name, obfuscate=False)
packer.delete_source_code(None) print(
size = _format_size(output_path) f" ⚠️ {Path(output_path).name}: PyArmor 授权不足(out of license),"
messages.append(f"{Path(output_path).name} ({size})") f"降级为无混淆打包"
)
messages.append(f"{Path(output_path).name} ({size}, 无 PyArmor 混淆)")
return " - " + "\n - ".join(messages) return " - " + "\n - ".join(messages)
+1
View File
@@ -14,6 +14,7 @@ def generate_markdown_from_py_files(directory, output_file):
dirs[:] = [d for d in dirs if d != "build"] dirs[:] = [d for d in dirs if d != "build"]
dirs[:] = [d for d in dirs if d != "dist"] dirs[:] = [d for d in dirs if d != "dist"]
dirs[:] = [d for d in dirs if d != "chongming-web"] dirs[:] = [d for d in dirs if d != "chongming-web"]
dirs[:] = [d for d in dirs if d != "workers"]
for file in files: for file in files:
if ( if (
file.endswith(".py") file.endswith(".py")