forked from rachpt/lanzou-gui
-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdebug.py
47 lines (39 loc) · 1.65 KB
/
debug.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
"""
调试日志设置,全局常量
"""
import logging
import os
__all__ = ['logger', 'SRC_DIR', 'CONFIG_FILE', 'DL_DIR', 'BG_IMG', 'USER_HOME']
LOG_TO_CONSOLE = False
# 全局常量: USER_HOME, DL_DIR, SRC_DIR, BG_IMG, CONFIG_FILE
USER_HOME = os.path.expanduser('~')
if os.name == 'nt': # Windows
root_dir = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.dirname(root_dir)
import winreg
sub_key = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
downloads_guid = '{374DE290-123F-4565-9164-39C4925E467B}'
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, sub_key) as key:
DL_DIR = winreg.QueryValueEx(key, downloads_guid)[0]
else: # Linux and MacOS ...
root_dir = USER_HOME + os.sep + '.config' + os.sep + 'lanzou-gui'
if not os.path.exists(root_dir):
os.makedirs(root_dir)
DL_DIR = USER_HOME + os.sep + 'Downloads'
SRC_DIR = root_dir + os.sep + "resources" + os.sep
BG_IMG = (SRC_DIR + "default_background_img.jpg").replace('\\', '/')
CONFIG_FILE = root_dir + os.sep + 'config.pkl'
# 日志设置
log_file = root_dir + os.sep + 'debug-lanzou-gui.log'
logger = logging.getLogger('lanzou')
fmt_str = "%(asctime)s [%(filename)s:%(lineno)d] %(funcName)s %(levelname)s - %(message)s"
logging.basicConfig(level=logging.ERROR,
filename=log_file,
filemode="a",
format=fmt_str,
datefmt="%Y-%m-%d %H:%M:%S")
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)
if LOG_TO_CONSOLE:
console_handler = logging.StreamHandler()
logger.addHandler(console_handler)