MCPcopy
hub / github.com/DeppWang/youdaonote-pull / _covert_config

Method _covert_config

pull.py:56–85  ·  view source on GitHub ↗

转换配置文件为 dict :param config_path: config 文件路径 :return: (config_dict, error_msg)

(self, config_path=None)

Source from the content-addressed store, hash-verified

54 self.is_relative_path = None # 是否使用相对路径
55
56 def _covert_config(self, config_path=None) -> Tuple[dict, str]:
57 """
58 转换配置文件为 dict
59 :param config_path: config 文件路径
60 :return: (config_dict, error_msg)
61 """
62
63 config_path = (
64 config_path
65 if config_path
66 else os.path.join(get_script_directory(), "config.json")
67 )
68 with open(config_path, "rb") as f:
69 config_str = f.read().decode("utf-8")
70
71 try:
72 config_dict = json.loads(config_str)
73 except:
74 return (
75 {},
76 "请检查「config.json」格式是否为 utf-8 格式的 json!建议使用 Sublime 编辑「config.json」",
77 )
78
79 key_list = ["local_dir", "ydnote_dir", "smms_secret_token", "is_relative_path"]
80 if key_list != list(config_dict.keys()):
81 return (
82 {},
83 "请检查「config.json」的 key 是否分别为 local_dir, ydnote_dir, smms_secret_token, is_relative_path",
84 )
85 return config_dict, ""
86
87 def _check_local_dir(self, local_dir, test_default_dir=None) -> Tuple[str, str]:
88 """

Callers 2

get_ydnote_dir_idMethod · 0.95

Calls 1

get_script_directoryFunction · 0.90

Tested by 1