repair translations
This commit is contained in:
parent
98581132dd
commit
84adc5d941
18 changed files with 304 additions and 122 deletions
|
|
@ -32,9 +32,20 @@ from models.network import (
|
|||
WiFiDevice,
|
||||
)
|
||||
import subprocess
|
||||
from utils.i18n import get_translations, _
|
||||
from utils.i18n import _, _load_translations
|
||||
from babel.support import Translations
|
||||
|
||||
def _extract_value(value):
|
||||
"""Приводит значения D-Bus к примитивам Python."""
|
||||
if isinstance(value, tuple) and len(value) == 2:
|
||||
value = value[1]
|
||||
if isinstance(value, bytes):
|
||||
try:
|
||||
return value.decode("utf-8")
|
||||
except Exception:
|
||||
return value.decode("utf-8", errors="ignore")
|
||||
return value
|
||||
|
||||
class NetworkService:
|
||||
"""Сервис для взаимодействия с NetworkManager через D-Bus.
|
||||
|
||||
|
|
@ -51,7 +62,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 or get_translations()()
|
||||
self.translations = translations or _load_translations("ru")
|
||||
|
||||
async def get_ip_method(self, device: NetworkDeviceGeneric, ip_type: str) -> str:
|
||||
"""Получает метод IP (например, "auto", "manual") для указанного устройства.
|
||||
|
|
@ -152,7 +163,7 @@ class NetworkService:
|
|||
wifi_info = {
|
||||
"ssid": None,
|
||||
"bssid": None,
|
||||
"bitrate": await wifi_device.bitrate,
|
||||
"bitrate": _extract_value(await wifi_device.bitrate),
|
||||
"strength": None,
|
||||
"frequency": None,
|
||||
"mode": None,
|
||||
|
|
@ -160,11 +171,11 @@ class NetworkService:
|
|||
if active_ap != "/":
|
||||
ap = AccessPoint(active_ap, self.system_bus)
|
||||
wifi_info.update({
|
||||
"ssid": await ap.ssid,
|
||||
"bssid": await ap.hw_address,
|
||||
"strength": await ap.strength,
|
||||
"frequency": await ap.frequency,
|
||||
"mode": await ap.mode,
|
||||
"ssid": _extract_value(await ap.ssid),
|
||||
"bssid": _extract_value(await ap.hw_address),
|
||||
"strength": _extract_value(await ap.strength),
|
||||
"frequency": _extract_value(await ap.frequency),
|
||||
"mode": _extract_value(await ap.mode),
|
||||
})
|
||||
return wifi_info
|
||||
|
||||
|
|
@ -209,8 +220,8 @@ class NetworkService:
|
|||
"device_mtu": str(await generic_device.mtu),
|
||||
"ipv4": IPConfig(configurations=await self.get_ip_config(generic_device, "4")),
|
||||
"ipv6": IPConfig(configurations=await self.get_ip_config(generic_device, "6")),
|
||||
"x": initial_positions.get(interface_name, (100, 100))[0],
|
||||
"y": initial_positions.get(interface_name, (100, 100))[1],
|
||||
"container_x": initial_positions.get(interface_name, (100, 100))[0],
|
||||
"container_y": initial_positions.get(interface_name, (100, 100))[1],
|
||||
}
|
||||
|
||||
if device_type == "WIFI":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue