浏览代码

BaseException增加了日志记录

Huan 5 年之前
父节点
当前提交
71604415e3

+ 2 - 1
algebraicfactory/gui.py

@@ -5,6 +5,7 @@ import tkinter.font as tkfont
 from algebraicfactory.controller import AlgebraPolynomial
 from system import exception_catch
 
+
 algebra_list = []
 variable_list = []
 SCREEN = tkinter.Tk()
@@ -91,7 +92,7 @@ class UIAPI:
         if all_ == 0:
             return True, False
         elif all_ == 1:
-            raise, False
+            return False, False
         else:
             return True, True
 

+ 8 - 2
algebraicfactory/template.py

@@ -1,5 +1,6 @@
 from abc import ABCMeta, abstractmethod
 import os
+import logging
 
 from sympy import simplify, count_ops, Float, Integer, Rational, sympify, factor, factor_list, expand, collect, Add, \
     Mul, ratsimp, cancel, apart, together, radsimp, trigsimp, expand_trig, expand_mul, expand_multinomial, powdenest, \
@@ -8,7 +9,9 @@ from sympy import simplify, count_ops, Float, Integer, Rational, sympify, factor
 from sympy.plotting import plot3d
 from sympy.core.sympify import SympifyError
 
-from system import plugin_class_loading, get_path, plugin_func_loading
+from system import plugin_class_loading, get_path, plugin_func_loading, basicConfig
+
+logging.basicConfig(**basicConfig)
 
 
 class DictNameError(Exception):
@@ -45,6 +48,7 @@ class AlgebraInit:
         self.algebra_dict_view = {}  # 门面(str)
         self.symbol_describe = {}  # 描述文件
         self.out_status = new
+        logging.info('AlgebraInit init')
 
     def get_expression(self, name, exp_str=False):
         try:
@@ -136,6 +140,7 @@ class AlgebraSymbol(AlgebraSymbolBase):
         try:
             exec(f"self.symbol_dict['{name}'] = Symbol('{name}', **k)", new_name)  # 创建一个Symbols
         except BaseException:
+            logging.error(f"add_symbol exec self.symbol_dict['{name}'] = Symbol('{name}', **k)")
             raise SymbolError
         self.symbol_describe[name] = describe
         return True
@@ -698,7 +703,8 @@ class General(AlgebraMath, metaclass=ABCMeta):
         alg = self.get_expression(name)
         try:
             return collect(alg, x)
-        except BaseException:
+        except BaseException as e:
+            logging.debug(str(e))
             return ceiling(alg)
 
 

+ 13 - 6
crawler/gui.py

@@ -2,12 +2,14 @@ import os
 import re
 import tkinter
 import threading
+import logging
 
 import crawler.controller
 import crawler.template
 from newtkinter import askdirectory
-from system import exception_catch
+from system import exception_catch, basicConfig
 
+logging.basicConfig(**basicConfig)
 SCREEN = tkinter.Tk()
 database_list = []
 attributes_dict = {}
@@ -76,7 +78,8 @@ class UIAPI:
     def get_db_index_gui():
         try:
             index = eval(object_index.get(), {})
-        except BaseException:
+        except BaseException as e:
+            logging.debug(str(e))
             index = slice(None, None)
         return index
 
@@ -169,11 +172,13 @@ class UIAPI:
         global find_text, text_regex, limit, is_recursive, find_path
         try:
             index = eval(object_index.get(), {})
-        except BaseException:
+        except BaseException as e:
+            logging.debug(str(e))
             index = slice(None, None)
         try:
             cookies = eval(new_cookies.get(), {})
