Fix console daemon connect

This commit is contained in:
Andrew Resch 2008-12-11 09:07:56 +00:00
parent c2c93f00de
commit 7171df62eb
1 changed files with 21 additions and 1 deletions

View File

@ -90,11 +90,31 @@ def load_commands(command_dir, exclude=[]):
except OSError, e:
return {}
def get_localhost_auth_uri(uri):
"""
Grabs the localclient auth line from the 'auth' file and creates a localhost uri
:param uri: the uri to add the authentication info to
:returns: a localhost uri containing authentication information or None if the information is not available
"""
import deluge.configmanager
auth_file = deluge.configmanager.get_config_dir("auth")
if os.path.exists(auth_file):
import urlparse
u = urlparse.urlsplit(uri)
for line in open(auth_file):
username, password = line.split(":")
if username == "localclient":
# We use '127.0.0.1' in place of 'localhost' just incase this isn't defined properly
hostname = u.hostname.replace("localhost", "127.0.0.1")
return u.scheme + "://" + username + ":" + password + "@" + hostname + ":" + str(u.port)
return None
class ConsoleUI(object):
prompt = '>>> '
def __init__(self, args=None):
client.set_core_uri("http://localhost:58846")
client.set_core_uri(get_localhost_auth_uri("http://localhost:58846"))
self._commands = load_commands(os.path.join(UI_PATH, 'commands'))
if args:
self.precmd()