modify: delete_source_code 清除明文代码

This commit is contained in:
chakcy 2026-01-23 16:16:54 +08:00
parent 4bdd50d25c
commit b085931da2
5 changed files with 34 additions and 2 deletions

3
.gitignore vendored
View File

@ -8,4 +8,5 @@ wheels/
# Virtual environments
.venv
.python-version
.python-version
output.md

BIN
lib.mb Normal file

Binary file not shown.

0
log/error.log Normal file
View File

View File

@ -1,4 +1,3 @@
# cli.py
import argparse
from pathlib import Path
@ -17,6 +16,15 @@ def main():
list_parser = subparsers.add_parser("list", help="列出数据库中的模块")
list_parser.add_argument("--db", default="modules.db", help="数据库文件路径")
# 删除原代码
delete_source_parser = subparsers.add_parser(
"delete_source", help="删除数据库中的源代码"
)
delete_source_parser.add_argument(
"--db", default="modules.db", help="数据库文件路径"
)
delete_source_parser.add_argument("--module", help="要删除的模块名")
# 安装命令
install_parser = subparsers.add_parser("install", help="安装SQLite导入器")
install_parser.add_argument("--db", default="modules.db", help="数据库文件路径")
@ -46,6 +54,15 @@ def main():
package_flag = " [包]" if module["is_package"] else ""
print(f" - {module['module_name']}{package_flag}")
elif args.command == "delete_source":
from .python_to_sqlite import PythonToSQLite
packer = PythonToSQLite(args.db)
if args.module:
packer.delete_source_code(args.module)
else:
packer.delete_source_code(None)
elif args.command == "install":
from .python_to_sqlite import PythonToSQLite

View File

@ -93,6 +93,20 @@ class PythonToSQLite:
)
return [dict(row) for row in cursor.fetchall()]
def delete_source_code(self, module_name):
"""删除数据库中的源代码"""
if module_name is None:
cursor = self.importer.connection.execute(
"UPDATE python_modules SET source_code = NULL"
)
else:
cursor = self.importer.connection.execute(
"UPDATE python_modules SET source_code = NULL WHERE module_name = ?",
(module_name,),
)
self.importer.connection.commit()
return cursor.rowcount > 0
def verify_package_structure(self):
"""验证包的完整性"""
cursor = self.importer.connection.execute(