38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
|
import os
|
||
|
import platform
|
||
|
import uuid
|
||
|
import json
|
||
|
|
||
|
|
||
|
class CreateConfig:
|
||
|
"""
|
||
|
:param title: 配置文件的
|
||
|
"""
|
||
|
|
||
|
def __init__(self, title):
|
||
|
uid = str(uuid.uuid4())
|
||
|
config_path = self.get_config_path()
|
||
|
todo_list_path = config_path + '/{' + uid + '}'
|
||
|
try:
|
||
|
os.mkdir(todo_list_path)
|
||
|
library = {
|
||
|
"title": title,
|
||
|
"uid": uuid
|
||
|
}
|
||
|
with open(todo_list_path + '/library.json', 'w') as f:
|
||
|
f.write(json.dumps(library))
|
||
|
except IOError as e:
|
||
|
print(e)
|
||
|
pass
|
||
|
|
||
|
def get_config_path(self):
|
||
|
# print(platform.system())
|
||
|
if platform.system() == 'Linux':
|
||
|
print(os.environ['HOME'] + '.config/PyQtToDoList')
|
||
|
# print(os.path.expandvars('~'))
|
||
|
print(os.path.expandvars('$HOME') + '.config/PyQtToDoList')
|
||
|
return os.path.expandvars('$HOME') + '.config/PyQtToDoList'
|
||
|
elif platform.system() == 'Windows':
|
||
|
print(os.getcwd() + 'config')
|
||
|
return os.getcwd() + 'config'
|