67 lines
2.5 KiB
Python
67 lines
2.5 KiB
Python
import configparser
|
||
import os
|
||
import base64
|
||
|
||
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
|
||
|
||
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)
|
||
# 避免密码明文显示,使用base64编码
|
||
webdav_password = str(base64.b64encode(webdav_password.encode('utf-8')), 'utf-8')
|
||
# 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)
|