vorta/src/vorta/network_status/abc.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

61 lines
1.8 KiB
Python
Raw Normal View History

import sys
from datetime import datetime
from typing import List, NamedTuple, Optional
class NetworkStatusMonitor:
@classmethod
def get_network_status_monitor(cls) -> 'NetworkStatusMonitor':
if sys.platform == 'darwin':
from .darwin import DarwinNetworkStatus
2022-08-15 05:21:14 +00:00
return DarwinNetworkStatus()
else:
from .network_manager import (
DBusException,
NetworkManagerMonitor,
UnsupportedException,
)
2022-08-15 05:21:14 +00:00
try:
return NetworkManagerMonitor()
except (UnsupportedException, DBusException):
return NullNetworkStatusMonitor()
def is_network_status_available(self):
"""Is the network status really available, and not just a dummy implementation?"""
return type(self) != NetworkStatusMonitor
def is_network_metered(self) -> bool:
"""Is the currently connected network a metered connection?"""
raise NotImplementedError()
def get_current_wifi(self) -> Optional[str]:
"""Get current SSID or None if Wifi is off."""
raise NotImplementedError()
def get_known_wifis(self) -> List['SystemWifiInfo']:
"""Get WiFi networks known to system."""
raise NotImplementedError()
class SystemWifiInfo(NamedTuple):
ssid: str
last_connected: Optional[datetime]
class NullNetworkStatusMonitor(NetworkStatusMonitor):
"""Dummy implementation, in case we don't have one for current platform."""
def is_network_status_available(self):
return False
def is_network_metered(self) -> bool:
return False
def get_current_wifi(self) -> Optional[str]:
pass
def get_known_wifis(self) -> List['SystemWifiInfo']:
return []