mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 20:44:50 +00:00
fix some indentation issues
This commit is contained in:
parent
3194f0f994
commit
cdf2f79c66
@ -75,7 +75,7 @@ def export(auth_level=AUTH_LEVEL_DEFAULT):
|
|||||||
global AUTH_LEVEL_DEFAULT
|
global AUTH_LEVEL_DEFAULT
|
||||||
if AUTH_LEVEL_DEFAULT is None:
|
if AUTH_LEVEL_DEFAULT is None:
|
||||||
from deluge.ui.web.auth import AUTH_LEVEL_DEFAULT
|
from deluge.ui.web.auth import AUTH_LEVEL_DEFAULT
|
||||||
|
|
||||||
def wrap(func, *args, **kwargs):
|
def wrap(func, *args, **kwargs):
|
||||||
func._json_export = True
|
func._json_export = True
|
||||||
func._json_auth_level = auth_level
|
func._json_auth_level = auth_level
|
||||||
@ -98,21 +98,21 @@ class JSON(resource.Resource, component.Component):
|
|||||||
A Twisted Web resource that exposes a JSON-RPC interface for web clients
|
A Twisted Web resource that exposes a JSON-RPC interface for web clients
|
||||||
to use.
|
to use.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
resource.Resource.__init__(self)
|
resource.Resource.__init__(self)
|
||||||
component.Component.__init__(self, "JSON")
|
component.Component.__init__(self, "JSON")
|
||||||
self._remote_methods = []
|
self._remote_methods = []
|
||||||
self._local_methods = {}
|
self._local_methods = {}
|
||||||
client.disconnect_callback = self._on_client_disconnect
|
client.disconnect_callback = self._on_client_disconnect
|
||||||
|
|
||||||
def connect(self, host="localhost", port=58846, username="", password=""):
|
def connect(self, host="localhost", port=58846, username="", password=""):
|
||||||
"""
|
"""
|
||||||
Connects the client to a daemon
|
Connects the client to a daemon
|
||||||
"""
|
"""
|
||||||
d = Deferred()
|
d = Deferred()
|
||||||
_d = client.connect(host, port, username, password)
|
_d = client.connect(host, port, username, password)
|
||||||
|
|
||||||
def on_get_methods(methods):
|
def on_get_methods(methods):
|
||||||
"""
|
"""
|
||||||
Handles receiving the method names
|
Handles receiving the method names
|
||||||
@ -121,7 +121,7 @@ class JSON(resource.Resource, component.Component):
|
|||||||
methods = list(self._remote_methods)
|
methods = list(self._remote_methods)
|
||||||
methods.extend(self._local_methods)
|
methods.extend(self._local_methods)
|
||||||
d.callback(methods)
|
d.callback(methods)
|
||||||
|
|
||||||
def on_client_connected(connection_id):
|
def on_client_connected(connection_id):
|
||||||
"""
|
"""
|
||||||
Handles the client successfully connecting to the daemon and
|
Handles the client successfully connecting to the daemon and
|
||||||
@ -132,10 +132,10 @@ class JSON(resource.Resource, component.Component):
|
|||||||
component.get("PluginManager").start()
|
component.get("PluginManager").start()
|
||||||
_d.addCallback(on_client_connected)
|
_d.addCallback(on_client_connected)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _on_client_disconnect(self, *args):
|
def _on_client_disconnect(self, *args):
|
||||||
component.get("PluginManager").stop()
|
component.get("PluginManager").stop()
|
||||||
|
|
||||||
def _exec_local(self, method, params):
|
def _exec_local(self, method, params):
|
||||||
"""
|
"""
|
||||||
Handles executing all local methods.
|
Handles executing all local methods.
|
||||||
@ -151,14 +151,14 @@ class JSON(resource.Resource, component.Component):
|
|||||||
# and any plugins.
|
# and any plugins.
|
||||||
return self._local_methods[method](*params)
|
return self._local_methods[method](*params)
|
||||||
raise JSONException("Unknown system method")
|
raise JSONException("Unknown system method")
|
||||||
|
|
||||||
def _exec_remote(self, method, params):
|
def _exec_remote(self, method, params):
|
||||||
"""
|
"""
|
||||||
Executes methods using the Deluge client.
|
Executes methods using the Deluge client.
|
||||||
"""
|
"""
|
||||||
component, method = method.split(".")
|
component, method = method.split(".")
|
||||||
return getattr(getattr(client, component), method)(*params)
|
return getattr(getattr(client, component), method)(*params)
|
||||||
|
|
||||||
def _handle_request(self, request):
|
def _handle_request(self, request):
|
||||||
"""
|
"""
|
||||||
Takes some json data as a string and attempts to decode it, and process
|
Takes some json data as a string and attempts to decode it, and process
|
||||||
@ -170,14 +170,14 @@ class JSON(resource.Resource, component.Component):
|
|||||||
request = json.loads(request)
|
request = json.loads(request)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise JSONException("JSON not decodable")
|
raise JSONException("JSON not decodable")
|
||||||
|
|
||||||
if "method" not in request or "id" not in request or \
|
if "method" not in request or "id" not in request or \
|
||||||
"params" not in request:
|
"params" not in request:
|
||||||
raise JSONException("Invalid JSON request")
|
raise JSONException("Invalid JSON request")
|
||||||
|
|
||||||
method, params = request["method"], request["params"]
|
method, params = request["method"], request["params"]
|
||||||
request_id = request["id"]
|
request_id = request["id"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if method.startswith("system."):
|
if method.startswith("system."):
|
||||||
return self._exec_local(method, params), request_id
|
return self._exec_local(method, params), request_id
|
||||||
@ -190,7 +190,7 @@ class JSON(resource.Resource, component.Component):
|
|||||||
d = Deferred()
|
d = Deferred()
|
||||||
d.callback(None)
|
d.callback(None)
|
||||||
return d, request_id
|
return d, request_id
|
||||||
|
|
||||||
def _on_rpc_request_finished(self, result, response, request):
|
def _on_rpc_request_finished(self, result, response, request):
|
||||||
"""
|
"""
|
||||||
Sends the response of any rpc calls back to the json-rpc client.
|
Sends the response of any rpc calls back to the json-rpc client.
|
||||||
@ -205,7 +205,7 @@ class JSON(resource.Resource, component.Component):
|
|||||||
print type(reason)
|
print type(reason)
|
||||||
request.setResponseCode(http.INTERNAL_SERVER_ERROR)
|
request.setResponseCode(http.INTERNAL_SERVER_ERROR)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def _on_json_request(self, request):
|
def _on_json_request(self, request):
|
||||||
"""
|
"""
|
||||||
Handler to take the json data as a string and pass it on to the
|
Handler to take the json data as a string and pass it on to the
|
||||||
@ -217,7 +217,7 @@ class JSON(resource.Resource, component.Component):
|
|||||||
d.addCallback(self._on_rpc_request_finished, response, request)
|
d.addCallback(self._on_rpc_request_finished, response, request)
|
||||||
d.addErrback(self._on_rpc_request_failed, response, request)
|
d.addErrback(self._on_rpc_request_failed, response, request)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _on_json_request_failed(self, reason, request):
|
def _on_json_request_failed(self, reason, request):
|
||||||
"""
|
"""
|
||||||
Errback handler to return a HTTP code of 500.
|
Errback handler to return a HTTP code of 500.
|
||||||
@ -225,13 +225,13 @@ class JSON(resource.Resource, component.Component):
|
|||||||
log.exception(reason)
|
log.exception(reason)
|
||||||
request.setResponseCode(http.INTERNAL_SERVER_ERROR)
|
request.setResponseCode(http.INTERNAL_SERVER_ERROR)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def _send_response(self, request, response):
|
def _send_response(self, request, response):
|
||||||
response = json.dumps(response)
|
response = json.dumps(response)
|
||||||
request.setHeader("content-type", "application/x-json")
|
request.setHeader("content-type", "application/x-json")
|
||||||
request.write(response)
|
request.write(response)
|
||||||
request.finish()
|
request.finish()
|
||||||
|
|
||||||
def render(self, request):
|
def render(self, request):
|
||||||
"""
|
"""
|
||||||
Handles all the POST requests made to the /json controller.
|
Handles all the POST requests made to the /json controller.
|
||||||
@ -240,7 +240,7 @@ class JSON(resource.Resource, component.Component):
|
|||||||
if request.method != "POST":
|
if request.method != "POST":
|
||||||
request.setResponseCode(http.NOT_ALLOWED)
|
request.setResponseCode(http.NOT_ALLOWED)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
request.content.seek(0)
|
request.content.seek(0)
|
||||||
request.json = request.content.read()
|
request.json = request.content.read()
|
||||||
@ -248,7 +248,7 @@ class JSON(resource.Resource, component.Component):
|
|||||||
return server.NOT_DONE_YET
|
return server.NOT_DONE_YET
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
return self._on_json_request_failed(e, request)
|
return self._on_json_request_failed(e, request)
|
||||||
|
|
||||||
def register_object(self, obj, name=None):
|
def register_object(self, obj, name=None):
|
||||||
"""
|
"""
|
||||||
Registers an object to export it's rpc methods. These methods should
|
Registers an object to export it's rpc methods. These methods should
|
||||||
@ -272,7 +272,7 @@ DEFAULT_PORT = 58846
|
|||||||
|
|
||||||
DEFAULT_HOSTS = {
|
DEFAULT_HOSTS = {
|
||||||
"hosts": [(hashlib.sha1(str(time.time())).hexdigest(),
|
"hosts": [(hashlib.sha1(str(time.time())).hexdigest(),
|
||||||
DEFAULT_HOST, DEFAULT_PORT, "", "")]
|
DEFAULT_HOST, DEFAULT_PORT, "", "")]
|
||||||
}
|
}
|
||||||
HOSTLIST_ID = 0
|
HOSTLIST_ID = 0
|
||||||
HOSTLIST_NAME = 1
|
HOSTLIST_NAME = 1
|
||||||
@ -292,11 +292,11 @@ class WebApi(JSONComponent):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(WebApi, self).__init__("Web")
|
super(WebApi, self).__init__("Web")
|
||||||
self.host_list = ConfigManager("hostlist.conf.1.2", DEFAULT_HOSTS)
|
self.host_list = ConfigManager("hostlist.conf.1.2", DEFAULT_HOSTS)
|
||||||
|
|
||||||
def get_host(self, host_id):
|
def get_host(self, host_id):
|
||||||
"""
|
"""
|
||||||
Return the information about a host
|
Return the information about a host
|
||||||
|
|
||||||
:param host_id: str, the id of the host
|
:param host_id: str, the id of the host
|
||||||
:returns: the host information
|
:returns: the host information
|
||||||
:rtype: list
|
:rtype: list
|
||||||
@ -304,12 +304,12 @@ class WebApi(JSONComponent):
|
|||||||
for host in self.host_list["hosts"]:
|
for host in self.host_list["hosts"]:
|
||||||
if host[0] == host_id:
|
if host[0] == host_id:
|
||||||
return host
|
return host
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def connect(self, host_id):
|
def connect(self, host_id):
|
||||||
"""
|
"""
|
||||||
Connect the client to a daemon
|
Connect the client to a daemon
|
||||||
|
|
||||||
:param host_id: str, the id of the daemon in the host list
|
:param host_id: str, the id of the daemon in the host list
|
||||||
:returns: the methods the daemon supports
|
:returns: the methods the daemon supports
|
||||||
:rtype: list
|
:rtype: list
|
||||||
@ -322,19 +322,19 @@ class WebApi(JSONComponent):
|
|||||||
continue
|
continue
|
||||||
self._json.connect(*host[1:]).addCallback(on_connected)
|
self._json.connect(*host[1:]).addCallback(on_connected)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def connected(self):
|
def connected(self):
|
||||||
"""
|
"""
|
||||||
The current connection state.
|
The current connection state.
|
||||||
|
|
||||||
:returns: True if the client is connected
|
:returns: True if the client is connected
|
||||||
:rtype: bool
|
:rtype: bool
|
||||||
"""
|
"""
|
||||||
d = Deferred()
|
d = Deferred()
|
||||||
d.callback(client.connected())
|
d.callback(client.connected())
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
"""
|
"""
|
||||||
@ -344,12 +344,12 @@ class WebApi(JSONComponent):
|
|||||||
client.disconnect()
|
client.disconnect()
|
||||||
d.callback(True)
|
d.callback(True)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def update_ui(self, keys, filter_dict):
|
def update_ui(self, keys, filter_dict):
|
||||||
"""
|
"""
|
||||||
Gather the information required for updating the web interface.
|
Gather the information required for updating the web interface.
|
||||||
|
|
||||||
:param keys: list, the information about the torrents to gather
|
:param keys: list, the information about the torrents to gather
|
||||||
:param filter_dict: dict, the filters to apply when selecting torrents.
|
:param filter_dict: dict, the filters to apply when selecting torrents.
|
||||||
:returns: The torrent and ui information.
|
:returns: The torrent and ui information.
|
||||||
@ -360,24 +360,24 @@ class WebApi(JSONComponent):
|
|||||||
"filters": None,
|
"filters": None,
|
||||||
"stats": None
|
"stats": None
|
||||||
}
|
}
|
||||||
|
|
||||||
d = Deferred()
|
d = Deferred()
|
||||||
|
|
||||||
log.info("Updating ui with keys '%r' and filters '%r'", keys,
|
log.info("Updating ui with keys '%r' and filters '%r'", keys,
|
||||||
filter_dict)
|
filter_dict)
|
||||||
|
|
||||||
def got_stats(stats):
|
def got_stats(stats):
|
||||||
ui_info["stats"] = stats
|
ui_info["stats"] = stats
|
||||||
|
|
||||||
def got_filters(filters):
|
def got_filters(filters):
|
||||||
ui_info["filters"] = filters
|
ui_info["filters"] = filters
|
||||||
|
|
||||||
def got_torrents(torrents):
|
def got_torrents(torrents):
|
||||||
ui_info["torrents"] = torrents
|
ui_info["torrents"] = torrents
|
||||||
|
|
||||||
def on_complete(result):
|
def on_complete(result):
|
||||||
d.callback(ui_info)
|
d.callback(ui_info)
|
||||||
|
|
||||||
d1 = client.core.get_torrents_status(filter_dict, keys)
|
d1 = client.core.get_torrents_status(filter_dict, keys)
|
||||||
d1.addCallback(got_torrents)
|
d1.addCallback(got_torrents)
|
||||||
|
|
||||||
@ -386,11 +386,11 @@ class WebApi(JSONComponent):
|
|||||||
|
|
||||||
d3 = client.core.get_stats()
|
d3 = client.core.get_stats()
|
||||||
d3.addCallback(got_stats)
|
d3.addCallback(got_stats)
|
||||||
|
|
||||||
dl = DeferredList([d1, d2, d3], consumeErrors=True)
|
dl = DeferredList([d1, d2, d3], consumeErrors=True)
|
||||||
dl.addCallback(on_complete)
|
dl.addCallback(on_complete)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
def _on_got_files(self, torrent, d):
|
def _on_got_files(self, torrent, d):
|
||||||
files = torrent.get("files")
|
files = torrent.get("files")
|
||||||
file_progress = torrent.get("file_progress")
|
file_progress = torrent.get("file_progress")
|
||||||
@ -405,22 +405,22 @@ class WebApi(JSONComponent):
|
|||||||
torrent_file["priority"] = file_priorities[index]
|
torrent_file["priority"] = file_priorities[index]
|
||||||
torrent_file["index"] = index
|
torrent_file["index"] = index
|
||||||
info[path] = torrent_file
|
info[path] = torrent_file
|
||||||
|
|
||||||
def walk(path, item):
|
def walk(path, item):
|
||||||
if type(item) is dict:
|
if type(item) is dict:
|
||||||
return item
|
return item
|
||||||
return [info[path]["index"], info[path]["size"],
|
return [info[path]["index"], info[path]["size"],
|
||||||
info[path]["progress"], info[path]["priority"]]
|
info[path]["progress"], info[path]["priority"]]
|
||||||
|
|
||||||
file_tree = uicommon.FileTree(paths)
|
file_tree = uicommon.FileTree(paths)
|
||||||
file_tree.walk(walk)
|
file_tree.walk(walk)
|
||||||
d.callback(file_tree.get_tree())
|
d.callback(file_tree.get_tree())
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def get_torrent_files(self, torrent_id):
|
def get_torrent_files(self, torrent_id):
|
||||||
"""
|
"""
|
||||||
Gets the files for a torrent in tree format
|
Gets the files for a torrent in tree format
|
||||||
|
|
||||||
:param torrent_id: string, the id of the torrent to retrieve.
|
:param torrent_id: string, the id of the torrent to retrieve.
|
||||||
:returns: The torrents files in a tree
|
:returns: The torrents files in a tree
|
||||||
:rtype: dict
|
:rtype: dict
|
||||||
@ -434,7 +434,7 @@ class WebApi(JSONComponent):
|
|||||||
def download_torrent_from_url(self, url):
|
def download_torrent_from_url(self, url):
|
||||||
"""
|
"""
|
||||||
Download a torrent file from a url to a temporary directory.
|
Download a torrent file from a url to a temporary directory.
|
||||||
|
|
||||||
:param url: str, the url of the torrent
|
:param url: str, the url of the torrent
|
||||||
:returns: the temporary file name of the torrent file
|
:returns: the temporary file name of the torrent file
|
||||||
:rtype: str
|
:rtype: str
|
||||||
@ -445,12 +445,12 @@ class WebApi(JSONComponent):
|
|||||||
d = Deferred()
|
d = Deferred()
|
||||||
d.callback(filename)
|
d.callback(filename)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def get_torrent_info(self, filename):
|
def get_torrent_info(self, filename):
|
||||||
"""
|
"""
|
||||||
Return information about a torrent on the filesystem.
|
Return information about a torrent on the filesystem.
|
||||||
|
|
||||||
:param filename: str, the path to the torrent
|
:param filename: str, the path to the torrent
|
||||||
:returns:
|
:returns:
|
||||||
{
|
{
|
||||||
@ -473,11 +473,11 @@ class WebApi(JSONComponent):
|
|||||||
def add_torrents(self, torrents):
|
def add_torrents(self, torrents):
|
||||||
"""
|
"""
|
||||||
Add torrents by file
|
Add torrents by file
|
||||||
|
|
||||||
:param torrents: A list of dictionaries containing the torrent
|
:param torrents: A list of dictionaries containing the torrent
|
||||||
path and torrent options to add with.
|
path and torrent options to add with.
|
||||||
:type torrents: list
|
:type torrents: list
|
||||||
|
|
||||||
**Usage**
|
**Usage**
|
||||||
>>> json_api.web.add_torrents([{
|
>>> json_api.web.add_torrents([{
|
||||||
"path": "/tmp/deluge-web/some-torrent-file.torrent",
|
"path": "/tmp/deluge-web/some-torrent-file.torrent",
|
||||||
@ -488,42 +488,42 @@ class WebApi(JSONComponent):
|
|||||||
filename = os.path.basename(torrent["path"])
|
filename = os.path.basename(torrent["path"])
|
||||||
fdump = base64.encodestring(open(torrent["path"], "rb").read())
|
fdump = base64.encodestring(open(torrent["path"], "rb").read())
|
||||||
log.info("Adding torrent from file `%s` with options `%r`",
|
log.info("Adding torrent from file `%s` with options `%r`",
|
||||||
filename, torrent["options"])
|
filename, torrent["options"])
|
||||||
client.core.add_torrent_file(filename, fdump, torrent["options"])
|
client.core.add_torrent_file(filename, fdump, torrent["options"])
|
||||||
d = Deferred()
|
d = Deferred()
|
||||||
d.callback(True)
|
d.callback(True)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def get_hosts(self):
|
def get_hosts(self):
|
||||||
"""
|
"""
|
||||||
Return the hosts in the hostlist.
|
Return the hosts in the hostlist.
|
||||||
"""
|
"""
|
||||||
log.debug("get_hosts called")
|
log.debug("get_hosts called")
|
||||||
d = Deferred()
|
d = Deferred()
|
||||||
d.callback([(tuple(host[HOSTS_ID:HOSTS_PORT+1]) + (_("Offline"),)) for host in self.host_list["hosts"]])
|
d.callback([(tuple(host[HOSTS_ID:HOSTS_PORT+1]) + (_("Offline"),)) for host in self.host_list["hosts"]])
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def get_host_status(self, host_id):
|
def get_host_status(self, host_id):
|
||||||
"""
|
"""
|
||||||
Returns the current status for the specified host.
|
Returns the current status for the specified host.
|
||||||
"""
|
"""
|
||||||
main_deferred = Deferred()
|
main_deferred = Deferred()
|
||||||
|
|
||||||
(host_id, host, port, user, password) = self.get_host(host_id)
|
(host_id, host, port, user, password) = self.get_host(host_id)
|
||||||
|
|
||||||
def callback(status, info=None):
|
def callback(status, info=None):
|
||||||
main_deferred.callback((host_id, host, port, status, info))
|
main_deferred.callback((host_id, host, port, status, info))
|
||||||
|
|
||||||
def on_connect(connected, c, host_id):
|
def on_connect(connected, c, host_id):
|
||||||
def on_info(info, c):
|
def on_info(info, c):
|
||||||
c.disconnect()
|
c.disconnect()
|
||||||
callback(_("Online"), info)
|
callback(_("Online"), info)
|
||||||
|
|
||||||
def on_info_fail(reason):
|
def on_info_fail(reason):
|
||||||
callback(_("Offline"))
|
callback(_("Offline"))
|
||||||
|
|
||||||
if not connected:
|
if not connected:
|
||||||
callback(_("Offline"))
|
callback(_("Offline"))
|
||||||
return
|
return
|
||||||
@ -531,24 +531,24 @@ class WebApi(JSONComponent):
|
|||||||
d = c.daemon.info()
|
d = c.daemon.info()
|
||||||
d.addCallback(on_info, c)
|
d.addCallback(on_info, c)
|
||||||
d.addErrback(on_info_fail)
|
d.addErrback(on_info_fail)
|
||||||
|
|
||||||
def on_connect_failed(reason, host_id):
|
def on_connect_failed(reason, host_id):
|
||||||
callback(_("Offline"))
|
callback(_("Offline"))
|
||||||
|
|
||||||
if client.connected() and (host, port, "localclient" if not \
|
if client.connected() and (host, port, "localclient" if not \
|
||||||
user and host in ("127.0.0.1", "localhost") else \
|
user and host in ("127.0.0.1", "localhost") else \
|
||||||
user) == client.connection_info():
|
user) == client.connection_info():
|
||||||
def on_info(info):
|
def on_info(info):
|
||||||
callback(_("Connected"), info)
|
callback(_("Connected"), info)
|
||||||
|
|
||||||
client.daemon.info().addCallback(on_info)
|
client.daemon.info().addCallback(on_info)
|
||||||
|
|
||||||
c = Client()
|
c = Client()
|
||||||
d = c.connect(host, port, user, password)
|
d = c.connect(host, port, user, password)
|
||||||
d.addCallback(on_connect, c, host_id)
|
d.addCallback(on_connect, c, host_id)
|
||||||
d.addErrback(on_connect_failed, host_id)
|
d.addErrback(on_connect_failed, host_id)
|
||||||
return main_deferred
|
return main_deferred
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def stop_daemon(self, connection_id):
|
def stop_daemon(self, connection_id):
|
||||||
"""
|
"""
|
||||||
@ -562,7 +562,7 @@ class WebApi(JSONComponent):
|
|||||||
if not host:
|
if not host:
|
||||||
main_deferred.callback((False, _("Daemon doesn't exist")))
|
main_deferred.callback((False, _("Daemon doesn't exist")))
|
||||||
return main_deferred
|
return main_deferred
|
||||||
|
|
||||||
try:
|
try:
|
||||||
def on_connect(connected, c):
|
def on_connect(connected, c):
|
||||||
if not connected:
|
if not connected:
|
||||||
@ -570,7 +570,7 @@ class WebApi(JSONComponent):
|
|||||||
return
|
return
|
||||||
c.daemon.shutdown()
|
c.daemon.shutdown()
|
||||||
main_deferred.callback((True, ))
|
main_deferred.callback((True, ))
|
||||||
|
|
||||||
def on_connect_failed(reason):
|
def on_connect_failed(reason):
|
||||||
main_deferred.callback((False, reason))
|
main_deferred.callback((False, reason))
|
||||||
|
|
||||||
@ -582,7 +582,7 @@ class WebApi(JSONComponent):
|
|||||||
except:
|
except:
|
||||||
main_deferred.callback((False, "An error occured"))
|
main_deferred.callback((False, "An error occured"))
|
||||||
return main_deferred
|
return main_deferred
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def add_host(self, host, port, username="", password=""):
|
def add_host(self, host, port, username="", password=""):
|
||||||
"""
|
"""
|
||||||
@ -600,21 +600,21 @@ class WebApi(JSONComponent):
|
|||||||
for entry in self.host_list["hosts"]:
|
for entry in self.host_list["hosts"]:
|
||||||
if (entry[0], entry[1], entry[2]) == (host, port, username):
|
if (entry[0], entry[1], entry[2]) == (host, port, username):
|
||||||
d.callback((False, "Host already in the list"))
|
d.callback((False, "Host already in the list"))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
port = int(port)
|
port = int(port)
|
||||||
except:
|
except:
|
||||||
d.callback((False, "Port is invalid"))
|
d.callback((False, "Port is invalid"))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
# Host isn't in the list, so lets add it
|
# Host isn't in the list, so lets add it
|
||||||
connection_id = hashlib.sha1(str(time.time())).hexdigest()
|
connection_id = hashlib.sha1(str(time.time())).hexdigest()
|
||||||
self.host_list["hosts"].append([connection_id, host, port, username,
|
self.host_list["hosts"].append([connection_id, host, port, username,
|
||||||
password])
|
password])
|
||||||
self.host_list.save()
|
self.host_list.save()
|
||||||
d.callback((True,))
|
d.callback((True,))
|
||||||
return d
|
return d
|
||||||
|
|
||||||
@export
|
@export
|
||||||
def remove_host(self, connection_id):
|
def remove_host(self, connection_id):
|
||||||
"""
|
"""
|
||||||
@ -627,7 +627,7 @@ class WebApi(JSONComponent):
|
|||||||
host = self.get_host(connection_id)
|
host = self.get_host(connection_id)
|
||||||
if host is None:
|
if host is None:
|
||||||
d.callback(False)
|
d.callback(False)
|
||||||
|
|
||||||
self.host_list["hosts"].remove(host)
|
self.host_list["hosts"].remove(host)
|
||||||
self.host_list.save()
|
self.host_list.save()
|
||||||
d.callback(True)
|
d.callback(True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user