-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
57 lines (48 loc) · 1.5 KB
/
util.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
from wox import Wox, WoxAPI
import types
import traceback
import logging
import functools
import os
from contextlib import contextmanager
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%a, %d %b %Y %H:%M:%S',
filename="error.log",
filemode='a')
class Log:
@classmethod
def debug(cls, msg):
logging.debug(msg)
@classmethod
def info(cls, msg):
logging.info(msg)
@classmethod
def error(cls, msg):
logging.error(msg)
@contextmanager
def load_module():
try:
yield
except:
Log.error(traceback.format_exc())
# os.system(r'explorer "{}"'.format(os.getcwd()))
def _debug(func):
@functools.wraps(func)
def wrap(*args, **kwargs):
try:
return func(*args, **kwargs)
except:
error = traceback.format_exc()
WoxAPI.show_msg("error", error)
Log.error(error)
# os.system(r'explorer "{}"'.format(os.getcwd()))
return wrap
class _DebugMeta(type):
def __new__(cls, clsname, bases, attrs):
for func_name, func in attrs.items():
if isinstance(func, types.FunctionType):
attrs[func_name] = _debug(func)
return super(_DebugMeta, cls).__new__(cls, clsname, bases, attrs)
class WoxEx(Wox, metaclass=_DebugMeta):
pass