import configparser import platform import os from utils import BasicUtils # todo : 用来创建软件的配置信息 from utils.BasicUtils import return_work_dir class CreateConfigure: """ :param login_type : 登录方式 有 NextCloud、JianGuoYun、WebDav :param webdav_login : 登录用户名 :param webdav_password : 登录密码 :param webdav_hostname : 服务地址 """ def __init__(self, login_type, webdav_login, webdav_password, webdav_hostname=None): config_file = return_work_dir() + 'PyQtToDoList.ini' config = configparser.ConfigParser() if not os.path.exists(config_file): # print(config_file) options = {} if login_type == 'NextCloud': webdav_hostname = webdav_hostname + '/' if webdav_hostname[-1] != '/' else webdav_hostname options = { 'webdav_hostname': webdav_hostname + "remote.php/dav/files/admin/", 'webdav_login': webdav_login, 'webdav_password': webdav_password, 'type': login_type } elif login_type == 'JianGuoYun': options = { 'webdav_hostname': "https://dav.jianguoyun.com/dav/", 'webdav_login': webdav_login, 'webdav_password': webdav_password, 'type': login_type } elif login_type == 'WebDav': webdav_hostname = webdav_hostname + '/' if webdav_hostname[-1] != '/' else webdav_hostname options = { 'webdav_hostname': webdav_hostname, 'webdav_login': webdav_login, 'webdav_password': webdav_password, 'type': login_type } config['Account'] = options config['ToDoList'] = {} with open(config_file, 'w') as f: config.write(f) print('create complete!', config_file) # def return_config_file(self): # if platform.system() == 'Linux': # work_path = os.path.expandvars('$HOME') + '/.config/PyQtToDoList' # if not os.path.exists(work_path): # os.mkdir(work_path) # return os.path.expandvars('$HOME') + '/.config/PyQtToDoList/PyQtToDoList.ini' # elif platform.system() == 'Windows': # return os.getcwd() + '/PyQtToDoList.ini' # CreateConfigure('NextCloud', 'admin', '19990903@lyp', 'https://cloud.liyp.cc')