movoid-debug 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
movoid_debug/__init__.py
ADDED
movoid_debug/flow.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#! /usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# File : flow
|
|
5
|
+
# Author : Sun YiFan-Movoid
|
|
6
|
+
# Time : 2024/4/14 16:15
|
|
7
|
+
# Description :
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from movoid_function import Function
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FlowFunction:
|
|
14
|
+
def __init__(self, func, args, kwargs, flow, ignore_exception):
|
|
15
|
+
self._func = Function(func, args, kwargs)
|
|
16
|
+
self._flow = flow
|
|
17
|
+
self._ignore_exception = ignore_exception
|
|
18
|
+
self._init = True
|
|
19
|
+
self._exception = None
|
|
20
|
+
|
|
21
|
+
def __call__(self):
|
|
22
|
+
while True:
|
|
23
|
+
try:
|
|
24
|
+
self.ask_call()
|
|
25
|
+
break
|
|
26
|
+
except:
|
|
27
|
+
break
|
|
28
|
+
|
|
29
|
+
def ask_call(self):
|
|
30
|
+
if self._init:
|
|
31
|
+
self._init = False
|
|
32
|
+
return self._func()
|
|
33
|
+
else:
|
|
34
|
+
ask_str = input('请输入操作方案(1)重新执行(2)返回None跳过执行(3)输入返回值后跳过执行(4)重新输入参数后执行(其他)认可失败,退出:')
|
|
35
|
+
if ask_str == '1':
|
|
36
|
+
return self._func()
|
|
37
|
+
elif ask_str == '2':
|
|
38
|
+
return None
|
|
39
|
+
elif ask_str == '3':
|
|
40
|
+
ask_return = input('请输入返回值:')
|
|
41
|
+
return eval(ask_return)
|
|
42
|
+
elif ask_str == '4':
|
|
43
|
+
ask_args = input('请输入参数值:')
|
|
44
|
+
return eval(f'self._func({ask_args})')
|
|
45
|
+
else:
|
|
46
|
+
raise self._exception
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Flow:
|
|
50
|
+
def __init__(self):
|
|
51
|
+
self._function_list = []
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#! /usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
# File : simple_debug
|
|
5
|
+
# Author : Sun YiFan-Movoid
|
|
6
|
+
# Time : 2024/5/20 1:52
|
|
7
|
+
# Description :
|
|
8
|
+
"""
|
|
9
|
+
import traceback
|
|
10
|
+
from movoid_function import wraps, Function
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ErrorFunction:
|
|
14
|
+
def __init__(self, func, args, kwargs, error):
|
|
15
|
+
self.func = func
|
|
16
|
+
self.args = args
|
|
17
|
+
self.kwargs = kwargs
|
|
18
|
+
self.error = error
|
|
19
|
+
self.traceback = traceback.format_exc()
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SimpleDebug:
|
|
23
|
+
def __init__(self):
|
|
24
|
+
self._error_list = []
|
|
25
|
+
|
|
26
|
+
def when_error(self, _continue=True, error_teardown=None, error_teardown_args=None, error_teardown_kwargs=None):
|
|
27
|
+
if isinstance(_continue, bool):
|
|
28
|
+
error_teardown_function = Function(error_teardown, error_teardown_args, error_teardown_kwargs)
|
|
29
|
+
|
|
30
|
+
def dec(func):
|
|
31
|
+
@wraps(func)
|
|
32
|
+
def wrapping(*args, **kwargs):
|
|
33
|
+
try:
|
|
34
|
+
re_value = func(*args, **kwargs)
|
|
35
|
+
except Exception as err:
|
|
36
|
+
if _continue:
|
|
37
|
+
self._error_list.append(ErrorFunction(func, args, kwargs, err))
|
|
38
|
+
try:
|
|
39
|
+
error_teardown_function()
|
|
40
|
+
except:
|
|
41
|
+
print(f'fail to teardown:\n{traceback.format_exc()}')
|
|
42
|
+
else:
|
|
43
|
+
raise err
|
|
44
|
+
else:
|
|
45
|
+
return re_value
|
|
46
|
+
|
|
47
|
+
return wrapping
|
|
48
|
+
|
|
49
|
+
return dec
|
|
50
|
+
else:
|
|
51
|
+
return self.when_error()(_continue)
|
|
52
|
+
|
|
53
|
+
def raise_all(self):
|
|
54
|
+
raise DebugError(self._error_list)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class DebugError(Exception):
|
|
58
|
+
def __init__(self, error_list, *args):
|
|
59
|
+
all_info = ''
|
|
60
|
+
for error in error_list:
|
|
61
|
+
all_info += f'{error.func.__name__}{error.args}{error.kwargs}:{error.error}\n{error.traceback}\n'
|
|
62
|
+
super().__init__(all_info, *args)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
DEBUG = SimpleDebug()
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
movoid_debug/__init__.py,sha256=bD3h80X2N4dvCy7mMYsrQYyznb6vUCDT7dYU9gc_m3w,227
|
|
2
|
+
movoid_debug/flow.py,sha256=l-alGZ54HlL2O_opwMpdwIbsOEqPFvoWdjFJD2WrqvQ,1554
|
|
3
|
+
movoid_debug/simple_debug.py,sha256=zpbS9oV4XPl5dY9mpLcJkbtNc5qGTOtygGnAbLn7e74,2069
|
|
4
|
+
movoid_debug-1.0.0.dist-info/METADATA,sha256=KqZQJmhhHB3fyBZvBkDEY7wc7ucoqR8myWspdeL6cMg,242
|
|
5
|
+
movoid_debug-1.0.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
6
|
+
movoid_debug-1.0.0.dist-info/top_level.txt,sha256=-3Pt_3Kkzi008eeHY-DfwlqPcpCmJDIwoTdethLA8YU,13
|
|
7
|
+
movoid_debug-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
movoid_debug
|