提交一下,准备更换总线通信架构
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from pathlib import Path
|
||||
from threading import Lock
|
||||
import atexit
|
||||
|
||||
|
||||
base_path = Path(__file__).resolve().parent.parent.parent
|
||||
lock = Lock()
|
||||
@@ -10,6 +12,10 @@ avatar = f"{base_path}/assets/media/avatar.jpg"
|
||||
proverb = "佛曰:Time will say~"
|
||||
bg = f"{base_path}/assets/media/bg.jpg"
|
||||
win_width, win_height = 1100, 500
|
||||
conn, cursor = None, None
|
||||
listW_items = ["实用工具", "效率提升", "财务分析"]
|
||||
|
||||
|
||||
def delete_files_in_directory(directory):
|
||||
path = Path(directory)
|
||||
if path.exists() and path.is_dir():
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import sqlite3
|
||||
import time
|
||||
from codes.common import clibs
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def db_init(db_file):
|
||||
@@ -74,7 +73,34 @@ def db_conn():
|
||||
return conn, cursor
|
||||
|
||||
@db_lock
|
||||
def db_close(conn, cursor):
|
||||
cursor.close()
|
||||
conn.close()
|
||||
def db_close():
|
||||
if clibs.cursor is not None:
|
||||
clibs.cursor.close()
|
||||
if clibs.conn is not None:
|
||||
clibs.conn.close()
|
||||
clibs.conn, clibs.cursor = None, None
|
||||
|
||||
@db_lock
|
||||
def db_write_logs(content, module, level="info"):
|
||||
if level.lower() not in ["debug", "info", "warning", "error", "exception"]:
|
||||
level = "unknown"
|
||||
clibs.cursor.execute(f"INSERT INTO logs (level, module, content) VALUES (?, ?, ?)", (level, module, content))
|
||||
|
||||
@db_lock
|
||||
def db_query_logs():
|
||||
...
|
||||
|
||||
@db_lock
|
||||
def db_write_users(username, password_encrypted, salt):
|
||||
clibs.cursor.execute("INSERT INTO users (username, password, salt) VALUES (?, ?, ?)", (username, password_encrypted, salt))
|
||||
|
||||
@db_lock
|
||||
def db_delete_users(username):
|
||||
# clibs.cursor.execute("INSERT INTO users (username, password, salt) VALUES (?, ?, ?)", (username, password_encrypted, salt))
|
||||
...
|
||||
|
||||
@db_lock
|
||||
def db_query_users(username):
|
||||
clibs.cursor.execute(f""" SELECT * FROM users where username = "{username}" """)
|
||||
record = clibs.cursor.fetchall()
|
||||
return record
|
||||
|
||||
15
toolbox/codes/common/exception_handler.py
Normal file
15
toolbox/codes/common/exception_handler.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from functools import wraps
|
||||
from codes.common import db_operation
|
||||
|
||||
def handle_exception(module, stop: bool = False):
|
||||
def exceptions(func):
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except Exception as e:
|
||||
db_operation.db_write_logs(e, module, "exception")
|
||||
if stop:
|
||||
raise e
|
||||
return wrapper
|
||||
return exceptions
|
||||
Reference in New Issue
Block a user