1
0
Fork 0
mirror of https://github.com/borgbase/vorta synced 2024-12-21 23:33:13 +00:00

Remove support for deprecated macOS XML wifi list. (#868)

* Use pytest-cov plugin to avoid hangers and subproc issues.
This commit is contained in:
Manu 2021-02-18 13:50:58 +08:00 committed by GitHub
parent bd0a1b8f4d
commit 9a4bbf0d65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 48 deletions

View file

@ -32,7 +32,7 @@ jobs:
brew install openssl readline xz borgbackup
- name: Install Vorta
run: |
pip install .
pip install -e .
pip install -r requirements.d/dev.txt
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v1
@ -40,11 +40,11 @@ jobs:
if: runner.os == 'Linux'
run: |
xvfb-run --server-args="-screen 0 1024x768x24+32" \
-a dbus-run-session -- coverage run -m pytest
-a dbus-run-session -- pytest --cov=vorta
- name: Test with pytest (macOS)
if: runner.os == 'macOS'
run: |
coverage run -m pytest
pytest --cov=vorta
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
env:

View file

@ -3,6 +3,7 @@ flake8
pyinstaller
pylint
pytest
pytest-cov
pytest-faulthandler
pytest-mock
pytest-qt

View file

@ -28,7 +28,7 @@ def get_current_wifi(self) -> Optional[str]:
"""Get current SSID or None if Wifi is off."""
raise NotImplementedError()
def get_known_wifis(self) -> Optional[List['SystemWifiInfo']]:
def get_known_wifis(self) -> List['SystemWifiInfo']:
"""Get WiFi networks known to system."""
raise NotImplementedError()
@ -50,5 +50,5 @@ def is_network_metered(self) -> bool:
def get_current_wifi(self) -> Optional[str]:
pass
def get_known_wifis(self) -> Optional[List['SystemWifiInfo']]:
pass
def get_known_wifis(self) -> List['SystemWifiInfo']:
return []

View file

@ -1,9 +1,6 @@
import plistlib
import subprocess
import xml
from typing import Optional, Iterator
from peewee import format_date_time
from datetime import datetime as dt
from vorta.log import logger
from vorta.network_status.abc import NetworkStatusMonitor, SystemWifiInfo
@ -29,30 +26,16 @@ def get_current_wifi(self) -> Optional[str]:
return split_line[1].strip()
def get_known_wifis(self):
from vorta.models import WifiSettingModel
plist_path = '/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist'
"""
Listing all known Wifi networks isn't possible any more from macOS 11. Instead we
just return the current Wifi.
"""
wifis = []
current_wifi = self.get_current_wifi()
if current_wifi is not None:
wifis.append(SystemWifiInfo(ssid=current_wifi, last_connected=dt.now()))
try:
plist_file = open(plist_path, 'rb')
wifis = plistlib.load(plist_file).get('KnownNetworks')
except xml.parsers.expat.ExpatError:
logger.error('Unable to parse list of Wifi networks.')
return None
result = []
if wifis is not None:
for wifi in wifis.values():
ssid = wifi.get('SSIDString', None)
if ssid is None:
continue
last_connected = wifi.get('LastConnected', None) or wifi.get('LastAutoJoinAt', None)
if isinstance(last_connected, str): # TODO: Maybe not needed any more?
last_connected = format_date_time(last_connected, WifiSettingModel.last_connected.formats)
result.append(SystemWifiInfo(ssid=ssid, last_connected=last_connected))
return result
return wifis
def get_network_devices() -> Iterator[str]:

View file

@ -39,14 +39,14 @@ def get_current_wifi(self) -> Optional[str]:
logger.exception("Failed to get currently connected WiFi network, assuming none")
return None
def get_known_wifis(self) -> Optional[List[SystemWifiInfo]]:
def get_known_wifis(self) -> List[SystemWifiInfo]:
wifis = []
try:
connections_paths = self._nm.get_connections_paths()
except DBusException:
logger.exception("Failed to list connections")
return None
return wifis
wifis = []
for connection_path in connections_paths:
try:
settings = self._nm.get_settings(connection_path)

View file

@ -199,33 +199,31 @@ def get_asset(path):
def get_sorted_wifis(profile):
"""Get SSIDs from OS and merge with settings in DB."""
"""
Get Wifi networks known to the OS (only current one on macOS) and
merge with networks from other profiles. Update last connected time.
"""
from vorta.models import WifiSettingModel
# Pull networks known to OS and all other backup profiles
system_wifis = get_network_status_monitor().get_known_wifis()
if system_wifis is None:
# Don't show any networks if we can't get the current list
return []
from_other_profiles = WifiSettingModel.select() \
.where(WifiSettingModel.profile != profile.id).execute()
for wifi in system_wifis:
for wifi in list(from_other_profiles) + system_wifis:
db_wifi, created = WifiSettingModel.get_or_create(
ssid=wifi.ssid,
profile=profile.id,
defaults={'last_connected': wifi.last_connected, 'allowed': True}
)
# update last connected time
# Update last connected time
if not created and db_wifi.last_connected != wifi.last_connected:
db_wifi.last_connected = wifi.last_connected
db_wifi.save()
# remove Wifis that were deleted in the system.
deleted_wifis = WifiSettingModel.select() \
.where(WifiSettingModel.ssid.not_in([wifi.ssid for wifi in system_wifis]))
for wifi in deleted_wifis:
wifi.delete_instance()
# Finally return list of networks and settings for that profile
return WifiSettingModel.select() \
.where(WifiSettingModel.profile == profile.id).order_by(-WifiSettingModel.last_connected)