Update public source
This commit is contained in:
+94
-32
@@ -36,6 +36,8 @@ class UnsupportedSecurityError(WiFiConnectionError):
|
|||||||
|
|
||||||
class NetworkRestoreError(WiFiConnectionError):
|
class NetworkRestoreError(WiFiConnectionError):
|
||||||
pass
|
pass
|
||||||
|
class NetworkCleanupError(WiFiConnectionError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
@@ -495,22 +497,45 @@ class WiFiConnectionService:
|
|||||||
*arguments
|
*arguments
|
||||||
)
|
)
|
||||||
|
|
||||||
output = self._nmcli(
|
try:
|
||||||
"--get-values",
|
|
||||||
"connection.uuid",
|
|
||||||
"connection",
|
|
||||||
"show",
|
|
||||||
profile_name
|
|
||||||
)
|
|
||||||
|
|
||||||
if not re.fullmatch(
|
output = self._nmcli(
|
||||||
r"[0-9a-fA-F-]{36}",
|
"--get-values",
|
||||||
output
|
"connection.uuid",
|
||||||
):
|
"connection",
|
||||||
raise WiFiConnectionError(
|
"show",
|
||||||
"NetworkManager created a profile but returned an invalid UUID."
|
profile_name
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not re.fullmatch(
|
||||||
|
r"[0-9a-fA-F-]{36}",
|
||||||
|
output
|
||||||
|
):
|
||||||
|
raise WiFiConnectionError(
|
||||||
|
"NetworkManager created a profile but returned an invalid UUID."
|
||||||
|
)
|
||||||
|
|
||||||
|
except Exception as error:
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
self._nmcli(
|
||||||
|
"connection",
|
||||||
|
"delete",
|
||||||
|
"id",
|
||||||
|
profile_name
|
||||||
|
)
|
||||||
|
|
||||||
|
except NetworkCommandError as cleanup_error:
|
||||||
|
|
||||||
|
raise WiFiConnectionError(
|
||||||
|
"NetworkManager created a temporary profile, but its UUID "
|
||||||
|
"could not be obtained and the profile could not be deleted: "
|
||||||
|
f"{cleanup_error}"
|
||||||
|
) from error
|
||||||
|
|
||||||
|
raise
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -644,17 +669,12 @@ class WiFiConnectionService:
|
|||||||
if not profile_uuid:
|
if not profile_uuid:
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
self._nmcli(
|
||||||
|
"connection",
|
||||||
self._nmcli(
|
"delete",
|
||||||
"connection",
|
"uuid",
|
||||||
"delete",
|
profile_uuid
|
||||||
"uuid",
|
)
|
||||||
profile_uuid
|
|
||||||
)
|
|
||||||
|
|
||||||
except NetworkCommandError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def connect(
|
def connect(
|
||||||
self,
|
self,
|
||||||
@@ -682,11 +702,21 @@ class WiFiConnectionService:
|
|||||||
password
|
password
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception:
|
except Exception as connection_error:
|
||||||
|
|
||||||
self._delete_profile(
|
try:
|
||||||
profile_uuid
|
|
||||||
)
|
self._delete_profile(
|
||||||
|
profile_uuid
|
||||||
|
)
|
||||||
|
|
||||||
|
except NetworkCommandError as cleanup_error:
|
||||||
|
|
||||||
|
raise NetworkCleanupError(
|
||||||
|
"Wi-Fi connection failed: "
|
||||||
|
f"{connection_error}. The temporary profile could not be deleted: "
|
||||||
|
f"{cleanup_error}"
|
||||||
|
) from connection_error
|
||||||
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@@ -729,6 +759,7 @@ class WiFiConnectionService:
|
|||||||
success = False
|
success = False
|
||||||
error_message = None
|
error_message = None
|
||||||
restore_error = None
|
restore_error = None
|
||||||
|
cleanup_error = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
@@ -781,8 +812,12 @@ class WiFiConnectionService:
|
|||||||
profile_uuid
|
profile_uuid
|
||||||
)
|
)
|
||||||
|
|
||||||
except NetworkCommandError:
|
except NetworkCommandError as error:
|
||||||
pass
|
|
||||||
|
if success:
|
||||||
|
restore_error = str(
|
||||||
|
error
|
||||||
|
)
|
||||||
|
|
||||||
except NetworkCommandError as error:
|
except NetworkCommandError as error:
|
||||||
|
|
||||||
@@ -790,12 +825,26 @@ class WiFiConnectionService:
|
|||||||
error
|
error
|
||||||
)
|
)
|
||||||
|
|
||||||
finally:
|
try:
|
||||||
|
|
||||||
self._delete_profile(
|
self._delete_profile(
|
||||||
profile_uuid
|
profile_uuid
|
||||||
)
|
)
|
||||||
|
|
||||||
|
except NetworkCommandError as error:
|
||||||
|
|
||||||
|
cleanup_error = str(
|
||||||
|
error
|
||||||
|
)
|
||||||
|
|
||||||
|
if restore_error and cleanup_error:
|
||||||
|
|
||||||
|
raise NetworkRestoreError(
|
||||||
|
"The Wi-Fi verification attempt finished, but the previous connection "
|
||||||
|
f"could not be restored: {restore_error}. "
|
||||||
|
f"The temporary profile could not be deleted: {cleanup_error}"
|
||||||
|
)
|
||||||
|
|
||||||
if restore_error:
|
if restore_error:
|
||||||
|
|
||||||
raise NetworkRestoreError(
|
raise NetworkRestoreError(
|
||||||
@@ -803,10 +852,23 @@ class WiFiConnectionService:
|
|||||||
f"could not be restored: {restore_error}"
|
f"could not be restored: {restore_error}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if cleanup_error:
|
||||||
|
|
||||||
|
verification_error = (
|
||||||
|
f"Password verification failed: {error_message}. "
|
||||||
|
if error_message else ""
|
||||||
|
)
|
||||||
|
|
||||||
|
raise NetworkCleanupError(
|
||||||
|
f"{verification_error}"
|
||||||
|
"The temporary Wi-Fi profile could not be deleted: "
|
||||||
|
f"{cleanup_error}"
|
||||||
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"success": success,
|
"success": success,
|
||||||
"interface": interface,
|
"interface": interface,
|
||||||
"bssid": access_point.bssid,
|
"bssid": access_point.bssid,
|
||||||
"ssid": access_point.ssid,
|
"ssid": access_point.ssid,
|
||||||
"error": error_message
|
"error": error_message
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user