-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsettings.py
67 lines (54 loc) · 1.84 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: leeyoshinari
import os
import shutil
import sys
import configparser
import logging.handlers
if hasattr(sys, 'frozen'):
path = os.path.dirname(sys.executable)
else:
path = os.path.dirname(os.path.abspath(__file__))
cfg = configparser.ConfigParser()
config_path = os.path.join(path, 'config.conf')
cfg.read(config_path, encoding='utf-8')
PAGE_SIZE = 20
def get_config(key):
return cfg.get('default', key, fallback=None)
FILE_PATH = get_config("path")
if not os.path.exists(FILE_PATH):
raise FileNotFoundError(FILE_PATH)
TORTOISE_ORM = {
"connections": {"default": f"sqlite://{FILE_PATH}/sqlite3.db"},
"apps": {
"models": {
"models": ["karaoke.models", "aerich.models"],
"default_connection": "default"
}
},
"timezone": "Asia/Shanghai"
}
CONTENT_TYPE = {'mp4': 'video/mp4', 'mp3': 'audio/mpeg'}
VIDEO_PATH = os.path.join(path, 'static', 'videos')
if os.path.exists(VIDEO_PATH):
shutil.rmtree(VIDEO_PATH)
os.mkdir(VIDEO_PATH)
log_path = os.path.join(path, 'logs')
if not os.path.exists(log_path):
os.mkdir(log_path)
log_level = {
'DEBUG': logging.DEBUG,
'INFO': logging.INFO,
'WARNING': logging.WARNING,
'ERROR': logging.ERROR,
'CRITICAL': logging.CRITICAL
}
logger = logging.getLogger()
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(threadName)s - %(filename)s[line:%(lineno)d] - %(message)s')
logger.setLevel(level=log_level.get(get_config("level")))
file_handler = logging.handlers.TimedRotatingFileHandler(os.path.join(log_path, 'access.log'), when='midnight', interval=1, backupCount=7)
file_handler.suffix = '%Y-%m-%d.log'
file_handler = logging.StreamHandler()
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)