mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-04 15:43:28 +00:00
Move get_localhost_auth_uri() to ui.common
This commit is contained in:
parent
7171df62eb
commit
2b34f64304
@ -25,8 +25,11 @@
|
||||
|
||||
import os
|
||||
from sha import sha
|
||||
import urlparse
|
||||
|
||||
from deluge import bencode
|
||||
from deluge.log import LOG as log
|
||||
import deluge.configmanager
|
||||
|
||||
class TorrentInfo(object):
|
||||
def __init__(self, filename):
|
||||
@ -116,3 +119,21 @@ def get_torrent_info(filename):
|
||||
"files": files,
|
||||
"info_hash": info_hash
|
||||
}
|
||||
|
||||
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
|
||||
"""
|
||||
auth_file = deluge.configmanager.get_config_dir("auth")
|
||||
if os.path.exists(auth_file):
|
||||
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
|
||||
|
@ -6,6 +6,7 @@ import optparse
|
||||
from deluge.ui.console import UI_PATH
|
||||
from deluge.ui.console.colors import Template, make_style, templates, default_style as style
|
||||
from deluge.ui.client import aclient as client
|
||||
from deluge.ui.common import get_localhost_auth_uri
|
||||
import shlex
|
||||
|
||||
|
||||
@ -90,26 +91,6 @@ 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 = '>>> '
|
||||
|
||||
|
@ -37,6 +37,7 @@ import deluge.component as component
|
||||
import deluge.xmlrpclib as xmlrpclib
|
||||
import deluge.common
|
||||
import deluge.ui.gtkui.common as common
|
||||
from deluge.ui.common import get_localhost_auth_uri
|
||||
from deluge.ui.client import aclient as client
|
||||
from deluge.configmanager import ConfigManager
|
||||
from deluge.log import LOG as log
|
||||
@ -151,7 +152,7 @@ class ConnectionManager(component.Component):
|
||||
if self.gtkui_config["classic_mode"]:
|
||||
self.start_localhost(DEFAULT_PORT)
|
||||
# We need to wait for the host to start before connecting
|
||||
uri = self.get_localhost_auth_uri(DEFAULT_URI)
|
||||
uri = get_localhost_auth_uri(DEFAULT_URI)
|
||||
while not self.test_online_status(uri):
|
||||
time.sleep(0.01)
|
||||
client.set_core_uri(uri)
|
||||
@ -183,7 +184,7 @@ class ConnectionManager(component.Component):
|
||||
while not auth_uri:
|
||||
# We need to keep trying because the daemon may not have been started yet
|
||||
# and the 'auth' file may not have been created
|
||||
auth_uri = self.get_localhost_auth_uri(uri)
|
||||
auth_uri = get_localhost_auth_uri(uri)
|
||||
time.sleep(0.01)
|
||||
|
||||
# We need to wait for the host to start before connecting
|
||||
@ -192,24 +193,6 @@ class ConnectionManager(component.Component):
|
||||
client.set_core_uri(auth_uri)
|
||||
self.hide()
|
||||
|
||||
def get_localhost_auth_uri(self, 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
|
||||
"""
|
||||
auth_file = deluge.configmanager.get_config_dir("auth")
|
||||
if os.path.exists(auth_file):
|
||||
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
|
||||
|
||||
def start(self):
|
||||
if self.gtkui_config["autoconnect"]:
|
||||
# We need to update the autoconnect_host_uri on connection to host
|
||||
@ -258,7 +241,7 @@ class ConnectionManager(component.Component):
|
||||
online = HOSTLIST_STATUS.index("Offline")
|
||||
|
||||
if urlparse.urlsplit(uri).hostname == "localhost" or urlparse.urlsplit(uri).hostname == "127.0.0.1":
|
||||
uri = self.get_localhost_auth_uri(uri)
|
||||
uri = get_localhost_auth_uri(uri)
|
||||
|
||||
if uri == current_uri:
|
||||
online = HOSTLIST_STATUS.index("Connected")
|
||||
@ -366,7 +349,7 @@ class ConnectionManager(component.Component):
|
||||
try:
|
||||
u = urlparse.urlsplit(uri)
|
||||
if u.hostname == "localhost" or u.hostname == "127.0.0.1":
|
||||
host = xmlrpclib.ServerProxy(self.get_localhost_auth_uri(uri))
|
||||
host = xmlrpclib.ServerProxy(get_localhost_auth_uri(uri))
|
||||
else:
|
||||
host = xmlrpclib.ServerProxy(uri)
|
||||
host.ping()
|
||||
@ -474,7 +457,7 @@ class ConnectionManager(component.Component):
|
||||
# We need to stop this daemon
|
||||
# Call the shutdown method on the daemon
|
||||
if u.hostname == "127.0.0.1" or u.hostname == "localhost":
|
||||
uri = self.get_localhost_auth_uri(uri)
|
||||
uri = get_localhost_auth_uri(uri)
|
||||
core = xmlrpclib.ServerProxy(uri)
|
||||
core.shutdown()
|
||||
# Update display to show change
|
||||
@ -529,7 +512,7 @@ class ConnectionManager(component.Component):
|
||||
# We need to wait for the host to start before connecting
|
||||
auth_uri = None
|
||||
while not auth_uri:
|
||||
auth_uri = self.get_localhost_auth_uri(uri)
|
||||
auth_uri = get_localhost_auth_uri(uri)
|
||||
time.sleep(0.01)
|
||||
|
||||
while not self.test_online_status(auth_uri):
|
||||
@ -545,7 +528,7 @@ class ConnectionManager(component.Component):
|
||||
|
||||
# Status is OK, so lets change to this host
|
||||
if localhost:
|
||||
client.set_core_uri(self.get_localhost_auth_uri(uri))
|
||||
client.set_core_uri(get_localhost_auth_uri(uri))
|
||||
else:
|
||||
client.set_core_uri(uri)
|
||||
|
||||
|
@ -38,6 +38,7 @@ from web import cookies, setcookie as w_setcookie
|
||||
from web import seeother as w_seeother
|
||||
|
||||
from deluge.common import fsize, fspeed, ftime
|
||||
from deluge.ui.common import get_localhost_auth_uri
|
||||
from deluge import component
|
||||
from deluge.log import LOG as log
|
||||
from deluge.configmanager import ConfigManager
|
||||
@ -158,25 +159,6 @@ def get_newforms_data(form_class):
|
||||
#/utils
|
||||
|
||||
#daemon:
|
||||
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
|
||||
def daemon_test_online_status(uri):
|
||||
"""Tests the status of URI.. Returns True or False depending on status.
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user