diff --git a/.gitignore b/.gitignore index 1b0f857..61fe22e 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ wheels/ # Virtual environments .venv -.python-version \ No newline at end of file +.python-version +output.md \ No newline at end of file diff --git a/lib.mb b/lib.mb new file mode 100644 index 0000000..a5d2dce Binary files /dev/null and b/lib.mb differ diff --git a/log/error.log b/log/error.log new file mode 100644 index 0000000..e69de29 diff --git a/src/module_bank/cli.py b/src/module_bank/cli.py index fe87e08..2b5d59a 100644 --- a/src/module_bank/cli.py +++ b/src/module_bank/cli.py @@ -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 diff --git a/src/module_bank/python_to_sqlite.py b/src/module_bank/python_to_sqlite.py index 6d5c09d..d6f98ba 100644 --- a/src/module_bank/python_to_sqlite.py +++ b/src/module_bank/python_to_sqlite.py @@ -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(