update
This commit is contained in:
@@ -7,6 +7,7 @@ miniQMTPath = r'D:\\Programs\\DTQMT\\userdata_mini' # miniQMT软件的安装路
|
||||
account_no:str = '99082560'
|
||||
console_log = True
|
||||
log_level = "INFO"
|
||||
use_simulated_qmt: bool = False
|
||||
|
||||
def get_config_path() -> Path:
|
||||
"""获取配置文件的正确路径(兼容开发环境和打包后的可执行文件)"""
|
||||
@@ -21,12 +22,14 @@ def get_config_path() -> Path:
|
||||
|
||||
return base_path / 'config.ini'
|
||||
|
||||
def save_config(miniQmtPath:str, account_no:str):
|
||||
def save_config(miniQmtPath:str, account_no:str, use_simulated_qmt: bool = False):
|
||||
"""创建默认配置文件"""
|
||||
config = configparser.ConfigParser()
|
||||
config['config'] = {
|
||||
'miniQMTPath': miniQmtPath,
|
||||
'account_no': account_no
|
||||
'account_no': account_no,
|
||||
'use_simulated_qmt': str(use_simulated_qmt),
|
||||
'log_level': 'INFO'
|
||||
}
|
||||
config_path = get_config_path()
|
||||
with open(config_path, 'w') as configfile:
|
||||
@@ -39,16 +42,20 @@ def exist_config() -> bool:
|
||||
return config_path.exists()
|
||||
|
||||
def initConfig() -> bool:
|
||||
global miniQMTPath, account_no, log_level
|
||||
|
||||
global miniQMTPath, account_no, log_level, use_simulated_qmt
|
||||
|
||||
# 获取配置文件路径
|
||||
config_path = get_config_path()
|
||||
|
||||
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_path, encoding='utf-8')
|
||||
miniQMTPath = config.get('config','miniQMTPath')
|
||||
account_no = config.get('config','account_no')
|
||||
log_level = config.get('config','log_level')
|
||||
try:
|
||||
use_simulated_qmt = config.get('config','use_simulated_qmt').lower() in ('true', '1', 'yes')
|
||||
except (configparser.NoOptionError, configparser.NoSectionError):
|
||||
use_simulated_qmt = False
|
||||
|
||||
# 判断miniQMTPath是否为空,并且目录是否存在
|
||||
if not miniQMTPath or not Path(miniQMTPath).exists():
|
||||
|
||||
Reference in New Issue
Block a user