From 9ec66a3521ea0a0e6a273cf6ae0fcabed757c224 Mon Sep 17 00:00:00 2001 From: StNicolay Date: Tue, 3 Jan 2023 11:59:06 +0300 Subject: [PATCH] Renamed src/database into src/db --- src/__init__.py | 8 ++--- src/bot/message_handlers.py | 58 ++++++++++++++++---------------- src/{database => db}/__init__.py | 0 src/{database => db}/add.py | 0 src/{database => db}/change.py | 0 src/{database => db}/delete.py | 0 src/{database => db}/get.py | 0 src/{database => db}/models.py | 0 src/{database => db}/prepare.py | 0 src/encryption/accounts.py | 2 +- src/encryption/master_pass.py | 2 +- 11 files changed, 35 insertions(+), 35 deletions(-) rename src/{database => db}/__init__.py (100%) rename src/{database => db}/add.py (100%) rename src/{database => db}/change.py (100%) rename src/{database => db}/delete.py (100%) rename src/{database => db}/get.py (100%) rename src/{database => db}/models.py (100%) rename src/{database => db}/prepare.py (100%) diff --git a/src/__init__.py b/src/__init__.py index 472ca7c..72c3529 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -7,7 +7,7 @@ from . import ( account_checks, account_parsing, bot, - database, + db, decrypted_account, encryption, generate_password, @@ -19,19 +19,19 @@ __all__ = [ "bot", "decrypted_account", "encryption", - "database", + "db", "generate_password", ] def main() -> None: load_dotenv("./.env") - engine = database.prepare.get_engine( + engine = db.prepare.get_engine( host=os.getenv("DB_HOST"), user=os.getenv("DB_USER"), passwd=os.getenv("DB_PASS"), db=os.getenv("DB_NAME"), ) - database.prepare.prepare(engine) + db.prepare.prepare(engine) bot_ = bot.create_bot(os.getenv("TG_TOKEN"), engine) asyncio.run(bot_.infinity_polling()) diff --git a/src/bot/message_handlers.py b/src/bot/message_handlers.py index fda784f..19fb439 100644 --- a/src/bot/message_handlers.py +++ b/src/bot/message_handlers.py @@ -7,7 +7,7 @@ import telebot from sqlalchemy.future import Engine from telebot.async_telebot import AsyncTeleBot -from .. import database, encryption, generate_password +from .. import db, encryption, generate_password from ..account_checks import ( check_account, check_account_name, @@ -36,7 +36,7 @@ async def get_accounts( mes: Message, ) -> None: await base_handler(bot, mes) - accounts = database.get.get_accounts( + accounts = db.get.get_accounts( engine, mes.from_user.id, to_sort=True, @@ -73,8 +73,8 @@ async def _delete_all2( await base_handler(bot, mes, prev_mes) text = mes.text.strip() if text == "YES": - database.delete.purge_accounts(engine, mes.from_user.id) - database.delete.delete_master_pass(engine, mes.from_user.id) + db.delete.purge_accounts(engine, mes.from_user.id) + db.delete.delete_master_pass(engine, mes.from_user.id) await send_tmp_message( bot, mes.chat.id, @@ -95,7 +95,7 @@ async def set_master_password( mes: Message, ) -> None: await base_handler(bot, mes, None) - if database.get.get_master_pass(engine, mes.from_user.id) is not None: + if db.get.get_master_pass(engine, mes.from_user.id) is not None: return await send_tmp_message( bot, mes.chat.id, @@ -120,7 +120,7 @@ async def _set_master_pass2( mes.from_user.id, text, ) - database.add.add_master_pass(engine, master_password) + db.add.add_master_pass(engine, master_password) await send_tmp_message(bot, mes.chat.id, "Успех") del mes, text @@ -134,7 +134,7 @@ async def reset_master_pass( ) -> None: await base_handler(bot, mes) - if database.get.get_master_pass(engine, mes.from_user.id) is None: + if db.get.get_master_pass(engine, mes.from_user.id) is None: return await send_tmp_message( bot, mes.chat.id, @@ -165,8 +165,8 @@ async def _reset_master_pass2( mes.from_user.id, text, ) - database.delete.purge_accounts(engine, mes.from_user.id) - database.change.change_master_pass(engine, master_password) + db.delete.purge_accounts(engine, mes.from_user.id) + db.change.change_master_pass(engine, master_password) await send_tmp_message( bot, mes.chat.id, "Все ваши аккаунты удалены, а мастер пароль изменён" @@ -178,7 +178,7 @@ async def _reset_master_pass2( async def add_account(bot: AsyncTeleBot, engine: Engine, mes: Message) -> None: await base_handler(bot, mes) - master_password_from_db = database.get.get_master_pass( + master_password_from_db = db.get.get_master_pass( engine, mes.from_user.id, ) @@ -210,7 +210,7 @@ async def _add_account2( mes.chat.id, "Не корректное название аккаунта", ) - if text in database.get.get_accounts(engine, mes.from_user.id): + if text in db.get.get_accounts(engine, mes.from_user.id): return await send_tmp_message( bot, mes.chat.id, "Аккаунт с таким именем уже существует" ) @@ -291,7 +291,7 @@ async def _add_account5( if text == "/cancel": return await send_tmp_message(bot, mes.chat.id, "Успешная отмена") - master_password = database.get.get_master_pass(engine, mes.from_user.id) + master_password = db.get.get_master_pass(engine, mes.from_user.id) if not encryption.master_pass.check_master_pass(text, master_password): return await send_tmp_message( bot, @@ -309,7 +309,7 @@ async def _add_account5( encrypted_account = encryption.accounts.encrypt(account, text) - result = database.add.add_account( + result = db.add.add_account( engine, encrypted_account, ) @@ -328,11 +328,11 @@ async def _add_account5( async def get_account(bot: AsyncTeleBot, engine: Engine, mes: Message) -> None: await base_handler(bot, mes) - master_pass = database.get.get_master_pass(engine, mes.from_user.id) + master_pass = db.get.get_master_pass(engine, mes.from_user.id) if master_pass is None: return await send_tmp_message(bot, mes.chat.id, "Нет мастер пароля") - accounts = database.get.get_accounts( + accounts = db.get.get_accounts( engine, mes.from_user.id, to_sort=True, @@ -355,7 +355,7 @@ async def _get_account2( if text == "/cancel": return await send_tmp_message(bot, mes.chat.id, "Успешная отмена") - if text not in database.get.get_accounts(engine, mes.from_user.id): + if text not in db.get.get_accounts(engine, mes.from_user.id): return await send_tmp_message(bot, mes.chat.id, "Нет такого аккаунта") bot_mes = await bot.send_message(mes.chat.id, "Отправьте мастер пароль") @@ -377,7 +377,7 @@ async def _get_account3( if text == "/cancel": return await send_tmp_message(bot, mes.chat.id, "Успешная отмена") - master_password = database.get.get_master_pass( + master_password = db.get.get_master_pass( engine, mes.from_user.id, ) @@ -389,7 +389,7 @@ async def _get_account3( "Не подходит мастер пароль", ) - account = database.get.get_account_info(engine, mes.from_user.id, name) + account = db.get.get_account_info(engine, mes.from_user.id, name) account = encryption.accounts.decrypt(account, text) await send_deleteable_message( bot, @@ -410,11 +410,11 @@ async def delete_account( ) -> None: await base_handler(bot, mes) - master_pass = database.get.get_master_pass(engine, mes.from_user.id) + master_pass = db.get.get_master_pass(engine, mes.from_user.id) if master_pass is None: return await send_tmp_message(bot, mes.chat.id, "Нет мастер пароля") - accounts = database.get.get_accounts( + accounts = db.get.get_accounts( engine, mes.from_user.id, to_sort=True, @@ -443,7 +443,7 @@ async def _delete_account2( if text == "/cancel": return await send_tmp_message(bot, mes.chat.id, "Успешная отмена") - if text not in database.get.get_accounts(engine, mes.from_user.id): + if text not in db.get.get_accounts(engine, mes.from_user.id): return await send_tmp_message(bot, mes.chat.id, "Нет такого аккаунта") bot_mes = await bot.send_message( @@ -470,7 +470,7 @@ async def _delete_account3( if text != "YES": return await send_tmp_message(bot, mes.chat.id, "Успешная отмена") - database.delete.delete_account(engine, mes.from_user.id, account_name) + db.delete.delete_account(engine, mes.from_user.id, account_name) await send_tmp_message(bot, mes.chat.id, "Аккаунт удалён") @@ -494,7 +494,7 @@ async def help_command(bot: AsyncTeleBot, mes: Message) -> None: async def export(bot: AsyncTeleBot, engine: Engine, mes: Message) -> None: await base_handler(bot, mes) - master_password_from_db = database.get.get_master_pass( + master_password_from_db = db.get.get_master_pass( engine, mes.from_user.id, ) @@ -502,7 +502,7 @@ async def export(bot: AsyncTeleBot, engine: Engine, mes: Message) -> None: if master_password_from_db is None: return await send_tmp_message(bot, mes.chat.id, "Нет мастер пароля") - if not database.get.get_accounts(engine, mes.from_user.id): + if not db.get.get_accounts(engine, mes.from_user.id): return await send_tmp_message(bot, mes.chat.id, "Нет аккаунтов") bot_mes = await bot.send_message(mes.chat.id, "Отправьте мастер пароль") @@ -518,7 +518,7 @@ async def _export2( if text == "/cancel": return await send_tmp_message(bot, mes.chat.id, "Успешная отмена") - master_password = database.get.get_master_pass( + master_password = db.get.get_master_pass( engine, mes.from_user.id, ) @@ -529,7 +529,7 @@ async def _export2( "Не подходит мастер пароль", ) - accounts = database.get.get_all_accounts(engine, mes.from_user.id) + accounts = db.get.get_all_accounts(engine, mes.from_user.id) with ProcessPoolExecutor() as pool: loop = asyncio.get_running_loop() tasks = [] @@ -559,7 +559,7 @@ async def import_accounts( mes: Message, ) -> None: await base_handler(bot, mes) - master_password_from_db = database.get.get_master_pass( + master_password_from_db = db.get.get_master_pass( engine, mes.from_user.id, ) @@ -627,7 +627,7 @@ async def _import3( if text == "/cancel": return await send_tmp_message(bot, mes.chat.id, "Успешная отмена") - master_password = database.get.get_master_pass( + master_password = db.get.get_master_pass( engine, mes.from_user.id, ) @@ -646,7 +646,7 @@ async def _import3( failed.append(account.name) continue account = encryption.accounts.encrypt(account, text) - result = database.add.add_account(engine, account) + result = db.add.add_account(engine, account) if not result: failed.append(account.name) diff --git a/src/database/__init__.py b/src/db/__init__.py similarity index 100% rename from src/database/__init__.py rename to src/db/__init__.py diff --git a/src/database/add.py b/src/db/add.py similarity index 100% rename from src/database/add.py rename to src/db/add.py diff --git a/src/database/change.py b/src/db/change.py similarity index 100% rename from src/database/change.py rename to src/db/change.py diff --git a/src/database/delete.py b/src/db/delete.py similarity index 100% rename from src/database/delete.py rename to src/db/delete.py diff --git a/src/database/get.py b/src/db/get.py similarity index 100% rename from src/database/get.py rename to src/db/get.py diff --git a/src/database/models.py b/src/db/models.py similarity index 100% rename from src/database/models.py rename to src/db/models.py diff --git a/src/database/prepare.py b/src/db/prepare.py similarity index 100% rename from src/database/prepare.py rename to src/db/prepare.py diff --git a/src/encryption/accounts.py b/src/encryption/accounts.py index 0c7d3d4..6e841b6 100644 --- a/src/encryption/accounts.py +++ b/src/encryption/accounts.py @@ -6,7 +6,7 @@ from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC -from ..database.models import Account +from ..db.models import Account from ..decrypted_account import DecryptedAccount diff --git a/src/encryption/master_pass.py b/src/encryption/master_pass.py index 228106e..5cf8ee9 100644 --- a/src/encryption/master_pass.py +++ b/src/encryption/master_pass.py @@ -3,7 +3,7 @@ import os from cryptography.exceptions import InvalidKey from cryptography.hazmat.primitives.kdf.scrypt import Scrypt -from ..database.models import MasterPass +from ..db.models import MasterPass MEMORY_USAGE = 2**14