Skip to content

Commit

Permalink
Fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Ketchel committed Nov 5, 2024
1 parent bdb4410 commit 9308302
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 23 deletions.
2 changes: 2 additions & 0 deletions wlanpi_core/models/network/wlan/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ class WlanDBUSException(Exception):
class WlanDBUSInterfaceException(WlanDBUSException):
pass


class WlanDBUSInterfaceCreationError(WlanDBUSInterfaceException):
pass


class WDIScanError(WlanDBUSInterfaceException):
pass

Expand Down
7 changes: 5 additions & 2 deletions wlanpi_core/models/network/wlan/wlan_dbus_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
WDIConnectionException,
WDIDisconnectedException,
WDIScanError,
WlanDBUSInterfaceException, WlanDBUSInterfaceCreationError,
WlanDBUSInterfaceCreationError,
WlanDBUSInterfaceException,
)
from wlanpi_core.schemas.network import (
NetworkSetupStatus,
Expand Down Expand Up @@ -63,7 +64,9 @@ def __init__(
)
except dbus.DBusException as exc:
if not str(exc).startswith("fi.w1.wpa_supplicant1.InterfaceUnknown:"):
raise WlanDBUSInterfaceCreationError(f"Interface unknown : {exc}") from exc
raise WlanDBUSInterfaceCreationError(
f"Interface unknown : {exc}"
) from exc
try:
self.interface_dbus_path = self.wpa_supplicant.CreateInterface(
{"Ifname": self.interface_name, "Driver": "nl80211"}
Expand Down
75 changes: 54 additions & 21 deletions wlanpi_core/services/network_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
from enum import Enum
from typing import Optional

from wlanpi_core.models.network.wlan.exceptions import WlanDBUSException, WlanDBUSInterfaceCreationError
from wlanpi_core.models.network.wlan.exceptions import (
WlanDBUSException,
WlanDBUSInterfaceCreationError,
)
from wlanpi_core.models.network.wlan.wlan_dbus import WlanDBUS
from wlanpi_core.models.network.wlan.wlan_dbus_interface import WlanDBUSInterface
from wlanpi_core.models.validation_error import ValidationError
Expand All @@ -24,8 +27,11 @@ async def get_systemd_network_interfaces(timeout: int):
logging.info(f"Available interfaces: {available_interfaces}")
return {"interfaces": available_interfaces}
except WlanDBUSInterfaceCreationError as error:
raise ValidationError("Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}", status_code=400)
raise ValidationError(
"Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}",
status_code=400,
)
except WlanDBUSException as err:
# Need to Split exceptions into validation and actual failures
raise ValidationError(str(err), status_code=400) from err
Expand Down Expand Up @@ -53,8 +59,11 @@ async def get_wireless_network_scan_async(
"nets": await interface_obj.get_network_scan(scan_type, timeout=timeout)
}
except WlanDBUSInterfaceCreationError as error:
raise ValidationError("Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}", status_code=400)
raise ValidationError(
"Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}",
status_code=400,
)
except (WlanDBUSException, ValueError) as err:
# Need to Split exceptions into validation and actual failures
raise ValidationError(str(err), status_code=400) from err
Expand All @@ -75,8 +84,11 @@ async def add_wireless_network(
wlan_config=net_config, remove_others=remove_all_first, timeout=timeout
)
except WlanDBUSInterfaceCreationError as error:
raise ValidationError("Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}", status_code=400)
raise ValidationError(
"Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}",
status_code=400,
)
except ValueError as error:
raise ValidationError(f"{error}", status_code=400)

Expand All @@ -89,8 +101,11 @@ async def get_current_wireless_network_details(interface: str, timeout: int):
wlan_dbus = WlanDBUS()
return wlan_dbus.get_interface(interface).get_current_network_details()
except WlanDBUSInterfaceCreationError as error:
raise ValidationError("Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}", status_code=400)
raise ValidationError(
"Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}",
status_code=400,
)
except WlanDBUSException as err:
raise ValidationError(str(err), status_code=400) from err

Expand All @@ -106,8 +121,11 @@ async def disconnect_wireless_network(
wlan_dbus = WlanDBUS()
return wlan_dbus.get_interface(interface).disconnect()
except WlanDBUSInterfaceCreationError as error:
raise ValidationError("Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}", status_code=400)
raise ValidationError(
"Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}",
status_code=400,
)
except ValueError as error:
raise ValidationError(f"{error}", status_code=400)

Expand All @@ -122,8 +140,11 @@ async def remove_all_networks(
wlan_dbus = WlanDBUS()
return wlan_dbus.get_interface(interface).remove_all_networks()
except WlanDBUSInterfaceCreationError as error:
raise ValidationError("Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}", status_code=400)
raise ValidationError(
"Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}",
status_code=400,
)
except ValueError as error:
raise ValidationError(f"{error}", status_code=400)

Expand All @@ -139,8 +160,11 @@ async def remove_network(
wlan_dbus = WlanDBUS()
return wlan_dbus.get_interface(interface).remove_network(network_id)
except WlanDBUSInterfaceCreationError as error:
raise ValidationError("Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}", status_code=400)
raise ValidationError(
"Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}",
status_code=400,
)
except ValueError as error:
raise ValidationError(f"{error}", status_code=400)

Expand All @@ -156,8 +180,11 @@ async def get_network(
wlan_dbus = WlanDBUS()
return wlan_dbus.get_interface(interface).get_network(network_id)
except WlanDBUSInterfaceCreationError as error:
raise ValidationError("Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}", status_code=400)
raise ValidationError(
"Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}",
status_code=400,
)
except ValueError as error:
raise ValidationError(f"{error}", status_code=400)

Expand All @@ -172,8 +199,11 @@ async def networks(
wlan_dbus = WlanDBUS()
return wlan_dbus.get_interface(interface).networks()
except WlanDBUSInterfaceCreationError as error:
raise ValidationError("Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}", status_code=400)
raise ValidationError(
"Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}",
status_code=400,
)
except ValueError as error:
raise ValidationError(f"{error}", status_code=400)

Expand All @@ -188,7 +218,10 @@ async def current_network(
wlan_dbus = WlanDBUS()
return wlan_dbus.get_interface(interface).current_network()
except WlanDBUSInterfaceCreationError as error:
raise ValidationError("Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}", status_code=400)
raise ValidationError(
"Could not create interface. Check that the requested interface exists.\n"
f"Original error: {str(error)}",
status_code=400,
)
except ValueError as error:
raise ValidationError(f"{error}", status_code=400)

0 comments on commit 9308302

Please sign in to comment.