Have the client module automatically try to get the localhost creds in connect()

This commit is contained in:
Andrew Resch 2009-02-10 08:40:05 +00:00
parent 9175ac16fd
commit be68515fdc
2 changed files with 8 additions and 7 deletions

View File

@ -146,6 +146,7 @@ class DelugeRPCProtocol(Protocol):
if message_type == RPC_EVENT: if message_type == RPC_EVENT:
event = request[1] event = request[1]
#log.debug("Received RPCEvent: %s", event)
# A RPCEvent was received from the daemon so run any handlers # A RPCEvent was received from the daemon so run any handlers
# associated with it. # associated with it.
if event in self.factory.event_handlers: if event in self.factory.event_handlers:
@ -463,6 +464,12 @@ class Client(object):
:returns: a Deferred object that will be called once the connection :returns: a Deferred object that will be called once the connection
has been established or fails has been established or fails
""" """
if not username and host in ("127.0.0.1", "localhost"):
# No username was provided and it's the localhost, so we can try
# to grab the credentials from the auth file.
import common
username, password = common.get_localhost_auth()
self._daemon_proxy = DaemonSSLProxy(self.__event_handlers) self._daemon_proxy = DaemonSSLProxy(self.__event_handlers)
self._daemon_proxy.set_disconnect_callback(self.__on_disconnect) self._daemon_proxy.set_disconnect_callback(self.__on_disconnect)
d = self._daemon_proxy.connect(host, port, username, password) d = self._daemon_proxy.connect(host, port, username, password)

View File

@ -282,9 +282,6 @@ class ConnectionManager(component.Component):
client.daemon.info().addCallback(on_info) client.daemon.info().addCallback(on_info)
continue continue
if host in ("127.0.0.1", "localhost") and not user:
# We need to get the localhost creds
user, password = deluge.ui.common.get_localhost_auth()
# Create a new Client instance # Create a new Client instance
c = deluge.ui.client.Client() c = deluge.ui.client.Client()
d = c.connect(host, port, user, password) d = c.connect(host, port, user, password)
@ -393,10 +390,7 @@ class ConnectionManager(component.Component):
port = model[row][HOSTLIST_COL_PORT] port = model[row][HOSTLIST_COL_PORT]
user = model[row][HOSTLIST_COL_USER] user = model[row][HOSTLIST_COL_USER]
password = model[row][HOSTLIST_COL_PASS] password = model[row][HOSTLIST_COL_PASS]
if not user and host in ("127.0.0.1", "localhost"):
# This is a localhost connection with no username, so lets try to
# get the localclient creds from the auth file.
user, password = deluge.ui.common.get_localhost_auth()
client.connect(host, port, user, password).addCallback(self.__on_connected, host_id) client.connect(host, port, user, password).addCallback(self.__on_connected, host_id)
self.connection_manager.response(gtk.RESPONSE_OK) self.connection_manager.response(gtk.RESPONSE_OK)