pyqt-todolist/utils/CreateConfigure.py
2022-04-26 21:10:49 +08:00

71 lines
2.6 KiB
Python

import configparser
import os
# todo : 用来创建软件的配置信息
from utils.BasicUtils import return_work_dir
class CreateConfigure:
def __init__(self):
config_file = return_work_dir() + 'PyQtToDoList.ini'
config = configparser.ConfigParser()
if not os.path.exists(config_file):
options = {
'webdav_hostname': "None",
'webdav_login': "None",
'webdav_password': "None",
'type': "None"
}
config['Account'] = options
# todo 解决保存配置文件的问题
config['System'] = {'exitStatus': 'None'}
with open(config_file, 'w') as f:
config.write(f)
"""
:param login_type : 登录方式 有 NextCloud、JianGuoYun、WebDav
:param webdav_login : 登录用户名
:param webdav_password : 登录密码
:param webdav_hostname : 服务地址
"""
def login(self, login_type, webdav_login, webdav_password, webdav_hostname=None):
config_file = return_work_dir() + 'PyQtToDoList.ini'
config = configparser.ConfigParser()
config.read(config_file)
# if not os.path.exists(config_file):
print(config['Account']['type'])
if login_type == 'NextCloud':
webdav_hostname = webdav_hostname + '/' if webdav_hostname[-1] != '/' else webdav_hostname
config['Account']['webdav_hostname'] = webdav_hostname + "remote.php/dav/files/admin/"
config['Account']['webdav_login'] = webdav_login
config['Account']['webdav_password'] = webdav_password
config['Account']['type'] = login_type
elif login_type == 'JianGuoYun':
config['Account']['webdav_hostname'] = "https://dav.jianguoyun.com/dav/"
config['Account']['webdav_login'] = webdav_login
config['Account']['webdav_password'] = webdav_password
config['Account']['type'] = login_type
elif login_type == 'WebDav':
webdav_hostname = webdav_hostname + '/' if webdav_hostname[-1] != '/' else webdav_hostname
config['Account']['webdav_hostname'] = webdav_hostname
config['Account']['webdav_login'] = webdav_login
config['Account']['webdav_password'] = webdav_password
config['Account']['type'] = login_type
# todo 解决保存配置文件的问题
config['System'] = {'exitStatus': 'None'}
print(config['System']['exitStatus'])
with open(config_file, 'w') as f:
config.write(f)
print('create complete!', config_file)