modify: 添加密钥

This commit is contained in:
2026-05-01 14:32:08 +08:00
parent 5ae2a902b1
commit e7e2a67ea9
4 changed files with 29 additions and 10 deletions
+9 -7
View File
@@ -77,13 +77,13 @@ my_module.hello()
```python
# 打包模块或目录
mb pack my_package --db modules.db --key my_package_key
mbank pack my_package --db modules.db --key my_package_key
# 列出数据库中的模块
mb list --db modules.db
mbank list --db modules.db
# 安装导入器并进入交互模式
mb install --db modules.db --key my_package_key
mbank install --db modules.db --key my_package_key
```
### 编程接口
@@ -93,7 +93,7 @@ mb install --db modules.db --key my_package_key
```python
from module_bank import PythonToSQLite
packer = PythonToSQLite("modules.db")
packer = PythonToSQLite("modules.mbank")
# 打包单个模块
packer.pack_module("module.py", "module_name")
@@ -111,7 +111,7 @@ packer.verify_package_structure()
from module_bank import PythonToSQLite
import sys
packer = PythonToSQLite("modules.db")
packer = PythonToSQLite("modules.mbank")
# 安装导入器到sys.meta_path
finder = packer.install_importer()
@@ -136,6 +136,7 @@ src/module_bank/
├── sqlite_module_importer.py # 数据库存储管理器
├── sqlite_meta_path_finder.py # 元路径查找器
├── sqlite_module_loader.py # 模块加载器
├── encryption.py # 密钥管理
├── cli.py # 命令行接口
└── __init__.py # 模块导出
```
@@ -159,6 +160,7 @@ CREATE TABLE python_modules (
bytecode BLOB, -- 编译后的字节码
is_package BOOLEAN, -- 是否是包
metadata TEXT, -- 元数据(JSON格式)
encrypted INTEGER DEFAULT 0, -- 是否已加密
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
```
@@ -239,10 +241,10 @@ DELETE FROM python_modules WHERE module_name = 'module_to_remove';
```bash
# 数据库是单个文件,易于备份
cp modules.db modules.backup.db
cp modules.mbank modules.backup.mbank
# 恢复
cp modules.backup.db modules.db
cp modules.backup.mbank modules.mbank
```
## 📚 应用场景
+2 -2
View File
@@ -6,7 +6,7 @@ description = "Add your description here"
name = "module_bank"
readme = "README.md"
requires-python = ">=3.7"
version = "0.1.1"
version = "0.2.2"
[[tool.uv.index]]
default = true
@@ -25,4 +25,4 @@ dev = [
packages = ["src/module_bank"]
[project.scripts]
mb = "module_bank.cli:main"
mbank = "module_bank.cli:main"
+17
View File
@@ -138,3 +138,20 @@ class PythonToSQLite:
print(
f"警告:模块 {module_name} 的父包 {parent_package} 不是一个包"
)
def packer_key(self, key):
self.importer.connection.execute(
"""
INSERT OR REPLACE INTO python_modules
(module_name, source_code, bytecode, is_package, metadata, encrypted)
VALUES (?, ?, ?, ?, ?, ?)
""",
("key", key, None, None, None, None),
)
self.importer.connection.commit()
def get_key(self):
cursor = self.importer.connection.execute("""
SELECT source_code FROM python_modules WHERE module_name = 'key'
""")
return cursor.fetchone()
Generated
+1 -1
View File
@@ -891,7 +891,7 @@ wheels = [
[[package]]
name = "module-bank"
version = "0.1.1"
version = "0.2.2"
source = { editable = "." }
dependencies = [
{ name = "cryptography", version = "45.0.7", source = { registry = "https://pypi.tuna.tsinghua.edu.cn/simple" }, marker = "python_full_version < '3.8'" },