modify: delete_source_code 清除明文代码
This commit is contained in:
parent
4bdd50d25c
commit
b085931da2
3
.gitignore
vendored
3
.gitignore
vendored
@ -8,4 +8,5 @@ wheels/
|
||||
|
||||
# Virtual environments
|
||||
.venv
|
||||
.python-version
|
||||
.python-version
|
||||
output.md
|
||||
0
log/error.log
Normal file
0
log/error.log
Normal 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
|
||||
|
||||
|
||||
@ -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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user