混淆失败则跳过混淆
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ requires = ["hatchling"]
|
||||
|
||||
[project]
|
||||
name = "chongming-cli"
|
||||
version = "0.2.4"
|
||||
version = "0.3.0"
|
||||
description = "chongming 命令脚本集合:构建打包 / 进程插件打包 / 插件脚手架 / 模型生成"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
|
||||
+30
-11
@@ -209,6 +209,23 @@ def _parse_args() -> tuple[str, set[str]]:
|
||||
# ── 阶段 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:
|
||||
"""
|
||||
使用 module-bank 加密打包 Python 模块为 .mbank 文件。
|
||||
@@ -221,18 +238,20 @@ def _stage_pack_modules(config: Config) -> str:
|
||||
|
||||
messages = []
|
||||
for output_path, source_dir, package_name in mbank_list:
|
||||
key = Encryption.generate_key()
|
||||
packer = PythonToSQLite(
|
||||
output_path,
|
||||
key,
|
||||
pyarmor_obfuscate=True,
|
||||
)
|
||||
packer.pack_directory(source_dir, package_name)
|
||||
packer.verify_package_structure()
|
||||
packer.packer_key(key)
|
||||
packer.delete_source_code(None)
|
||||
size = _format_size(output_path)
|
||||
try:
|
||||
size = _pack_mbank(output_path, source_dir, package_name, obfuscate=True)
|
||||
messages.append(f"{Path(output_path).name} ({size})")
|
||||
except Exception as e:
|
||||
if not _is_pyarmor_license_error(e):
|
||||
raise
|
||||
# PyArmor 试用版授权额度耗尽(out of license) → 降级为不混淆重打包
|
||||
Path(output_path).unlink(missing_ok=True)
|
||||
size = _pack_mbank(output_path, source_dir, package_name, obfuscate=False)
|
||||
print(
|
||||
f" ⚠️ {Path(output_path).name}: PyArmor 授权不足(out of license),"
|
||||
f"降级为无混淆打包"
|
||||
)
|
||||
messages.append(f"{Path(output_path).name} ({size}, 无 PyArmor 混淆)")
|
||||
return " - " + "\n - ".join(messages)
|
||||
|
||||
|
||||
|
||||
@@ -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 != "dist"]
|
||||
dirs[:] = [d for d in dirs if d != "chongming-web"]
|
||||
dirs[:] = [d for d in dirs if d != "workers"]
|
||||
for file in files:
|
||||
if (
|
||||
file.endswith(".py")
|
||||
|
||||
Reference in New Issue
Block a user