add lock window function, and did some improvements for the whole structure
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from pathlib import Path
|
||||
from threading import Lock
|
||||
|
||||
|
||||
base_path = Path(__file__).resolve().parent.parent.parent
|
||||
code_dict = [4, 11, 4, 31, 22, 12, 19, 23, 7, 16, 7, 23, 1, 8, 7, 18, 27, 32, 28, 25, 7, 32, 9, 15, 2, 32, 0, 12, 26, 15, 14, 17]
|
||||
salt = ""
|
||||
max_db_number = 10
|
||||
lock = Lock()
|
||||
account = None
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import sqlite3
|
||||
from threading import Lock
|
||||
import time
|
||||
from codes.common import clibs
|
||||
|
||||
@@ -30,10 +29,10 @@ def db_init(db_file):
|
||||
def db_lock(func):
|
||||
def wrapper(*args, **kwargs):
|
||||
try:
|
||||
Lock().acquire(True)
|
||||
clibs.lock.acquire(True)
|
||||
ret = func(*args, **kwargs)
|
||||
finally:
|
||||
Lock().release()
|
||||
clibs.lock.release()
|
||||
return ret
|
||||
return wrapper
|
||||
|
||||
@@ -47,8 +46,7 @@ def db_backup():
|
||||
db_file_backup.write_bytes(db_file.read_bytes())
|
||||
db_dir = clibs.base_path / "assets/database"
|
||||
db_list = [db for db in db_dir.glob("*.db")]
|
||||
print(f"db_list: {sorted(db_list)}")
|
||||
for db in sorted(db_list)[:-clibs.max_db_number]:
|
||||
for db in sorted(db_list)[:-clibs.account["maximum_db_number"]]:
|
||||
db.unlink()
|
||||
|
||||
def db_conn():
|
||||
@@ -61,4 +59,9 @@ def db_conn():
|
||||
cursor.execute("PRAGMA temp_store=memory")
|
||||
cursor.execute("PRAGMA mmap_size=30000000000")
|
||||
cursor.execute("PRAGMA cache_size=200000")
|
||||
return conn, cursor
|
||||
return conn, cursor
|
||||
|
||||
@db_lock
|
||||
def db_close(conn, cursor):
|
||||
cursor.close()
|
||||
conn.close()
|
@@ -3,6 +3,7 @@ import hashlib
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto import Random
|
||||
from Crypto.Util.Padding import pad, unpad
|
||||
from codes.common import clibs
|
||||
|
||||
|
||||
class PassCipher:
|
||||
@@ -25,13 +26,12 @@ class PassCipher:
|
||||
plaintext = unpad(cipher.decrypt(ciphertext), AES.block_size)
|
||||
return plaintext.decode("utf-8")
|
||||
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# salt = "my_secret_salt_string"
|
||||
# cipher = PassCipher(salt)
|
||||
# original_text = "这是一段需要加密的敏感信息"
|
||||
# encrypted_text = cipher.encrypt(original_text)
|
||||
# print(f"加密后的文本: {encrypted_text}")
|
||||
# decrypted_text = cipher.decrypt(encrypted_text)
|
||||
# print(f"解密后的文本: {decrypted_text}")
|
||||
# print(f"加解密是否成功: {original_text == decrypted_text}")
|
||||
@staticmethod
|
||||
def gen_salt(text: str):
|
||||
key = ""
|
||||
passwd = {idx: char for idx, char in enumerate(text * 4)}
|
||||
for idx in range(32):
|
||||
char_i = 0 if ord(passwd[idx]) - clibs.account["code_dict"][idx] < 0 else ord(passwd[idx]) - clibs.account["code_dict"][idx]
|
||||
key += chr(char_i)
|
||||
salt = base64.urlsafe_b64encode(key.encode()).decode()
|
||||
return salt
|
||||
|
@@ -19,8 +19,10 @@ def single_uic(ui_path: str, py_path: str):
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"转换失败: {ui_file}\n{e.stderr}", file=sys.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
def main():
|
||||
ui_path = clibs.base_path / "assets" / "ui"
|
||||
py_path = clibs.base_path / "codes" / "ui"
|
||||
single_uic(str(ui_path), str(py_path))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
Reference in New Issue
Block a user