Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI][Common] Add daemon version check #427

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion deluge/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from twisted.internet import defer

from deluge import error
from deluge.common import AUTH_LEVEL_NORMAL, get_localhost_auth
from deluge.common import AUTH_LEVEL_NORMAL, get_localhost_auth, get_version
from deluge.core.authmanager import AUTH_LEVEL_ADMIN
from deluge.ui.client import Client, DaemonSSLProxy, client

Expand Down Expand Up @@ -170,3 +170,23 @@ def on_failure(failure):

d.addCallbacks(self.fail, on_failure)
return d

@pytest_twisted.inlineCallbacks
def test_daemon_version(self):
username, password = get_localhost_auth()
yield client.connect(
'localhost', self.listen_port, username=username, password=password
)

assert client.daemon_version == get_version()

@pytest_twisted.inlineCallbacks
def test_is_daemon_compatible(self):
username, password = get_localhost_auth()
yield client.connect(
'localhost', self.listen_port, username=username, password=password
)

assert client.is_daemon_compatible(get_version())
assert not client.is_daemon_compatible(f'{get_version()}1')
assert client.is_daemon_compatible('0.1.0')
22 changes: 21 additions & 1 deletion deluge/ui/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from twisted.internet.protocol import ClientFactory

from deluge import error
from deluge.common import get_localhost_auth, get_version
from deluge.common import VersionSplit, get_localhost_auth, get_version
from deluge.decorators import deprecated
from deluge.transfer import DelugeTransferProtocol

Expand Down Expand Up @@ -227,6 +227,7 @@ def clientConnectionLost(self, connector, reason): # NOQA: N802
self.daemon.host = None
self.daemon.port = None
self.daemon.username = None
self.daemon.daemon_info = None
self.daemon.connected = False

if (
Expand Down Expand Up @@ -260,6 +261,7 @@ def __init__(self, event_handlers=None):
self.host = None
self.port = None
self.username = None
self.daemon_info = None
self.authentication_level = 0

self.connected = False
Expand Down Expand Up @@ -741,6 +743,24 @@ def connection_info(self):

return None

@property
def daemon_version(self) -> str:
"""
Get the connected daemon version

Returns:
the daemon version
"""
return self._daemon_proxy.daemon_info if self.connected() else ''

def is_daemon_compatible(self, version=get_version()) -> bool:
daemon_version = self.daemon_version

if not (daemon_version and version):
return False

return VersionSplit(daemon_version) >= VersionSplit(version)

def register_event_handler(self, event, handler):
"""
Registers a handler that will be called when an event is received from the daemon.
Expand Down