Pep8
This commit is contained in:
parent
06a5a758a3
commit
58fa7d1ee6
19 changed files with 567 additions and 377 deletions
|
|
@ -25,17 +25,27 @@ class ContainerPositionManager:
|
|||
|
||||
def __init__(self):
|
||||
self.positions: Dict[str, Dict[str, Union[int, bool]]] = {
|
||||
"activation": {"x": 0, "y": 0, "isOpen": False},
|
||||
"deactivation": {"x": 0, "y": 0, "isOpen": False},
|
||||
"activation": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"isOpen": False
|
||||
},
|
||||
"deactivation": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"isOpen": False
|
||||
},
|
||||
}
|
||||
|
||||
def get_position_and_state(self, container_name: str) -> Tuple[int, int, bool]:
|
||||
def get_position_and_state(self,
|
||||
container_name: str) -> Tuple[int, int, bool]:
|
||||
container = self.positions.get(container_name)
|
||||
if not container:
|
||||
raise ValueError(f"Неверное имя контейнера: {container_name}")
|
||||
return container["x"], container["y"], container["isOpen"]
|
||||
|
||||
def update_position(self, container_id: int, x: int, y: int, isOpen: bool) -> None:
|
||||
def update_position(self, container_id: int, x: int, y: int,
|
||||
isOpen: bool) -> None:
|
||||
container_name = "activation" if container_id == 1 else "deactivation"
|
||||
self.positions[container_name] = {"x": x, "y": y, "isOpen": isOpen}
|
||||
|
||||
|
|
@ -52,15 +62,12 @@ async def get_network_data() -> Dict[str, Dict]:
|
|||
network_data = await network_service.get_network_interfaces_container()
|
||||
|
||||
activation_interfaces, deactivation_interfaces = _split_interfaces(
|
||||
network_data.interfaces
|
||||
)
|
||||
network_data.interfaces)
|
||||
|
||||
activation_x, activation_y, activation_is_open = (
|
||||
container_manager.get_position_and_state("activation")
|
||||
)
|
||||
container_manager.get_position_and_state("activation"))
|
||||
deactivation_x, deactivation_y, deactivation_is_open = (
|
||||
container_manager.get_position_and_state("deactivation")
|
||||
)
|
||||
container_manager.get_position_and_state("deactivation"))
|
||||
|
||||
activation = Activation(
|
||||
id=1,
|
||||
|
|
@ -83,16 +90,14 @@ async def get_network_data() -> Dict[str, Dict]:
|
|||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Ошибка в get_network_data: {e}")
|
||||
raise HTTPException(
|
||||
status_code=500, detail="Не удалось получить сетевые данные"
|
||||
)
|
||||
raise HTTPException(status_code=500,
|
||||
detail="Не удалось получить сетевые данные")
|
||||
|
||||
|
||||
def _split_interfaces(
|
||||
interfaces: List[Union[NetworkInterface, WiFiDevice]],
|
||||
) -> Tuple[
|
||||
List[Union[NetworkInterface, WiFiDevice]], List[Union[NetworkInterface, WiFiDevice]]
|
||||
]:
|
||||
) -> Tuple[List[Union[NetworkInterface, WiFiDevice]], List[Union[
|
||||
NetworkInterface, WiFiDevice]]]:
|
||||
"""
|
||||
Разделяет интерфейсы на активные и неактивные
|
||||
"""
|
||||
|
|
@ -107,13 +112,16 @@ def _split_interfaces(
|
|||
|
||||
|
||||
@router.post("/update_container_position")
|
||||
async def update_container_position(data: Dict[str, Union[int, bool]] = Body(...)):
|
||||
async def update_container_position(data: Dict[str, Union[int,
|
||||
bool]] = Body(...)):
|
||||
"""
|
||||
Обновляет позицию и состояние контейнера
|
||||
"""
|
||||
try:
|
||||
|
||||
required_keys = ["container_id", "container_x", "container_y", "isOpen"]
|
||||
required_keys = [
|
||||
"container_id", "container_x", "container_y", "isOpen"
|
||||
]
|
||||
if not all(key in data for key in required_keys):
|
||||
raise ValueError(
|
||||
"Отсутствуют обязательные поля: container_id, container_x, container_y, isOpen"
|
||||
|
|
@ -125,18 +133,18 @@ async def update_container_position(data: Dict[str, Union[int, bool]] = Body(...
|
|||
is_open = data["isOpen"]
|
||||
|
||||
# Проверка типов
|
||||
if (
|
||||
not isinstance(container_id, int)
|
||||
or not isinstance(container_x, int)
|
||||
or not isinstance(container_y, int)
|
||||
or not isinstance(is_open, bool)
|
||||
):
|
||||
if (not isinstance(container_id, int)
|
||||
or not isinstance(container_x, int)
|
||||
or not isinstance(container_y, int)
|
||||
or not isinstance(is_open, bool)):
|
||||
raise ValueError("Неверный тип данных в запросе")
|
||||
|
||||
container_manager.update_position(
|
||||
container_id, container_x, container_y, is_open
|
||||
)
|
||||
return {"success": True, "message": "Позиция и состояние контейнера обновлены"}
|
||||
container_manager.update_position(container_id, container_x,
|
||||
container_y, is_open)
|
||||
return {
|
||||
"success": True,
|
||||
"message": "Позиция и состояние контейнера обновлены"
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Ошибка обновления позиции контейнера: {e}")
|
||||
raise HTTPException(
|
||||
|
|
@ -152,4 +160,5 @@ async def get_hostname():
|
|||
return hostname_info
|
||||
except Exception as e:
|
||||
logger.error(f"Ошибка в get_hostname: {e}")
|
||||
raise HTTPException(status_code=500, detail="Не удалось получить имя хоста")
|
||||
raise HTTPException(status_code=500,
|
||||
detail="Не удалось получить имя хоста")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue