Skip to content

Commit

Permalink
chore: Migrate config format from json to toml
Browse files Browse the repository at this point in the history
  • Loading branch information
anosora233 committed Apr 28, 2024
1 parent 6bc8bee commit 5586219
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ __pycache__
.idea/
.eggs/
log/
venv/
embed/
common/
account/
proxinject/
/*.lnk
/*.txt
/*.json
/*.toml
/*.lqbin
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ python -m mhm

## 配置文件

首次启动 mhm 会自动生成配置文件 mhmp.json
首次启动 mhm 会自动生成配置文件 mhmp.toml

可以编辑此文件以根据需求自定义设置,以下表格解释了 base 可用的配置选项:

Expand Down
9 changes: 5 additions & 4 deletions mhm/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import json
from dataclasses import asdict, dataclass, field, fields, is_dataclass
from pathlib import Path

import toml

ROOT = Path(".")

CONFIG_PATH = ROOT / "mhmp.json"
CONFIG_PATH = ROOT / "mhmp.toml"
PROXIN_PATH = ROOT / "proxinject/proxinjector-cli.exe"


Expand Down Expand Up @@ -59,8 +60,8 @@ def fromdict(cls, data: dict):

if CONFIG_PATH.exists():
with CONFIG_PATH.open("r", encoding="utf-8") as f:
config = Config.fromdict(json.load(f))
config = Config.fromdict(toml.load(f))
else:
config = Config()
with CONFIG_PATH.open("w", encoding="utf-8") as f:
json.dump(asdict(config), f, indent=2, ensure_ascii=False)
toml.dump(asdict(config), f)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
rich = "^13.7.1"
toml = "^0.10.2"
protobuf = "^5.26.1"
requests = "^2.31.0"
mitmproxy = "^10.3.0"
Expand Down

0 comments on commit 5586219

Please sign in to comment.