From 265b23b36d6388e6b9be1759419147452f158c76 Mon Sep 17 00:00:00 2001 From: g1879 Date: Fri, 7 Jan 2022 13:15:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E4=B8=8D=E6=96=B0=E5=BB=BAtmp=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=EF=BC=8C=E4=BF=9D=E5=AD=98=E6=97=B6=E6=98=BE=E7=A4=BA=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=AD=E5=8F=A5=E3=80=82save()=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/config.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/DrissionPage/config.py b/DrissionPage/config.py index 33d6cfc..7864d09 100644 --- a/DrissionPage/config.py +++ b/DrissionPage/config.py @@ -32,11 +32,11 @@ class OptionsManager(object): self._chrome_options = None self._session_options = None - if 'tmp_path' not in self.paths or not self.get_value('paths', 'tmp_path'): - tmp_path = str((Path(__file__).parent / 'tmp').absolute()) - Path(tmp_path).mkdir(parents=True, exist_ok=True) - self.set_item('paths', 'tmp_path', tmp_path) - self.save(self.ini_path) + # if 'tmp_path' not in self.paths or not self.get_value('paths', 'tmp_path'): + # tmp_path = str((Path(__file__).parent / 'tmp').absolute()) + # Path(tmp_path).mkdir(parents=True, exist_ok=True) + # self.set_item('paths', 'tmp_path', tmp_path) + # self.save(self.ini_path) def __text__(self) -> str: """打印ini文件内容""" @@ -111,13 +111,14 @@ class OptionsManager(object): self.__setattr__(f'_{section}', None) return self - def save(self, path: str = None): + def save(self, path: str = None) -> str: """保存配置文件 \n :param path: ini文件的路径,传入 'default' 保存到默认ini文件 - :return: 当前对象 + :return: 保存路径 """ + default_path = (Path(__file__).parent / 'configs.ini').absolute() if path == 'default': - path = (Path(__file__).parent / 'configs.ini').absolute() + path = default_path elif path is None: path = Path(self.ini_path).absolute() else: @@ -125,9 +126,14 @@ class OptionsManager(object): path = path / 'config.ini' if path.is_dir() else path - self._conf.write(open(str(path), 'w', encoding='utf-8')) + path = str(path) + self._conf.write(open(path, 'w', encoding='utf-8')) - return self + print(f'配置已保存到文件:{path}') + if path == str(default_path): + print('以后程序可自动从文件加载配置。') + + return path class SessionOptions(object):