easy_set增加configs_to_here()方法;创建配置对象默认先读取项目文件夹下的dp_configs.ini

This commit is contained in:
g1879 2023-02-17 00:25:21 +08:00
parent afc9414600
commit 61fc745328
5 changed files with 30 additions and 6 deletions

View File

@ -21,8 +21,9 @@ class ChromiumOptions(object):
self._prefs_to_del = []
if read_file is not False:
self.ini_path = str(ini_path) if ini_path else str(Path(__file__).parent / 'configs.ini')
om = OptionsManager(self.ini_path)
ini_path = str(ini_path) if ini_path else None
om = OptionsManager(ini_path)
self.ini_path = om.ini_path
options = om.chrome_options
self._download_path = om.paths.get('download_path', None)

View File

@ -13,9 +13,18 @@ class OptionsManager(object):
def __init__(self, path=None):
"""初始化,读取配置文件,如没有设置临时文件夹,则设置并新建
:param path: ini文件的路径默认读取模块文件夹下的
:param path: ini文件的路径为None则找项目文件夹下的找不到则读取模块文件夹下的
"""
self.ini_path = str(Path(__file__).parent / 'configs.ini') if path == 'default' or path is None else str(path)
if path is None:
if Path('dp_configs.ini').exists():
self.ini_path = 'dp_configs.ini'
else:
self.ini_path = str(Path(__file__).parent / 'configs.ini')
elif path == 'default':
self.ini_path = str(Path(__file__).parent / 'configs.ini')
else:
self.ini_path = str(path)
if not Path(self.ini_path).exists():
raise FileNotFoundError('ini文件不存在。')
self._conf = RawConfigParser()

View File

@ -36,8 +36,9 @@ class SessionOptions(object):
self._del_set = set() # 记录要从ini文件删除的参数
if read_file is not False:
self.ini_path = str(ini_path) if ini_path else str(Path(__file__).parent / 'configs.ini')
om = OptionsManager(self.ini_path)
ini_path = str(ini_path) if ini_path else None
om = OptionsManager(ini_path)
self.ini_path = om.ini_path
options_dict = om.session_options
if options_dict.get('headers', None) is not None:

View File

@ -18,6 +18,16 @@ from .common.tools import unzip
from .session_page import SessionPage
def configs_to_here(file_name=None):
"""把默认ini文件复制到当前目录
:param file_name: 指定文件名为None则命名为'dp_configs.ini'
:return: None
"""
om = OptionsManager('default')
file_name = str(file_name) if file_name is not None else 'dp_configs.ini'
om.save(file_name)
def show_settings(ini_path=None):
"""打印ini文件内容
:param ini_path: ini文件路径

View File

@ -7,6 +7,9 @@ from pathlib import Path
from typing import Union
def configs_to_here(file_name: Union[Path, str] = None) -> None: ...
def show_settings(ini_path: Union[str, Path] = None) -> None: ...