mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
easy_set增加configs_to_here()方法;创建配置对象默认先读取项目文件夹下的dp_configs.ini
This commit is contained in:
parent
afc9414600
commit
61fc745328
@ -21,8 +21,9 @@ class ChromiumOptions(object):
|
|||||||
self._prefs_to_del = []
|
self._prefs_to_del = []
|
||||||
|
|
||||||
if read_file is not False:
|
if read_file is not False:
|
||||||
self.ini_path = str(ini_path) if ini_path else str(Path(__file__).parent / 'configs.ini')
|
ini_path = str(ini_path) if ini_path else None
|
||||||
om = OptionsManager(self.ini_path)
|
om = OptionsManager(ini_path)
|
||||||
|
self.ini_path = om.ini_path
|
||||||
options = om.chrome_options
|
options = om.chrome_options
|
||||||
|
|
||||||
self._download_path = om.paths.get('download_path', None)
|
self._download_path = om.paths.get('download_path', None)
|
||||||
|
@ -13,9 +13,18 @@ class OptionsManager(object):
|
|||||||
|
|
||||||
def __init__(self, path=None):
|
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():
|
if not Path(self.ini_path).exists():
|
||||||
raise FileNotFoundError('ini文件不存在。')
|
raise FileNotFoundError('ini文件不存在。')
|
||||||
self._conf = RawConfigParser()
|
self._conf = RawConfigParser()
|
||||||
|
@ -36,8 +36,9 @@ class SessionOptions(object):
|
|||||||
self._del_set = set() # 记录要从ini文件删除的参数
|
self._del_set = set() # 记录要从ini文件删除的参数
|
||||||
|
|
||||||
if read_file is not False:
|
if read_file is not False:
|
||||||
self.ini_path = str(ini_path) if ini_path else str(Path(__file__).parent / 'configs.ini')
|
ini_path = str(ini_path) if ini_path else None
|
||||||
om = OptionsManager(self.ini_path)
|
om = OptionsManager(ini_path)
|
||||||
|
self.ini_path = om.ini_path
|
||||||
options_dict = om.session_options
|
options_dict = om.session_options
|
||||||
|
|
||||||
if options_dict.get('headers', None) is not None:
|
if options_dict.get('headers', None) is not None:
|
||||||
|
@ -18,6 +18,16 @@ from .common.tools import unzip
|
|||||||
from .session_page import SessionPage
|
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):
|
def show_settings(ini_path=None):
|
||||||
"""打印ini文件内容
|
"""打印ini文件内容
|
||||||
:param ini_path: ini文件路径
|
:param ini_path: ini文件路径
|
||||||
|
@ -7,6 +7,9 @@ from pathlib import Path
|
|||||||
from typing import Union
|
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: ...
|
def show_settings(ini_path: Union[str, Path] = None) -> None: ...
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user