From 5586219a7d7ab6f09ec4eff125a2606fc78486df Mon Sep 17 00:00:00 2001 From: anosora233 <86921203+anosora233@users.noreply.github.com> Date: Sun, 28 Apr 2024 20:28:25 +0800 Subject: [PATCH] chore: Migrate config format from json to toml --- .gitignore | 2 ++ README.md | 2 +- mhm/config.py | 9 +++++---- pyproject.toml | 1 + 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 2c599bf..4d383f8 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ __pycache__ .idea/ .eggs/ log/ +venv/ embed/ common/ account/ @@ -24,4 +25,5 @@ proxinject/ /*.lnk /*.txt /*.json +/*.toml /*.lqbin diff --git a/README.md b/README.md index 80683f1..23d0a9e 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ python -m mhm ## 配置文件 -首次启动 mhm 会自动生成配置文件 mhmp.json +首次启动 mhm 会自动生成配置文件 mhmp.toml 可以编辑此文件以根据需求自定义设置,以下表格解释了 base 可用的配置选项: diff --git a/mhm/config.py b/mhm/config.py index e5fb5da..7457c1a 100644 --- a/mhm/config.py +++ b/mhm/config.py @@ -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" @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 72987bc..601094b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"