2022-04-18 20:22:42 +08:00
|
|
|
|
import configparser
|
|
|
|
|
import os
|
2022-04-28 17:07:42 +08:00
|
|
|
|
import base64
|
2022-04-17 22:36:19 +08:00
|
|
|
|
|
2022-04-22 22:09:38 +08:00
|
|
|
|
from utils.BasicUtils import return_work_dir
|
|
|
|
|
|
|
|
|
|
|
2022-04-18 20:22:42 +08:00
|
|
|
|
class CreateConfigure:
|
2022-04-26 21:10:49 +08:00
|
|
|
|
|
|
|
|
|
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
|
2022-04-26 22:41:33 +08:00
|
|
|
|
|
2022-04-26 21:10:49 +08:00
|
|
|
|
config['System'] = {'exitStatus': 'None'}
|
|
|
|
|
|
|
|
|
|
with open(config_file, 'w') as f:
|
|
|
|
|
config.write(f)
|
|
|
|
|
|
2022-04-18 20:22:42 +08:00
|
|
|
|
"""
|
|
|
|
|
:param login_type : 登录方式 有 NextCloud、JianGuoYun、WebDav
|
|
|
|
|
:param webdav_login : 登录用户名
|
|
|
|
|
:param webdav_password : 登录密码
|
|
|
|
|
:param webdav_hostname : 服务地址
|
|
|
|
|
"""
|
|
|
|
|
|
2022-04-26 21:10:49 +08:00
|
|
|
|
def login(self, login_type, webdav_login, webdav_password, webdav_hostname=None):
|
2022-04-22 22:09:38 +08:00
|
|
|
|
config_file = return_work_dir() + 'PyQtToDoList.ini'
|
2022-04-18 20:22:42 +08:00
|
|
|
|
config = configparser.ConfigParser()
|
2022-04-26 21:10:49 +08:00
|
|
|
|
config.read(config_file)
|
2022-04-28 17:07:42 +08:00
|
|
|
|
# 避免密码明文显示,使用base64编码
|
|
|
|
|
webdav_password = str(base64.b64encode(webdav_password.encode('utf-8')), 'utf-8')
|
2022-04-26 21:10:49 +08:00
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
with open(config_file, 'w') as f:
|
|
|
|
|
config.write(f)
|
|
|
|
|
print('create complete!', config_file)
|