-        except BaseException:
+        except BaseException as e:
+            logging.debug(str(e))
             cookies = {}
         return dict(
             element_value=operation_object.get(),
@@ -269,7 +274,8 @@ class UIAPI:
     def get_url_parameter_gui():
         try:
             data = eval(requests_data.get(), {})
-        except BaseException:
+        except BaseException as e:
+            logging.debug(str(e))
             data = {}
         try:
             the_time_out = int(time_out.get())
@@ -297,7 +303,8 @@ class UIAPI:
     def add_url_from_tag_gui():
         try:
             index = eval(object_index.get(), {})
-        except BaseException:
+        except BaseException as e:
+            logging.debug(str(e))
             index = slice(None, None)
         return dict(
             element_value=operation_object.get(),

+ 6 - 3
crawler/template.py

@@ -6,6 +6,7 @@ import threading
 import time
 from abc import ABCMeta, abstractmethod
 from time import sleep
+import logging
 
 from selenium import webdriver
 from selenium.webdriver import ActionChains
@@ -13,7 +14,9 @@ from selenium.webdriver.common.keys import Keys
 from selenium.common.exceptions import InvalidSessionIdException, WebDriverException
 import requests
 
-from system import plugin_class_loading, get_path
+from system import plugin_class_loading, get_path, basicConfig
+
+logging.basicConfig(**basicConfig)
 
 keys_name_dict = {
     "ctrl": Keys.CONTROL,
@@ -1389,8 +1392,8 @@ class PageParserTool(PageParserFunc):
                     if re is None:
                         raise PageParserError
                     paser_list.append(re)
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
             self.element_dict[f"{name}[{num}]"] = paser_list
 
         self.add_func(f"get>{path}:{element_value}[{index}]", action)  # 添加func

+ 55 - 53
datascience/template.py

@@ -3,6 +3,7 @@ from random import randint
 import re
 from os import getcwd
 import os
+import logging
 
 import numpy as np
 from sklearn.feature_extraction import DictVectorizer
@@ -18,8 +19,9 @@ import pandas_profiling as pp
 
 from pyecharts.globals import CurrentConfig
 from pyecharts.globals import GeoType  # 地图推荐使用GeoType而不是str
-from system import plugin_class_loading, get_path
+from system import plugin_class_loading, get_path, basicConfig
 
+logging.basicConfig(**basicConfig)
 CurrentConfig.ONLINE_HOST = f"{getcwd()}{os.sep}assets{os.sep}"
 
 
@@ -441,14 +443,14 @@ class SheetSlice(FormBase, metaclass=ABCMeta):
         for i in column:
             try:
                 new_sheet = new_sheet.drop(column_list[int(i)], axis=1)
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         row_list = new_sheet.index.values
         for i in row:
             try:
                 new_sheet = new_sheet.drop(row_list[int(i)])
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         if new:
             self.add_sheet(new_sheet, f"{name}:删减")
         return new_sheet
@@ -480,8 +482,8 @@ class DatacleaningFunc(FormBase, metaclass=ABCMeta):
         try:
             del self.clean_func[key]
             del self.clean_func_code[key]
-        finally:
-            pass
+        except BaseException as e:
+            logging.warning(str(e))
 
     def del_all_clean_func(self):
         self.clean_func = {}
@@ -539,8 +541,8 @@ class DatacleaningFunc(FormBase, metaclass=ABCMeta):
                             else:
                                 # 第一个是行名,然后是列名
                                 exec(f"get.iloc[{row},{column}] = {d}", {"get": get})
-                    finally:
-                        pass
+                    except BaseException as e:
+                        logging.warning(str(e))
         self.add_sheet(get, f"{name}:清洗")
         return get
 
@@ -552,8 +554,8 @@ class SheetDtype(FormBase, metaclass=ABCMeta):
         for i in range(len(column)):
             try:
                 column[i] = int(column[i])
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
 
         if dtype != "":
             func_dic = {
@@ -580,8 +582,8 @@ class SheetDtype(FormBase, metaclass=ABCMeta):
         for i in range(len(column)):
             try:
                 column[i] = int(column[i])
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         func_dic = {
             "Int": int,
             "Float": float,
@@ -987,8 +989,8 @@ class AxisPlot(Render):
                 )  # i[0]是名字,i是tuple,其中i[1]是data
                 # q不需要float,因为应多不同的type他会自动变更,但是y是用来比较大小
                 y += list(map(int, q))
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         if not y:
             args["show_Visual_mapping"] = False  # 关闭视觉映射
             y = [0, 100]
@@ -1019,8 +1021,8 @@ class AxisPlot(Render):
                 )  # i[0]是名字,i是tuple,其中i[1]是data
                 # q不需要float,因为应多不同的type他会自动变更,但是y是用来比较大小
                 y += list(map(int, q))
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         if not y:
             args["show_Visual_mapping"] = False  # 关闭视觉映射
             y = [0, 100]
@@ -1057,8 +1059,8 @@ class AxisPlot(Render):
                 )  # i[0]是名字,i是tuple,其中i[1]是data
                 # q不需要float,因为应多不同的type他会自动变更,但是y是用来比较大小
                 y += list(map(int, q))
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         if not y:
             args["show_Visual_mapping"] = False  # 关闭视觉映射
             y = [0, 100]
@@ -1095,8 +1097,8 @@ class AxisPlot(Render):
                 )
                 # q不需要float,因为应多不同的type他会自动变更,但是y是用来比较大小
                 y += list(map(int, q))
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         if not y:
             args["show_Visual_mapping"] = False  # 关闭视觉映射
             y = [0, 100]
@@ -1120,8 +1122,8 @@ class AxisPlot(Render):
                 c.add_yaxis(f"{name}_{i[0]}", [q], **self.yaxis_label(args))
                 # q不需要float,因为应多不同的type他会自动变更,但是y是用来比较大小
                 y += list(map(float, q))
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         if not y:
             args["show_Visual_mapping"] = False  # 关闭视觉映射
             y = [0, 100]
@@ -1186,10 +1188,10 @@ class GeneralPlot(Render):
                         link.append(
                             {"source": f"{i[0]}", "target": n[0], "value": float(n[1])}
                         )
-                    finally:
-                        pass
-            finally:
-                pass
+                    except BaseException as e:
+                        logging.warning(str(e))
+            except BaseException as e:
+                logging.warning(str(e))
         if not link:
             for i in nodes:
                 for j in nodes:
@@ -1246,8 +1248,8 @@ class GeneralPlot(Render):
                 try:
                     v = float(eval(f"get.iloc[{y},{x}]", {"get": get}))  # 取得value
                     link.append({"source": y_n, "target": x_n, "value": v})
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
         c = (
             Graph(**self.init_setting(args))
             .add(
@@ -1301,8 +1303,8 @@ class GeneralPlot(Render):
                     link.append({"source": y_n, "target": x_n, "value": v})
                     target[y_n].add(x_n)
                     source[x_n].add(y_n)
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
         c = (
             Sankey()
             .add(
@@ -1347,8 +1349,8 @@ class GeneralPlot(Render):
         for i in get.iterrows():  # 按行迭代
             try:
                 data.append([f"{i[0]}", float(i[1].tolist()[0])])
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         args = self.parsing_parameters(text)
         c = (
             Pie(**self.init_setting(args))
@@ -1374,8 +1376,8 @@ class GeneralPlot(Render):
             try:
                 q = i[1].tolist()
                 data.append((float(q[0]), float(q[1]) / convert))
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         c = (
             Polar(**self.init_setting(args))
             .add(f"{name}", data, type_="scatter", **self.yaxis_label(args))
@@ -1401,8 +1403,8 @@ class GeneralPlot(Render):
                     f = float(q[a])
                     max_list[a].append(f)
                     add.append(f)
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
             data.append([f"{i[0]}", [add]])  # add是包含在一个list中的
 
         for i in range(len(max_list)):  # 计算x_list
@@ -1458,8 +1460,8 @@ class GeneralPlot(Render):
                 try:
                     data[a].append([date, q[a]])
                     y.append(float(q[a]))
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
         args = self.parsing_parameters(text)
         if not y:
             y = [0, 100]
@@ -1491,8 +1493,8 @@ class GeneralPlot(Render):
                 try:
                     data.append([date, q[a], x_name[a]])
                     y.append(float(q[a]))
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
         args = self.parsing_parameters(text)
         if not y:
             y = [0, 100]
@@ -1718,8 +1720,8 @@ class GeographyPlot(Render):
                     v = float(q[a])
                     y.append(v)
                     data[a].append((map_, v))
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
         args = self.parsing_parameters(text)
         args["show_Visual_mapping"] = True  # 必须视觉映射
         if not y:
@@ -1826,8 +1828,8 @@ class GeographyPlot(Render):
                             color="#1E90FF" if args["is_Dark"] else "#0000FF",
                         )
                     m.append(v)
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
         if not m:
             m = [0, 100]
         c.set_series_opts(label_opts=opts.LabelOpts(is_show=False))  # 不显示
@@ -1848,8 +1850,8 @@ class WordPlot(Render):
         for i in get.iterrows():  # 按行迭代
             try:
                 data.append([str(i[0]), float(i[1].tolist()[0])])
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         args = self.parsing_parameters(text)
         c = (
             WordCloud(**self.init_setting(args))
@@ -1914,8 +1916,8 @@ class SolidPlot(Render):
                     v = eval(f"get.iloc[{r},{c}]", {"get": get})  # 先行后列
                     value_list.append([c, r, v])
                     q.append(float(v))
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
         args = self.parsing_parameters(text)
         if not q:
             q = [0, 100]
@@ -1952,8 +1954,8 @@ class SolidPlot(Render):
                     v = eval(f"get.iloc[{r},{c}]", {"get": get})  # 先行后列
                     value_list.append([c, r, v])
                     q.append(float(v))
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
         args = self.parsing_parameters(text)
         if not q:
             q = [0, 100]
@@ -1988,8 +1990,8 @@ class SolidPlot(Render):
                     v = eval(f"get.iloc[{r},{c}]", {"get": get})  # 先行后列
                     value_list.append([c, r, v])
                     q.append(float(v))
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
         args = self.parsing_parameters(text)
         if not q:
             q = [0, 100]

+ 6 - 2
draftboard/board.py

@@ -1,10 +1,14 @@
 import time
 import os
+import logging
 
 import pygame
 from pygame.locals import *
 
 from draftboard.toolbox import tool_box
+from system import basicConfig
+
+logging.basicConfig(**basicConfig)
 
 # 定义一些变量
 pen_color = [0, 0, 0]  # 画笔颜色
@@ -322,8 +326,8 @@ def draw_main():
                         try:
                             bg_im = pygame.image.load(tool_set[9]).convert()  # 加载位图
                             SCREEN.blit(bg_im, (0, 0))  # 绘制位图
-                        finally:
-                            pass
+                        except BaseException as e:
+                            logging.warning(str(e))
                     # 恢复参数
                     previous_x = None
                     previous_y = None

+ 22 - 18
funcsystem/factory.py

@@ -3,6 +3,7 @@ import random
 import tkinter
 import tkinter.messagebox
 import os
+import logging
 
 import sympy
 from matplotlib import pyplot as plt
@@ -11,8 +12,9 @@ from matplotlib.animation import FuncAnimation
 
 from funcsystem.controller import ExpFunc as ExpFunc
 from newtkinter import asksaveasfilename
-from system import exception_catch
+from system import exception_catch, basicConfig
 
+logging.basicConfig(**basicConfig)
 func = None
 fig = None
 prompt_num = 0
@@ -61,8 +63,8 @@ class UIAPI:
                 else:
                     a = float(dicon_parameters[i].get())
                 parameters[i] = a
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         return parameters
 
     @staticmethod
@@ -93,9 +95,9 @@ class UIAPI:
             span_a,
         ]
         # 参数的处理
+        span = None
         try:
             span_str = span_definition.get().replace(" ", "")
-            span = None
             if span_str[0] == "H":
                 domain = {
                     "Pi": sympy.pi,
@@ -115,13 +117,13 @@ class UIAPI:
                     "atan": sympy.atan,
                 }
                 span = eval(span_str[1:], domain)
-        finally:
-            pass
+        except BaseException as e:
+            logging.warning(str(e))
         for i in range(8):
             try:
                 default_value[i] = float(get[i].get())
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         if span is not None:
             default_value[2] = span
         # View的处理
@@ -479,8 +481,8 @@ class API(UIAPI):
             for i in API.get_y_value_gui():
                 try:
                     answer += func.dichotomy(float(i), *API.dichotomy_gui())[0]
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
             if answer:
                 API.output_prompt_gui("系统运算完成")
             else:
@@ -547,8 +549,8 @@ class API(UIAPI):
                         exp_parameter[2] = int(plot_parameter[2])
                         exp_parameter[3] = int(plot_parameter[3])
                         exp_parameter[4] = int(plot_parameter[4])
-                    finally:
-                        pass
+                    except BaseException as e:
+                        logging.warning(str(e))
                     plot_parameter = exp_parameter
                     x_exp_scale = API.type_selection(
                         ExpFunc(
@@ -570,7 +572,8 @@ class API(UIAPI):
                 else:  # 输入纯数字
                     x_exp_scale = API.type_selection(x_scale.get().split(","))
                     axis.set_xticks(x_exp_scale)
-            except BaseException:
+            except BaseException as e:
+                logging.debug(str(e))
                 x_major_locator = plt.MultipleLocator(2)
                 axis.xaxis.set_major_locator(x_major_locator)
             # 检测y
@@ -590,8 +593,8 @@ class API(UIAPI):
                         exp_parameter[2] = int(plot_parameter[2])
                         exp_parameter[3] = int(plot_parameter[3])
                         exp_parameter[4] = int(plot_parameter[4])
-                    finally:
-                        pass
+                    except BaseException as e:
+                        logging.warning(str(e))
                     plot_parameter = exp_parameter
                     y_exp_scale = API.type_selection(
                         ExpFunc(
@@ -612,7 +615,8 @@ class API(UIAPI):
                 else:
                     y_exp_scale = API.type_selection(y_scale.get().split(","))
                     axis.set_yticks(y_exp_scale)
-            except BaseException:
+            except BaseException as e:
+                logging.debug(str(e))
                 y_major_locator = plt.MultipleLocator(2)
                 axis.yaxis.set_major_locator(y_major_locator)
             # 极限
@@ -633,8 +637,8 @@ class API(UIAPI):
                     _y_limit = [y_limit[0], y_limit[1]]
                 except IndexError:
                     _y_limit = _x_limit
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
             _x_limit.sort()
             _y_limit.sort()
             axis.set_xlim(_x_limit)

+ 15 - 11
funcsystem/map.py

@@ -4,6 +4,7 @@ import math
 import random
 import tkinter
 import tkinter.messagebox
+import logging
 
 import pandas
 from matplotlib import pyplot as plt
@@ -11,8 +12,9 @@ from matplotlib import rcParams
 
 from funcsystem.controller import SheetFunc, ExpFunc
 from newtkinter import askopenfilename, asksaveasfilename
-from system import exception_catch
+from system import exception_catch, basicConfig
 
+logging.basicConfig(**basicConfig)
 func_logger = []
 fig = None
 func_str_list = []
@@ -146,8 +148,8 @@ class UIAPI:
                     "atan": math.atan,
                 }
                 definition[2] = eval(span_str[1:], named_domain)
-        finally:
-            pass
+        except BaseException as e:
+            logging.warning(str(e))
         return get, [name, style] + definition
 
     @staticmethod
@@ -218,8 +220,8 @@ class API(UIAPI):
                     exp_parameter[2] = int(plot_parameter[2])
                     exp_parameter[3] = int(plot_parameter[3])
                     exp_parameter[4] = int(plot_parameter[4])
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
                 plot_parameter = exp_parameter
                 x_exp_scale = API.type_selection(
                     ExpFunc(
@@ -240,7 +242,8 @@ class API(UIAPI):
             else:  # 输入纯数字
                 x_exp_scale = API.type_selection(x_axis.get().split(","))
                 axis.set_xticks(x_exp_scale)
-        except BaseException:
+        except BaseException as e:
+            logging.debug(str(e))
             x_major_locator = plt.MultipleLocator(2)
             axis.xaxis.set_major_locator(x_major_locator)
         # 检测y
@@ -255,8 +258,8 @@ class API(UIAPI):
                     exp_parameter[2] = int(plot_parameter[2])
                     exp_parameter[3] = int(plot_parameter[3])
                     exp_parameter[4] = int(plot_parameter[4])
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
                 plot_parameter = exp_parameter
                 y_exp_scale = API.type_selection(
                     ExpFunc(
@@ -277,7 +280,8 @@ class API(UIAPI):
             else:
                 y_exp_scale = API.type_selection(y_axis.get().split(","))
                 axis.set_yticks(y_exp_scale)
-        except BaseException:
+        except BaseException as e:
+            logging.debug(str(e))
             y_major_locator = plt.MultipleLocator(2)
             axis.yaxis.set_major_locator(y_major_locator)
         # 极限
@@ -294,8 +298,8 @@ class API(UIAPI):
                 _y_limit = [_y_limit[0], _y_limit[1]]
             except IndexError:
                 _y_limit = _x_limit
-        finally:
-            pass
+        except BaseException as e:
+            logging.warning(str(e))
         _x_limit.sort()
         _y_limit.sort()
         plt.xlim(_x_limit)

+ 46 - 40
funcsystem/template.py

@@ -3,11 +3,14 @@ import tkinter
 import tkinter.messagebox
 from abc import ABCMeta, abstractmethod
 import tkinter.messagebox
+import logging
 
 import pandas
 import sympy
 
-from system import plugin_class_loading, get_path, plugin_func_loading
+from system import plugin_class_loading, get_path, plugin_func_loading, basicConfig
+
+logging.basicConfig(**basicConfig)
 
 
 @plugin_func_loading(get_path(r'template/funcsystem'))
@@ -182,8 +185,8 @@ class SheetFuncInit(SheetFuncBase):
                 float_y = float(func[1][i])
                 float_x_list.append(float_x)
                 float_y_list.append(float_y)
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         # 筛查重复
         x = []
         y = []
@@ -281,8 +284,8 @@ class SheetDataPacket(SheetFuncInit, metaclass=ABCMeta):
                     self.classification_x[-1].append(now_x)
                     self.classification_y[-1].append(y)
                     last_y = y
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
         except (TypeError, IndexError, ValueError):
             pass
         classification_reason.append(99)
@@ -360,8 +363,8 @@ class SheetComputing(SheetFuncInit, metaclass=ABCMeta):
                 ):
                     result = [last_y, i]
                     break
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
             last_y = i
         if result is None:
             for i in y_list:
@@ -369,8 +372,8 @@ class SheetComputing(SheetFuncInit, metaclass=ABCMeta):
                     if abs(((i + last_y) / 2) - y_in) < 0.1:
                         result = [last_y, i]
                         break
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
                 last_y = i
         if result is None:
             return [], []
@@ -551,8 +554,8 @@ class SheetProperty(SheetFuncInit, metaclass=ABCMeta):
                 possible_cycle_list.extend(
                     list(set(possible_cycle))
                 )  # 这里是extend不是append,相当于 +=
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
 
         possible_cycle = []  # a的可能列表
         max_count = 0
@@ -593,8 +596,8 @@ class SheetProperty(SheetFuncInit, metaclass=ABCMeta):
                     if possible_symmetry_axis:
                         possible_symmetry_axis.append(a)
                 possible_symmetry_axis_list.extend(list(set(possible_symmetry_axis)))
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
 
         possible_symmetry_axis = []  # a的可能列表
         max_count = 0
@@ -630,8 +633,8 @@ class SheetProperty(SheetFuncInit, metaclass=ABCMeta):
                 y = self(start)
                 x = start
                 coordinate_points.append((x, y))
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
 
         possible_center_list = []
         output_prompt("正在预测对称中心")
@@ -770,7 +773,8 @@ class ExpFuncInit(ExpFuncBase):
         # 函数求导
         try:
             self.derivatives = sympy.diff(self.func, self.symbol_x)
-        except BaseException:
+        except BaseException as e:
+            logging.debug(str(e))
             self.derivatives = None
 
         # 儿子函数
@@ -789,8 +793,8 @@ class ExpFuncInit(ExpFuncBase):
                     self.son_list.append(
                         ExpFuncSon(func, style, start, end, span, accuracy, a_start)
                     )
-                finally:
-                    pass  # 不应该出现
+                except BaseException as e:
+                    logging.warning(str(e))  # 不应该出现
                 a_start += a_span
             # 这个是函数名字
             self.func_name = (
@@ -873,7 +877,8 @@ class ExpDataPacket(ExpFuncInit, metaclass=ABCMeta):
                     self.classification_x[-1].append(accuracy_x)
                     self.classification_y[-1].append(now_y)
                     last_y = now_y
-                except BaseException:
+                except BaseException as e:
+                    logging.debug(str(e))
                     classification_reason.append(0)
                     self.classification_x.append([])
                     self.classification_y.append([])
@@ -1147,8 +1152,8 @@ class ExpComputing(ExpFuncInit, metaclass=ABCMeta):
             if allow_original_value and y_value in y:  # 如果已经计算过
                 num = y.index(y_value)
                 return x[num]
-        finally:
-            pass
+        except BaseException as e:
+            logging.warning(str(e))
         iter_interval = [[self.start, self.end]]  # 准备迭代的列表
         middle_list = []
         middle_list_deviation = []
@@ -1261,7 +1266,8 @@ class ExpComputing(ExpFuncInit, metaclass=ABCMeta):
                         ):
                             middle = None
                         break
-                except BaseException:
+                except BaseException as e:
+                    logging.debug(str(e))
                     break
             else:  # 证明没有break
                 no_break = True
@@ -1472,18 +1478,18 @@ class ExpProperty(ExpFuncInit, metaclass=ABCMeta):
             try:
                 for i in periodic[1][1:]:
                     answer.append(f"可能的最小正周期:{i}")
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
             try:
                 for i in symmetry_axis[1][1:]:
                     answer.append(f"可能的对称轴:{i}")
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
             try:
                 for i in symmetry_center[1][1:]:
                     answer.append(f"可能的对称中心:{i}")
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
 
         return answer
 
@@ -1515,8 +1521,8 @@ class ExpProperty(ExpFuncInit, metaclass=ABCMeta):
                     if a:
                         possible_cycle.append(round(a, self.accuracy))
                 possible_cycle_list.extend(list(set(possible_cycle)))  # 不是append
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
             start += span
 
         possible_cycle = []  # a的可能列表
@@ -1563,8 +1569,8 @@ class ExpProperty(ExpFuncInit, metaclass=ABCMeta):
                     if a:
                         possible_symmetry_axis.append(round(a, self.accuracy))
                 possible_symmetry_axis_list.extend(list(set(possible_symmetry_axis)))
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
             start += span
 
         possible_symmetry_axis = []  # a的可能列表
@@ -1604,8 +1610,8 @@ class ExpProperty(ExpFuncInit, metaclass=ABCMeta):
                 y = self(start)
                 x = start
                 coordinate_points.append((x, y))
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
             start += span
         possible_center_list = []
 
@@ -1706,8 +1712,8 @@ class ExpCheck(ExpFuncInit, metaclass=ABCMeta):
                 last_y = round(self(start + parameters), self.accuracy)
                 if now_y != last_y:
                     result = False
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
             start += span
         result_key = {True: "是", False: "不是"}
         return result, f"{self}的周期{result_key[result]}{parameters}"
@@ -1733,8 +1739,8 @@ class ExpCheck(ExpFuncInit, metaclass=ABCMeta):
                 last_y = round(self(parameters - start), self.accuracy)
                 if now_y != last_y:
                     result = False
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
             start += span
         result_key = {True: "是", False: "不是"}
         return result, f"{self}的对称轴{result_key[result]}{parameters}"
@@ -1762,8 +1768,8 @@ class ExpCheck(ExpFuncInit, metaclass=ABCMeta):
                 last_y = round(self(2 * parameters[0] - start), self.accuracy)
                 if round((now_y + last_y) / 2, self.accuracy) != parameters[1]:
                     result = False
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
             start += span
         result_key = {True: "是", False: "不是"}
         return result, f"{self}的对称中心{result_key[result]}{parameters}"

+ 10 - 7
gitrepo/gui.py

@@ -2,6 +2,7 @@ import time
 import threading
 import tkinter
 import os
+import logging
 
 import tkinter.messagebox
 from tkinter import ttk
@@ -10,7 +11,9 @@ from tkinter.scrolledtext import ScrolledText
 
 import gitrepo.template
 from gitrepo import controller
-from system import exception_catch
+from system import exception_catch, basicConfig
+
+logging.basicConfig(**basicConfig)
 
 
 class UIAPI:
@@ -115,8 +118,8 @@ class UIAPI:
                     if show_screen:
                         try:
                             cli_screen.update()
-                        finally:
-                            pass
+                        except BaseException as e:
+                            logging.warning(str(e))
                     assert time.time() - start >= break_time != 0
                     assert break_time == 0 and start == 0
                 except AssertionError:
@@ -393,8 +396,8 @@ class UIAPI:
         try:  # 窗口可能已经关闭
             repo_dir.delete(0, tkinter.END)
             repo_dir.insert(tkinter.END, *dir_list)
-        finally:
-            pass
+        except BaseException as e:
+            logging.warning(str(e))
         last_name = name
 
     @staticmethod
@@ -928,8 +931,8 @@ class API(UIAPI):
         try:
             del file_list[API.get_file_box_index()]
             API.update_file_box_gui()
-        finally:
-            pass
+        except BaseException as e:
+            logging.warning(str(e))
 
     @staticmethod
     @exception_catch()

+ 0 - 1
gitrepo/template.py

@@ -402,7 +402,6 @@ class RemoteClasses(GitBase, metaclass=ABCMeta):
                     branch = f"{local}"  # 要去掉冒号
             else:
                 if remote_branch != "HEAD":
-                    # git push <远程主机名> <本地分支名>:<远程分支名>
                     branch = f"{remote_branch}:{local}"
                 else:
                     branch = f"{remote_branch}"

+ 23 - 20
machinelearning/template.py

@@ -5,6 +5,7 @@ from abc import ABCMeta, abstractmethod
 from os import getcwd, mkdir
 from os.path import split as path_split, splitext, basename, exists
 import os
+import logging
 
 from sklearn.svm import SVC, SVR  # SVC是svm分类,SVR是svm回归
 from sklearn.cluster import KMeans, AgglomerativeClustering, DBSCAN
@@ -40,8 +41,9 @@ from pyecharts import options as opts
 from pyecharts.components import Image
 from pyecharts.globals import CurrentConfig
 
-from system import plugin_class_loading, get_path, plugin_func_loading
+from system import plugin_class_loading, get_path, plugin_func_loading, basicConfig
 
+logging.basicConfig(**basicConfig)
 CurrentConfig.ONLINE_HOST = f"{getcwd()}{os.sep}assets{os.sep}"
 
 
@@ -846,15 +848,15 @@ class ViewData(ToPyebase):  # 绘制预测型热力图
             x_testdata = self.x_testdata
             if x_testdata is not None:
                 add_func(x_testdata, f"{x_name}:x测试数据")
-        finally:
-            pass
+        except BaseException as e:
+            logging.warning(str(e))
 
         try:
             y_testdata = self.y_testdata.copy()
             if y_testdata is not None:
                 add_func(y_testdata, f"{x_name}:y测试数据")
-        finally:
-            pass
+        except BaseException as e:
+            logging.warning(str(e))
 
         self.have_fit = True
         if y_traindata is None:
@@ -1089,8 +1091,8 @@ class PredictiveHeatmapBase(ToPyebase):  # 绘制预测型热力图
     def fit_model(self, x_data, *args, **kwargs):
         try:
             self.means = x_data.ravel()
-        finally:
-            pass
+        except BaseException as e:
+            logging.warning(str(e))
         self.have_fit = True
         return "None", "None"
 
@@ -1119,8 +1121,8 @@ class PredictiveHeatmapBase(ToPyebase):  # 绘制预测型热力图
                     if g == np.nan:
                         raise Exception
                     x_means[i] = g
-                finally:
-                    pass
+                except BaseException as e:
+                    logging.warning(str(e))
             get = decision_boundary_func(
                 x_range, x_means, self.learner.predict, class_, data_type
             )
@@ -2125,7 +2127,8 @@ class SelectFromModel(PrepBase):  # 有监督
             self.y_testdata = x_predict.copy()
             self.have_predict = True
             return x_predict, "模型特征工程"
-        except BaseException:
+        except BaseException as e:
+            logging.debug(str(e))
             self.have_predict = True
             return np.array([]), "无结果工程"
 
@@ -2170,8 +2173,8 @@ class SelectFromModel(PrepBase):  # 有监督
         except AttributeError:
             try:
                 make_bar_(self.model.feature_importances_)
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
 
         save = save_dir + rf"{os.sep}模型特征选择.HTML"
         tab.render(save)  # 生成HTML
@@ -3692,8 +3695,8 @@ class Table(TableFisrt):
                 DataFrame(self.ROWS, columns=self.HEADERS).to_csv(
                     save_dir + os.sep + name + ".csv"
                 )
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
         return super().render(path, *args, **kwargs)
 
 
@@ -4033,14 +4036,14 @@ def see_tree(tree_file_dir):
                         "children": [],
                     }
                     continue
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
             try:
                 regex_result = re.findall(link_regex, i)[0]
                 if regex_result[0] != "" and regex_result[1] != "":
                     link_list.append((regex_result[0], regex_result[1]))
-            finally:
-                pass
+            except BaseException as e:
+                logging.warning(str(e))
 
     father_list = []  # 已经有父亲的list
     for i in link_list:
@@ -4049,8 +4052,8 @@ def see_tree(tree_file_dir):
         try:
             node_dict[father]["children"].append(node_dict[son])
             father_list.append(son)
-        finally:
-            pass
+        except BaseException as e:
+            logging.warning(str(e))
 
     father = list(set(node_dict.keys()) - set(father_list))
 

+ 8 - 4
system/__init__.py

@@ -3,8 +3,9 @@ import logging
 
 PATH = os.getcwd()
 LOG_DIR = rf'{PATH}{os.sep}Log{os.sep}log_system.log'
-LOG_FORMAT = '%(asctime)s - %(pathname)s - [%(lineno)d]%(funcName)s  %(message)s'
-logging.basicConfig(filename=LOG_DIR, level=logging.DEBUG, format=LOG_FORMAT)
+LOG_FORMAT = '%(asctime)s - %(pathname)s - %(levelname)s  [%(lineno)d]%(funcName)s  %(message)s'
+basicConfig = dict(filename=LOG_DIR, level=logging.DEBUG, format=LOG_FORMAT)
+logging.basicConfig(**basicConfig)
 
 
 class NoPluginError(Exception):
@@ -25,6 +26,7 @@ def plugin_class_loading(template_path):
                 with open(template, 'r') as f:
                     namespace = {'base': base}
                     exec(f.read().replace('base = None', ''), namespace)
+                logging.info(f'{base.__name__} use plugin success')
                 return namespace[name]
             else:
                 raise NoPluginError
@@ -44,9 +46,11 @@ def exception_catch(*args_catch, **kwargs_catch):
     def catch(func):
         def adorner(*args, **kwargs):
             try:
-                func()
+                return_ = func(*args, **kwargs)
+                logging.debug(f'run  {func.__name__} args:{args}  kwargs:{kwargs} return:{return_}')
+                return return_
             except BaseException as e:
-                logging.error(str(e))
+                logging.error(f'{e}  {func.__name__} args:{args}  kwargs:{kwargs}')
                 assert func.__name__.endswith('_gui'), str(e)
         return adorner
     return catch

+ 7 - 1
system/controller.py

@@ -1,5 +1,6 @@
 import os
 import shutil
+from system import LOG_DIR
 
 PATH = os.getcwd() + rf'{os.sep}template'
 
@@ -12,7 +13,7 @@ class ConflictError(BaseException):
     pass
 
 
-class Plugin:
+class Systemctl:
     def __init__(self):
         self.dir_list = []
         self.plugin_list = []
@@ -66,3 +67,8 @@ class Plugin:
         with open(f'{PATH}{os.sep}{self.plugin_list[index]}') as f:
             code = f.read() + '\n[END]'
         return code, self.plugin_list[index]
+
+    def show_log(self):
+        with open(LOG_DIR) as f:
+            log = f.read()
+        return log

+ 41 - 9
system/gui.py

@@ -3,10 +3,10 @@ from newtkinter import askopenfilename
 from tkinter.messagebox import showwarning, askokcancel
 from tkinter.scrolledtext import ScrolledText
 
-from system.controller import Plugin, NamingError, ConflictError
+from system.controller import Systemctl, NamingError, ConflictError
 
 SCREEN = tkinter.Tk()
-plugin = Plugin()
+systemctl = Systemctl()
 SCREEN.title("插件管理")
 SCREEN.resizable(width=False, height=False)
 SCREEN.geometry(f"+10+10")
@@ -51,12 +51,12 @@ def code_window(name):
 
 def get_dir():
     plugin_dir_box.delete(0, tkinter.END)
-    plugin_dir_box.insert(0, *plugin.get_dir())
+    plugin_dir_box.insert(0, *systemctl.get_dir())
 
 
 def get_all_plugin():
     plugin_box.delete(0, tkinter.END)
-    plugin_box.insert(0, *plugin.get_all_plugin())
+    plugin_box.insert(0, *systemctl.get_all_plugin())
 
 
 def get_plugin():
@@ -65,19 +65,19 @@ def get_plugin():
     except IndexError:
         return False
     plugin_box.delete(0, tkinter.END)
-    plugin_box.insert(0, *plugin.get_plugin(index))
+    plugin_box.insert(0, *systemctl.get_plugin(index))
 
 
 def add_plugin():
     index = plugin_dir_box.curselection()[0]
     plugin_dir = askopenfilename(title="选择插件文件", filetypes=[("Python", ".py")])
     try:
-        plugin_list = plugin.add_plugin(index, plugin_dir)
+        plugin_list = systemctl.add_plugin(index, plugin_dir)
     except NamingError:
         showwarning("文件错误", "插件命名错误,命名规则:\ntemplate_[类\\方法名].py")
     except ConflictError:
         if askokcancel("提示", f"已经存在插件,是否需要尝试合并插件?\n[合并失败将产生不可逆的后果]"):
-            plugin.merge_plugin(index, plugin_dir)
+            systemctl.merge_plugin(index, plugin_dir)
     except BaseException as e:
         showwarning("文件错误", f"插件导入遇到了未知错误:\n{e}")
     else:
@@ -88,7 +88,7 @@ def add_plugin():
 def del_plugin():
     index = plugin_box.curselection()[0]
     try:
-        plugin_list = plugin.del_plugin(index)
+        plugin_list = systemctl.del_plugin(index)
         plugin_box.delete(0, tkinter.END)
         plugin_box.insert(0, *plugin_list)
     finally:
@@ -98,12 +98,20 @@ def del_plugin():
 def show_plugin():
     index = plugin_box.curselection()[0]
     try:
-        code, name = plugin.show_plugin(index)
+        code, name = systemctl.show_plugin(index)
         code_window(name)[0].insert(tkinter.END, code)
     finally:
         pass
 
 
+def show_log():
+    try:
+        log = systemctl.show_log()
+        code_window('日志信息')[0].insert(tkinter.END, log)
+    finally:
+        pass
+
+
 def system_main():
     global SCREEN
     SCREEN.mainloop()
@@ -224,3 +232,27 @@ row += 5
         height=gui_height,
     ).grid(column=column + 2, row=row, sticky=tkinter.E + tkinter.W)
 )
+(
+    tkinter.Label(
+        SCREEN,
+        text="【日志管理】",
+        bg=bg_color,
+        fg=word_color,
+        font=FONT,
+        width=gui_width * 3,
+        height=gui_height,
+    ).grid(column=column, row=row, columnspan=3)
+)
+row += 1
+(
+    tkinter.Button(
+        SCREEN,
+        bg=botton_color,
+        fg=word_color,
+        command=show_log,
+        text="查看日记",
+        font=FONT,
+        width=gui_width,
+        height=gui_height,
+    ).grid(column=column, columnspan=3, row=row, sticky=tkinter.E + tkinter.W)
+)