Edit depends call in i18n
This commit is contained in:
parent
9f0ab4ae5a
commit
a13636ca49
8 changed files with 52 additions and 53 deletions
|
|
@ -18,7 +18,6 @@
|
|||
"""
|
||||
import os
|
||||
import logging
|
||||
from fastapi import Depends
|
||||
import netifaces
|
||||
from netaddr import IPNetwork
|
||||
from utils.i18n import get_translations, _
|
||||
|
|
@ -45,7 +44,7 @@ class NetworkScanner:
|
|||
вывода информации о клиентах.
|
||||
"""
|
||||
|
||||
def __init__(self, interface=None, translations: Translations = Depends(get_translations())):
|
||||
def __init__(self, interface=None, translations: Translations = None):
|
||||
"""Инициализация параметров сетевого сканера.
|
||||
|
||||
Args:
|
||||
|
|
@ -55,7 +54,7 @@ class NetworkScanner:
|
|||
|
||||
Инициализирует интерфейс, информацию об IP-адресах и локальный MAC-адрес.
|
||||
"""
|
||||
self.translations = translations
|
||||
self.translations = translations or get_translations()()
|
||||
self.interface = None
|
||||
self.ip_info = []
|
||||
self.networks = []
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
from jose import JWTError, jwt
|
||||
from datetime import datetime, timedelta
|
||||
from fastapi import HTTPException, Depends, Request
|
||||
from fastapi import HTTPException, Depends
|
||||
from fastapi.security import OAuth2PasswordBearer
|
||||
from models.auth import UserCreate, UserLogin, UserResponse, Token
|
||||
from storage.json_storage import JsonStorage
|
||||
|
|
@ -35,10 +35,10 @@ oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/auth/login")
|
|||
class AuthService:
|
||||
"""Сервис для регистрации, авторизации и управления сессиями"""
|
||||
|
||||
def __init__(self, translations: Translations = Depends(get_translations())):
|
||||
def __init__(self, translations: Optional[Translations] = None):
|
||||
self.storage = JsonStorage()
|
||||
self.session_storage = SessionStorage()
|
||||
self.translations = translations
|
||||
self.translations = translations or get_translations()()
|
||||
|
||||
def create_access_token(self, data: dict) -> str:
|
||||
"""Создаёт токен"""
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import logging
|
|||
from typing import Tuple, Optional
|
||||
from utils.i18n import get_translations, _
|
||||
from babel.support import Translations
|
||||
from fastapi import Depends
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -37,13 +36,7 @@ class WifiConnectionService:
|
|||
Автоматически определяет доступный Wi-Fi-интерфейс и сохраняет его имя.
|
||||
"""
|
||||
self.interface = self._get_wifi_interface()
|
||||
if translations is None:
|
||||
try:
|
||||
self.translations = Translations.load("locales", ["ru"], "messages")
|
||||
except Exception:
|
||||
self.translations = Translations()
|
||||
else:
|
||||
self.translations = translations
|
||||
self.translations = translations or get_translations()()
|
||||
|
||||
def _get_wifi_interface(self) -> str:
|
||||
"""Автоматически определяет Wi-Fi-интерфейс.
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ from models.network import (
|
|||
import subprocess
|
||||
from utils.i18n import get_translations, _
|
||||
from babel.support import Translations
|
||||
from fastapi import Depends
|
||||
|
||||
class NetworkService:
|
||||
"""Сервис для взаимодействия с NetworkManager через D-Bus.
|
||||
|
|
@ -43,7 +42,7 @@ class NetworkService:
|
|||
их конфигурациях IP, Wi-Fi и состояниях.
|
||||
"""
|
||||
|
||||
def __init__(self, translations: Translations = Depends(get_translations())):
|
||||
def __init__(self, translations: Translations = None):
|
||||
"""Инициализирует сервис NetworkManager.
|
||||
|
||||
Устанавливает системный D-Bus и создаёт объекты для взаимодействия с
|
||||
|
|
@ -52,7 +51,7 @@ class NetworkService:
|
|||
self.system_bus = sd_bus_open_system()
|
||||
self.nm = NetworkManager(self.system_bus)
|
||||
self.nm_settings = NetworkManagerSettings(self.system_bus)
|
||||
self.translations = translations
|
||||
self.translations = translations or get_translations()()
|
||||
|
||||
async def get_ip_method(self, device: NetworkDeviceGeneric, ip_type: str) -> str:
|
||||
"""Получает метод IP (например, "auto", "manual") для указанного устройства.
|
||||
|
|
@ -383,4 +382,4 @@ class NetworkService:
|
|||
NetworkInterfacesContainer: Объект с неактивными интерфейсами и координатами.
|
||||
"""
|
||||
interfaces = await self.get_deactivated_interfaces(initial_positions)
|
||||
return NetworkInterfacesContainer(interfaces=interfaces, container_x=container_x, container_y=container_y)
|
||||
return NetworkInterfacesContainer(interfaces=interfaces, container_x=container_x, container_y=container_y)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ from typing import Optional
|
|||
|
||||
from utils.i18n import get_translations
|
||||
from babel.support import Translations
|
||||
from fastapi import Depends
|
||||
from pathlib import Path
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
|
@ -13,10 +12,10 @@ logger = logging.getLogger(__name__)
|
|||
class SettingsService:
|
||||
"""Сервис для управления настройками и очистки данных сети."""
|
||||
|
||||
def __init__(self, translations: Translations = Depends(get_translations())):
|
||||
def __init__(self, translations: Translations = None):
|
||||
self.subnet_base_path = "storage/subnets"
|
||||
self.wifi_file = "storage/wifi/wifi.json"
|
||||
self.translations = translations
|
||||
self.translations = translations or get_translations()()
|
||||
|
||||
def clear_subnet(self, subnet: Optional[str] = None) -> bool:
|
||||
"""Очищает данные узлов подсети в указанном файле или во всех файлах.
|
||||
|
|
@ -101,4 +100,4 @@ class SettingsService:
|
|||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Error clearing all network data: {str(e)}")
|
||||
raise Exception(self.translations.gettext("Ошибка очистки всех сетевых данных: {error}").format(error=str(e)))
|
||||
raise Exception(self.translations.gettext("Ошибка очистки всех сетевых данных: {error}").format(error=str(e)))
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ from pathlib import Path
|
|||
import json
|
||||
from utils.i18n import get_translations
|
||||
from babel.support import Translations
|
||||
from fastapi import Depends
|
||||
|
||||
# Настройка логирования
|
||||
logging.basicConfig(
|
||||
|
|
@ -34,10 +33,10 @@ class WifiStorage:
|
|||
- Создаёт директорию хранения при инициализации, ведёт логирование путей.
|
||||
- Валидирует структуру при чтении и безопасно записывает JSON с Unicode и отступами.
|
||||
"""
|
||||
def __init__(self, storage_path: str = "storage/wifi/wifi.json", translations: Translations = Depends(get_translations())):
|
||||
def __init__(self, storage_path: str = "storage/wifi/wifi.json", translations: Translations = None):
|
||||
self.storage_file = Path(storage_path)
|
||||
self.storage_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
self.translations = translations
|
||||
self.translations = translations or get_translations()()
|
||||
logger.info(f"Wi-Fi storage initialized at: {self.storage_file.absolute()}")
|
||||
|
||||
def load_notes(self) -> Dict[str, Optional[str]]:
|
||||
|
|
@ -85,15 +84,15 @@ class WifiService:
|
|||
- Кэширование определения вендора.
|
||||
- Сохранение SSID даже без заметок для будущих операций.
|
||||
"""
|
||||
def __init__(self, translations: Translations = Depends(get_translations())):
|
||||
def __init__(self, translations: Translations = None):
|
||||
self.mac_lookup = MacLookup()
|
||||
self.wifi = pywifi.PyWiFi()
|
||||
self.interface = self._get_wifi_interface()
|
||||
if not hasattr(translations, 'gettext'):
|
||||
validated_translations = translations or get_translations()()
|
||||
if not hasattr(validated_translations, "gettext"):
|
||||
logger.warning("Translations object does not support gettext, using fallback")
|
||||
self.translations = Translations.load("utils/locales/en/LC_MESSAGES/services.mo")
|
||||
else:
|
||||
self.translations = translations
|
||||
validated_translations = get_translations()()
|
||||
self.translations = validated_translations
|
||||
self.storage = WifiStorage()
|
||||
|
||||
def _get_wifi_interface(self) -> Optional[object]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue