diff --git a/deluge/ui/console/main.py b/deluge/ui/console/main.py index 1867287da..42dedc3d1 100644 --- a/deluge/ui/console/main.py +++ b/deluge/ui/console/main.py @@ -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()