diff options
author | DjLegolas <djlegolas@protonmail.com> | 2023-06-03 09:16:18 +0200 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2023-11-20 13:36:52 +0100 |
commit | 1989d0de73403dc4569b02478aec333252d2cea8 (patch) | |
tree | f0a799b48ece7be3eeb9b7e58298c2b5f61f85a5 | |
parent | [Core] Support creating v2 torrents (diff) | |
download | deluge-1989d0de73403dc4569b02478aec333252d2cea8.tar.xz deluge-1989d0de73403dc4569b02478aec333252d2cea8.zip |
[UI][Common] Add daemon version check
For new UI features to be added, one should make sure the backend daemon
is supported and add fallback in case it doesn't.
Here we add the ability to get the daemon version from the `Client`
class and also check the version against a desired version.
Closes: https://github.com/deluge-torrent/deluge/pull/427
-rw-r--r-- | deluge/tests/test_client.py | 22 | ||||
-rw-r--r-- | deluge/ui/client.py | 26 |
2 files changed, 45 insertions, 3 deletions
diff --git a/deluge/tests/test_client.py b/deluge/tests/test_client.py index 5a6727907..763d43c59 100644 --- a/deluge/tests/test_client.py +++ b/deluge/tests/test_client.py @@ -8,7 +8,7 @@ import pytest_twisted 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 @@ -170,3 +170,23 @@ class TestClient: 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_daemon_version_check_min(self): + username, password = get_localhost_auth() + yield client.connect( + 'localhost', self.listen_port, username=username, password=password + ) + + assert client.daemon_version_check_min(get_version()) + assert not client.daemon_version_check_min(f'{get_version()}1') + assert client.daemon_version_check_min('0.1.0') diff --git a/deluge/ui/client.py b/deluge/ui/client.py index 6b657d5ca..0fef66767 100644 --- a/deluge/ui/client.py +++ b/deluge/ui/client.py @@ -15,7 +15,7 @@ from twisted.internet import defer, reactor, ssl 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 @@ -227,6 +227,7 @@ class DelugeRPCClientFactory(ClientFactory): self.daemon.host = None self.daemon.port = None self.daemon.username = None + self.daemon.daemon_version = None self.daemon.connected = False if ( @@ -260,6 +261,7 @@ class DaemonSSLProxy(DaemonProxy): self.host = None self.port = None self.username = None + self.daemon_version = None self.authentication_level = 0 self.connected = False @@ -389,7 +391,7 @@ class DaemonSSLProxy(DaemonProxy): log.debug('__on_connect called') def on_info(daemon_info): - self.daemon_info = daemon_info + self.daemon_version = daemon_info log.debug('Got info from daemon: %s', daemon_info) self.daemon_info_deferred.callback(daemon_info) @@ -741,6 +743,26 @@ class Client: return None + @property + def daemon_version(self) -> str: + """Get the connected daemon version + + Returns: + The daemon version + """ + return self._daemon_proxy.daemon_version if self.connected() else '' + + def daemon_version_check_min(self, min_version=get_version()) -> bool: + """Check connected daemon against a minimum version. + + Returns: + If connected daemon meets minimum version requirement. + """ + if not (self.daemon_version and min_version): + return False + + return VersionSplit(self.daemon_version) >= VersionSplit(min_version) + def register_event_handler(self, event, handler): """ Registers a handler that will be called when an event is received from the daemon. |