Fix #1281. Show a nice dialog stating that the client is incompatible on the GTK UI.

This commit is contained in:
Pedro Algarvio 2011-05-17 22:50:05 +01:00
parent 6151050ad4
commit e383187796
4 changed files with 25 additions and 15 deletions

View File

@ -55,14 +55,15 @@ except ImportError:
import deluge.component as component
import deluge.configmanager
from deluge.core.authmanager import AUTH_LEVEL_NONE, AUTH_LEVEL_DEFAULT, AUTH_LEVEL_ADMIN
from deluge.core.authmanager import (AUTH_LEVEL_NONE, AUTH_LEVEL_DEFAULT,
AUTH_LEVEL_ADMIN)
from deluge.error import (DelugeError, NotAuthorizedError, _PassthroughError,
IncompatibleClient)
RPC_RESPONSE = 1
RPC_ERROR = 2
RPC_EVENT = 3
RPC_EVENT_AUTH = 4
RPC_EVENT_EXCEPTION = 4
log = logging.getLogger(__name__)
@ -177,7 +178,8 @@ class DelugeRPCProtocol(Protocol):
for call in request:
if len(call) != 4:
log.debug("Received invalid rpc request: number of items in request is %s", len(call))
log.debug("Received invalid rpc request: number of items "
"in request is %s", len(call))
continue
#log.debug("RPCRequest: %s", format_request(call))
reactor.callLater(0, self.dispatch, *call)
@ -198,7 +200,8 @@ class DelugeRPCProtocol(Protocol):
This method is called when a new client connects.
"""
peer = self.transport.getPeer()
log.info("Deluge Client connection made from: %s:%s", peer.host, peer.port)
log.info("Deluge Client connection made from: %s:%s",
peer.host, peer.port)
# Set the initial auth level of this session to AUTH_LEVEL_NONE
self.factory.authorized_sessions[self.transport.sessionno] = AUTH_LEVEL_NONE
@ -264,11 +267,7 @@ class DelugeRPCProtocol(Protocol):
try:
client_version = kwargs.pop('client_version', None)
if client_version is None:
raise IncompatibleClient(
"Your deluge client is not compatible with the daemon. "
"Please upgrade your client to %s" %
deluge.common.get_version()
)
raise IncompatibleClient(deluge.common.get_version())
ret = component.get("AuthManager").authorize(*args, **kwargs)
if ret:
self.factory.authorized_sessions[self.transport.sessionno] = (ret, args[0])
@ -276,7 +275,7 @@ class DelugeRPCProtocol(Protocol):
except Exception, e:
if isinstance(e, _PassthroughError):
self.sendData(
(RPC_EVENT_AUTH, request_id,
(RPC_EVENT_EXCEPTION, request_id,
e.__class__.__name__,
e._args, e._kwargs, args[0])
)

View File

@ -66,7 +66,12 @@ class _PassthroughError(DelugeError):
return inst
class IncompatibleClient(_PassthroughError):
pass
def __init__(self, daemon_version):
self.daemon_version = daemon_version
self.message = _(
"Your deluge client is not compatible with the daemon. "
"Please upgrade your client to %(daemon_version)s"
) % {'daemon_version': self.daemon_version}
class NotAuthorizedError(_PassthroughError):

View File

@ -56,7 +56,7 @@ else:
RPC_RESPONSE = 1
RPC_ERROR = 2
RPC_EVENT = 3
RPC_EVENT_AUTH = 4
RPC_EVENT_EXCEPTION = 4
log = logging.getLogger(__name__)
@ -204,7 +204,7 @@ class DelugeRPCProtocol(Protocol):
if message_type == RPC_RESPONSE:
# Run the callbacks registered with this Deferred object
d.callback(request[2])
elif message_type == RPC_EVENT_AUTH:
elif message_type == RPC_EVENT_EXCEPTION:
# Recreate exception and errback'it
d.errback(getattr(error, request[2])(*request[3], **request[4]))
elif message_type == RPC_ERROR:

View File

@ -48,7 +48,7 @@ from deluge.ui.common import get_localhost_auth
from deluge.ui.client import client
import deluge.ui.client
from deluge.configmanager import ConfigManager
from deluge.error import AuthenticationRequired, BadLoginError
from deluge.error import AuthenticationRequired, BadLoginError, IncompatibleClient
import dialogs
log = logging.getLogger(__name__)
@ -512,7 +512,6 @@ class ConnectionManager(component.Component):
def __on_connected_failed(self, reason, host_id, host, port, user, passwd,
try_counter):
log.debug("Failed to connect: %s", reason.value)
print reason, host_id, host, port, user, passwd, try_counter
if reason.check(AuthenticationRequired, BadLoginError):
log.debug("PasswordRequired exception")
@ -527,6 +526,13 @@ class ConnectionManager(component.Component):
d = dialog.run().addCallback(dialog_finished, host, port, user)
return d
elif reason.trap(IncompatibleClient):
dialog = dialogs.ErrorDialog(
_("Incompatible Client"), reason.value.message
)
return dialog.run()
if try_counter:
log.info("Retrying connection.. Retries left: %s", try_counter)
return reactor.callLater(