big client.py refactor
This commit is contained in:
parent
21c4025a7b
commit
d53a606b0e
|
@ -34,7 +34,7 @@
|
||||||
import gettext
|
import gettext
|
||||||
import locale
|
import locale
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
class UI:
|
class UI:
|
||||||
|
@ -78,7 +78,7 @@ class UI:
|
||||||
torrent_ids = self.plugin.get_selected_torrents()
|
torrent_ids = self.plugin.get_selected_torrents()
|
||||||
for torrent_id in torrent_ids:
|
for torrent_id in torrent_ids:
|
||||||
try:
|
try:
|
||||||
client.get_core().queue_queue_top(torrent_id)
|
client.queue_queue_top(torrent_id)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.debug("Unable to queue top torrent: %s", e)
|
log.debug("Unable to queue top torrent: %s", e)
|
||||||
return
|
return
|
||||||
|
@ -89,7 +89,7 @@ class UI:
|
||||||
torrent_ids = self.plugin.get_selected_torrents()
|
torrent_ids = self.plugin.get_selected_torrents()
|
||||||
for torrent_id in torrent_ids:
|
for torrent_id in torrent_ids:
|
||||||
try:
|
try:
|
||||||
client.get_core().queue_queue_up(torrent_id)
|
client.queue_queue_up(torrent_id)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.debug("Unable to queue up torrent: %s", e)
|
log.debug("Unable to queue up torrent: %s", e)
|
||||||
return
|
return
|
||||||
|
@ -100,7 +100,7 @@ class UI:
|
||||||
torrent_ids = self.plugin.get_selected_torrents()
|
torrent_ids = self.plugin.get_selected_torrents()
|
||||||
for torrent_id in torrent_ids:
|
for torrent_id in torrent_ids:
|
||||||
try:
|
try:
|
||||||
client.get_core().queue_queue_down(torrent_id)
|
client.queue_queue_down(torrent_id)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.debug("Unable to queue down torrent: %s", e)
|
log.debug("Unable to queue down torrent: %s", e)
|
||||||
return
|
return
|
||||||
|
@ -111,7 +111,7 @@ class UI:
|
||||||
torrent_ids = self.plugin.get_selected_torrents()
|
torrent_ids = self.plugin.get_selected_torrents()
|
||||||
for torrent_id in torrent_ids:
|
for torrent_id in torrent_ids:
|
||||||
try:
|
try:
|
||||||
client.get_core().queue_queue_bottom(torrent_id)
|
client.queue_queue_bottom(torrent_id)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.debug("Unable to queue bottom torrent: %s", e)
|
log.debug("Unable to queue bottom torrent: %s", e)
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
#
|
#
|
||||||
# client.py
|
# client.py
|
||||||
#
|
#
|
||||||
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
# Copyright (C) 2007/2008 Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||||
#
|
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
|
||||||
|
#
|
||||||
# Deluge is free software.
|
# Deluge is free software.
|
||||||
#
|
#
|
||||||
# You may redistribute it and/or modify it under the terms of the
|
# You may redistribute it and/or modify it under the terms of the
|
||||||
# GNU General Public License, as published by the Free Software
|
# GNU General Public License, as published by the Free Software
|
||||||
# Foundation; either version 2 of the License, or (at your option)
|
# Foundation; either version 2 of the License, or (at your option)
|
||||||
# any later version.
|
# any later version.
|
||||||
#
|
#
|
||||||
# deluge is distributed in the hope that it will be useful,
|
# deluge is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
# See the GNU General Public License for more details.
|
# See the GNU General Public License for more details.
|
||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with deluge. If not, write to:
|
# along with deluge. If not, write to:
|
||||||
# The Free Software Foundation, Inc.,
|
# The Free Software Foundation, Inc.,
|
||||||
|
@ -43,26 +44,26 @@ import deluge.xmlrpclib as xmlrpclib
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.error
|
import deluge.error
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
class CoreProxy(gobject.GObject):
|
class CoreProxy(gobject.GObject):
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
"new_core" : (
|
"new_core" : (
|
||||||
|
gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
|
||||||
|
"no_core" : (
|
||||||
gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
|
gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
|
||||||
"no_core" : (
|
|
||||||
gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, []),
|
|
||||||
}
|
}
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
log.debug("CoreProxy init..")
|
log.debug("CoreProxy init..")
|
||||||
gobject.GObject.__init__(self)
|
gobject.GObject.__init__(self)
|
||||||
self._uri = None
|
self._uri = None
|
||||||
self._core = None
|
self.rpc_core = None
|
||||||
self._multi = None
|
self._multi = None
|
||||||
self._callbacks = []
|
self._callbacks = []
|
||||||
self._multi_timer = None
|
self._multi_timer = None
|
||||||
|
|
||||||
def call(self, func, callback, *args):
|
def call(self, func, callback, *args):
|
||||||
if self._core is None or self._multi is None:
|
if self.rpc_core is None or self._multi is None:
|
||||||
if self.get_core() is None:
|
if self.rpc_core is None:
|
||||||
raise deluge.error.NoCoreError("The core proxy is invalid.")
|
raise deluge.error.NoCoreError("The core proxy is invalid.")
|
||||||
return
|
return
|
||||||
_func = getattr(self._multi, func)
|
_func = getattr(self._multi, func)
|
||||||
|
@ -77,14 +78,14 @@ class CoreProxy(gobject.GObject):
|
||||||
_func()
|
_func()
|
||||||
else:
|
else:
|
||||||
_func(*args)
|
_func(*args)
|
||||||
|
|
||||||
self._callbacks.append([callback])
|
self._callbacks.append([callback])
|
||||||
|
|
||||||
def do_multicall(self, block=False):
|
def do_multicall(self, block=False):
|
||||||
if len(self._callbacks) == 0:
|
if len(self._callbacks) == 0:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if self._multi is not None and self._core is not None:
|
if self._multi is not None and self.rpc_core is not None:
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
for i, ret in enumerate(self._multi()):
|
for i, ret in enumerate(self._multi()):
|
||||||
|
@ -99,18 +100,18 @@ class CoreProxy(gobject.GObject):
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
log.warning("Could not contact daemon: %s", e)
|
log.warning("Could not contact daemon: %s", e)
|
||||||
self.set_core_uri(None)
|
self.set_core_uri(None)
|
||||||
finally:
|
finally:
|
||||||
self._callbacks = []
|
self._callbacks = []
|
||||||
|
|
||||||
self._multi = xmlrpclib.MultiCall(self._core)
|
self._multi = xmlrpclib.MultiCall(self.rpc_core)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def set_core_uri(self, uri):
|
def set_core_uri(self, uri):
|
||||||
log.info("Setting core uri as %s", uri)
|
log.info("Setting core uri as %s", uri)
|
||||||
|
|
||||||
if uri == None and self._uri != None:
|
if uri == None and self._uri != None:
|
||||||
self._uri = None
|
self._uri = None
|
||||||
self._core = None
|
self.rpc_core = None
|
||||||
self._multi = None
|
self._multi = None
|
||||||
try:
|
try:
|
||||||
gobject.source_remove(self._multi_timer)
|
gobject.source_remove(self._multi_timer)
|
||||||
|
@ -118,252 +119,266 @@ class CoreProxy(gobject.GObject):
|
||||||
pass
|
pass
|
||||||
self.emit("no_core")
|
self.emit("no_core")
|
||||||
return
|
return
|
||||||
|
|
||||||
if uri != self._uri and self._uri != None:
|
if uri != self._uri and self._uri != None:
|
||||||
self._core = None
|
self.rpc_core = None
|
||||||
self._multi = None
|
self._multi = None
|
||||||
try:
|
try:
|
||||||
gobject.source_remove(self._multi_timer)
|
gobject.source_remove(self._multi_timer)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self.emit("no_core")
|
self.emit("no_core")
|
||||||
|
|
||||||
self._uri = uri
|
self._uri = uri
|
||||||
# Get a new core
|
# Get a new core
|
||||||
self.get_core()
|
self.get_rpc_core()
|
||||||
|
|
||||||
def get_core_uri(self):
|
def get_core_uri(self):
|
||||||
"""Returns the URI of the core currently being used."""
|
"""Returns the URI of the core currently being used."""
|
||||||
return self._uri
|
return self._uri
|
||||||
|
|
||||||
def get_core(self):
|
def get_rpc_core(self):
|
||||||
if self._core is None and self._uri is not None:
|
if self.rpc_core is None and self._uri is not None:
|
||||||
log.debug("Creating ServerProxy..")
|
log.debug("Creating ServerProxy..")
|
||||||
self._core = xmlrpclib.ServerProxy(self._uri, allow_none=True)
|
self.rpc_core = xmlrpclib.ServerProxy(self._uri, allow_none=True)
|
||||||
self._multi = xmlrpclib.MultiCall(self._core)
|
self._multi = xmlrpclib.MultiCall(self.rpc_core)
|
||||||
self._multi_timer = gobject.timeout_add(200, self.do_multicall)
|
self._multi_timer = gobject.timeout_add(200, self.do_multicall)
|
||||||
# Call any callbacks registered
|
# Call any callbacks registered
|
||||||
self.emit("new_core")
|
self.emit("new_core")
|
||||||
|
|
||||||
return self._core
|
return self.rpc_core
|
||||||
|
|
||||||
_core = CoreProxy()
|
_core = CoreProxy()
|
||||||
|
|
||||||
def get_core():
|
class BaseClient(object):
|
||||||
"""Get the core object and return it"""
|
"""
|
||||||
return _core
|
wraps all calls to core/coreproxy
|
||||||
|
base for AClient and SClient
|
||||||
def connect_on_new_core(callback):
|
"""
|
||||||
"""Connect a callback whenever a new core is connected to."""
|
no_callback_list = [ "add_torrent_url", "pause_all_torrents",
|
||||||
return _core.connect("new_core", callback)
|
"resume_all_torrent", "set_config", "enable_plugin",
|
||||||
|
"disable_plugin", "set_torrent_trackers",
|
||||||
|
"set_torrent_max_connections", "set_torrent_max_upload_slots",
|
||||||
|
"set_torrent_max_upload_speed", "set_torrent_max_download_speed",
|
||||||
|
"set_torrent_private_flag", "set_torrent_file_priorities",
|
||||||
|
"block_ip_range",
|
||||||
|
"remove_torrent", "pause_torrent", "move_torrent" ,
|
||||||
|
"resume_torrent","force_reannounce", "force_recheck",
|
||||||
|
"deregister_client","register_client",
|
||||||
|
"add_torrent_file"]
|
||||||
|
|
||||||
def connect_on_no_core(callback):
|
def __init__(self):
|
||||||
"""Connect a callback whenever the core is disconnected from."""
|
self.core = _core
|
||||||
return _core.connect("no_core", callback)
|
|
||||||
|
|
||||||
def set_core_uri(uri):
|
|
||||||
"""Sets the core uri"""
|
|
||||||
return _core.set_core_uri(uri)
|
|
||||||
|
|
||||||
def get_core_uri():
|
#xml-rpc introspection
|
||||||
"""Get the core URI"""
|
def list_methods(self):
|
||||||
return _core.get_core_uri()
|
registered = self.core.rpc_core.system.listMethods( )
|
||||||
|
return sorted(registered)
|
||||||
|
|
||||||
def is_localhost():
|
def methodSignature(self, method_name):
|
||||||
"""Returns True if core is a localhost"""
|
"broken :("
|
||||||
# Get the uri
|
return self.core.rpc_core.system.methodSignature(method_name)
|
||||||
uri = _core.get_core_uri()
|
|
||||||
if uri != None:
|
|
||||||
# Get the host
|
|
||||||
host = uri[7:].split(":")[0]
|
|
||||||
if host == "localhost" or host == "127.0.0.1":
|
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
|
||||||
|
|
||||||
def connected():
|
def methodHelp(self, method_name):
|
||||||
"""Returns True if connected to a host, and False if not."""
|
return self.core.rpc_core.system.methodHelp(method_name)
|
||||||
if get_core_uri() != None:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
def shutdown():
|
#wrappers, getattr
|
||||||
"""Shutdown the core daemon"""
|
def get_method(self, method_name):
|
||||||
try:
|
"Override this in subclass."
|
||||||
get_core().call("shutdown", None)
|
raise NotImplementedError()
|
||||||
force_call(block=False)
|
|
||||||
finally:
|
|
||||||
set_core_uri(None)
|
|
||||||
|
|
||||||
def force_call(block=True):
|
def __getattr__(self, method_name):
|
||||||
"""Forces the multicall batch to go now and not wait for the timer. This
|
return self.get_method(method_name)
|
||||||
call also blocks until all callbacks have been dealt with."""
|
#raise AttributeError("no attr/method named:%s" % attr)
|
||||||
get_core().do_multicall(block=block)
|
|
||||||
|
|
||||||
## Core methods ##
|
#custom wrapped methods:
|
||||||
|
def add_torrent_file(self, torrent_files, torrent_options=None):
|
||||||
def register_client(port):
|
"""Adds torrent files to the core
|
||||||
get_core().call("register_client", None, port)
|
|
||||||
|
|
||||||
def deregister_client():
|
|
||||||
get_core().call("deregister_client", None)
|
|
||||||
|
|
||||||
def add_torrent_file(torrent_files, torrent_options=None):
|
|
||||||
"""Adds torrent files to the core
|
|
||||||
Expects a list of torrent files
|
Expects a list of torrent files
|
||||||
A list of torrent_option dictionaries in the same order of torrent_files
|
A list of torrent_option dictionaries in the same order of torrent_files
|
||||||
"""
|
"""
|
||||||
if torrent_files is None:
|
if torrent_files is None:
|
||||||
log.debug("No torrent files selected..")
|
log.debug("No torrent files selected..")
|
||||||
return
|
return
|
||||||
log.debug("Attempting to add torrent files: %s", torrent_files)
|
log.debug("Attempting to add torrent files: %s", torrent_files)
|
||||||
for torrent_file in torrent_files:
|
for torrent_file in torrent_files:
|
||||||
# Open the .torrent file for reading because we need to send it's
|
# Open the .torrent file for reading because we need to send it's
|
||||||
# contents to the core.
|
# contents to the core.
|
||||||
try:
|
|
||||||
f = open(torrent_file, "rb")
|
|
||||||
except Exception, e:
|
|
||||||
log.warning("Unable to open %s: %s", torrent_file, e)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Get the filename because the core doesn't want a path.
|
|
||||||
(path, filename) = os.path.split(torrent_file)
|
|
||||||
fdump = xmlrpclib.Binary(f.read())
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
# Get the options for the torrent
|
|
||||||
if torrent_options != None:
|
|
||||||
try:
|
try:
|
||||||
options = torrent_options[torrent_files.index(torrent_file)]
|
f = open(torrent_file, "rb")
|
||||||
except:
|
except Exception, e:
|
||||||
|
log.warning("Unable to open %s: %s", torrent_file, e)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Get the filename because the core doesn't want a path.
|
||||||
|
(path, filename) = os.path.split(torrent_file)
|
||||||
|
fdump = xmlrpclib.Binary(f.read())
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
# Get the options for the torrent
|
||||||
|
if torrent_options != None:
|
||||||
|
try:
|
||||||
|
options = torrent_options[torrent_files.index(torrent_file)]
|
||||||
|
except:
|
||||||
|
options = None
|
||||||
|
else:
|
||||||
options = None
|
options = None
|
||||||
|
self.get_method("add_torrent_file")(filename, fdump, options)
|
||||||
|
|
||||||
|
#utility:
|
||||||
|
def has_callback(self, method_name):
|
||||||
|
return (method_name in self.no_callback_list)
|
||||||
|
|
||||||
|
def is_localhost(self):
|
||||||
|
"""Returns True if core is a localhost"""
|
||||||
|
# Get the uri
|
||||||
|
uri = self.core.get_core_uri()
|
||||||
|
if uri != None:
|
||||||
|
# Get the host
|
||||||
|
host = uri[7:].split(":")[0]
|
||||||
|
if host == "localhost" or host == "127.0.0.1":
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def get_core_uri(self):
|
||||||
|
"""Get the core URI"""
|
||||||
|
return self.core.get_core_uri()
|
||||||
|
|
||||||
|
def set_core_uri(self, uri = 'http://localhost:58846'):
|
||||||
|
"""Sets the core uri"""
|
||||||
|
return self.core.set_core_uri(uri)
|
||||||
|
|
||||||
|
def connected(self):
|
||||||
|
"""Returns True if connected to a host, and False if not."""
|
||||||
|
if self.get_core_uri() != None:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def shutdown(self):
|
||||||
|
"""Shutdown the core daemon"""
|
||||||
|
try:
|
||||||
|
self.core.call("shutdown", None)
|
||||||
|
self.core.force_call(block=False)
|
||||||
|
finally:
|
||||||
|
self.set_core_uri(None)
|
||||||
|
|
||||||
|
#events:
|
||||||
|
def connect_on_new_core(self, callback):
|
||||||
|
"""Connect a callback whenever a new core is connected to."""
|
||||||
|
return self.core.connect("new_core", callback)
|
||||||
|
|
||||||
|
def connect_on_no_core(self, callback):
|
||||||
|
"""Connect a callback whenever the core is disconnected from."""
|
||||||
|
return self.core.connect("no_core", callback)
|
||||||
|
|
||||||
|
class SClient(BaseClient):
|
||||||
|
"""
|
||||||
|
sync proxy
|
||||||
|
"""
|
||||||
|
def get_method(self, method_name):
|
||||||
|
return getattr(self.core.rpc_core, method_name)
|
||||||
|
|
||||||
|
class AClient(BaseClient):
|
||||||
|
"""
|
||||||
|
async proxy
|
||||||
|
"""
|
||||||
|
def get_method(self, method_name):
|
||||||
|
if self.has_callback(method_name):
|
||||||
|
def async_proxy_nocb(*args, **kwargs):
|
||||||
|
return self.core.call(method_name,None, *args, **kwargs)
|
||||||
|
return async_proxy_nocb
|
||||||
else:
|
else:
|
||||||
options = None
|
def async_proxy(*args, **kwargs):
|
||||||
|
return self.core.call(method_name, *args, **kwargs)
|
||||||
get_core().call("add_torrent_file", None,
|
return async_proxy
|
||||||
filename, fdump, options)
|
|
||||||
|
|
||||||
def add_torrent_url(torrent_url, options=None):
|
def force_call(self, block=True):
|
||||||
"""Adds torrents to the core via url"""
|
"""Forces the multicall batch to go now and not wait for the timer. This
|
||||||
from deluge.common import is_url
|
call also blocks until all callbacks have been dealt with."""
|
||||||
if is_url(torrent_url):
|
self.core.do_multicall(block=block)
|
||||||
get_core().call("add_torrent_url", None,
|
|
||||||
torrent_url, str(), options)
|
|
||||||
else:
|
|
||||||
log.warning("Invalid URL %s", torrent_url)
|
|
||||||
|
|
||||||
def remove_torrent(torrent_ids, remove_torrent=False, remove_data=False):
|
|
||||||
"""Removes torrent_ids from the core.. Expects a list of torrent_ids"""
|
|
||||||
log.debug("Attempting to remove torrents: %s", torrent_ids)
|
|
||||||
get_core().call("remove_torrent", None, torrent_ids, remove_torrent, remove_data)
|
|
||||||
|
|
||||||
def pause_torrent(torrent_ids):
|
sclient = SClient()
|
||||||
"""Pauses torrent_ids"""
|
aclient = AClient()
|
||||||
get_core().call("pause_torrent", None, torrent_ids)
|
|
||||||
|
|
||||||
def move_torrent(torrent_ids, folder):
|
#------------------------------------------------------------------------------
|
||||||
"""Pauses torrent_ids"""
|
#tests:
|
||||||
get_core().call("move_torrent", None, torrent_ids, folder)
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
def pause_all_torrents():
|
def test_introspection():
|
||||||
"""Pauses all torrents"""
|
print "*start introspection test*"
|
||||||
get_core().call("pause_all_torrents", None)
|
sclient.set_core_uri()
|
||||||
|
print "list_methods", sclient.list_methods()
|
||||||
|
print "sig of block_ip_range", sclient.methodSignature('block_ip_range')
|
||||||
|
print "doc of block_ip_range", sclient.methodHelp('block_ip_range')
|
||||||
|
|
||||||
def resume_all_torrents():
|
def test_sync():
|
||||||
"""Resumes all torrents"""
|
print "*start sync test*"
|
||||||
get_core().call("resume_all_torrents", None)
|
sclient.set_core_uri()
|
||||||
|
|
||||||
def resume_torrent(torrent_ids):
|
|
||||||
"""Resume torrent_ids"""
|
|
||||||
get_core().call("resume_torrent", None, torrent_ids)
|
|
||||||
|
|
||||||
def force_reannounce(torrent_ids):
|
|
||||||
"""Reannounce to trackers"""
|
|
||||||
get_core().call("force_reannounce", None, torrent_ids)
|
|
||||||
|
|
||||||
def get_torrent_status(callback, torrent_id, keys):
|
#get list of torrents and display the 1st.
|
||||||
"""Builds the status dictionary and returns it"""
|
torrent_ids = sclient.get_session_state()
|
||||||
get_core().call("get_torrent_status", callback, torrent_id, keys)
|
print "session_state():", torrent_ids
|
||||||
|
print ("get_torrent_status(%s):" % torrent_ids[0],
|
||||||
|
sclient.get_torrent_status(torrent_ids[0], []))
|
||||||
|
|
||||||
def get_torrents_status(callback, torrent_ids, keys):
|
sclient.pause_torrent(torrent_ids)
|
||||||
"""Builds a dictionary of torrent_ids status. Expects 2 lists. This is
|
|
||||||
asynchronous so the return value will be sent as the signal
|
|
||||||
'torrent_status'"""
|
|
||||||
get_core().call("get_torrents_status", callback, torrent_ids, keys)
|
|
||||||
|
|
||||||
def get_session_state(callback):
|
print "paused:", [
|
||||||
get_core().call("get_session_state", callback)
|
sclient.get_torrent_status(id, ['paused'])['paused']
|
||||||
|
for id in torrent_ids]
|
||||||
|
|
||||||
def get_config(callback):
|
sclient.resume_torrent(torrent_ids)
|
||||||
get_core().call("get_config", callback)
|
print "resumed:", [
|
||||||
|
sclient.get_torrent_status(id, ['paused'])['paused']
|
||||||
|
for id in torrent_ids]
|
||||||
|
|
||||||
def get_config_value(callback, key):
|
def test_async():
|
||||||
get_core().call("get_config_value", callback, key)
|
print "*start async test*"
|
||||||
|
torrent_ids = []
|
||||||
def set_config(config):
|
|
||||||
if config == {}:
|
|
||||||
return
|
|
||||||
get_core().call("set_config", None, config)
|
|
||||||
|
|
||||||
def get_listen_port(callback):
|
#callbacks:
|
||||||
get_core().call("get_listen_port", callback)
|
def cb_session_state(temp_torrent_list):
|
||||||
|
print "session_state:" , temp_torrent_list
|
||||||
|
torrent_ids.extend(temp_torrent_list)
|
||||||
|
|
||||||
def get_available_plugins(callback):
|
def cb_torrent_status_full(status):
|
||||||
get_core().call("get_available_plugins", callback)
|
print "\ntorrent_status_full=", status
|
||||||
|
|
||||||
def get_enabled_plugins(callback):
|
def cb_torrent_status_paused(torrent_state):
|
||||||
get_core().call("get_enabled_plugins", callback)
|
print "(paused=%s)," % torrent_state['paused'],
|
||||||
|
|
||||||
def get_download_rate(callback):
|
#/callbacks
|
||||||
get_core().call("get_download_rate", callback)
|
|
||||||
|
|
||||||
def get_upload_rate(callback):
|
aclient.set_core_uri()
|
||||||
get_core().call("get_upload_rate", callback)
|
aclient.get_session_state(cb_session_state)
|
||||||
|
|
||||||
def get_num_connections(callback):
|
print "force_call 1"
|
||||||
get_core().call("get_num_connections", callback)
|
aclient.force_call(block=True)
|
||||||
|
print "end force_call 1:", len(torrent_ids)
|
||||||
|
|
||||||
def get_dht_nodes(callback):
|
|
||||||
get_core().call("get_dht_nodes", callback)
|
|
||||||
|
|
||||||
def enable_plugin(plugin):
|
#has_callback+multicall
|
||||||
get_core().call("enable_plugin", None, plugin)
|
aclient.pause_torrent(torrent_ids)
|
||||||
|
aclient.force_call(block=True)
|
||||||
def disable_plugin(plugin):
|
for id in torrent_ids:
|
||||||
get_core().call("disable_plugin", None, plugin)
|
aclient.get_torrent_status(cb_torrent_status_paused, id , ['paused'])
|
||||||
|
|
||||||
def force_recheck(torrent_ids):
|
aclient.get_torrent_status(cb_torrent_status_full, torrent_ids[0], [])
|
||||||
"""Forces a data recheck on torrent_ids"""
|
|
||||||
get_core().call("force_recheck", None, torrent_ids)
|
|
||||||
|
|
||||||
def set_torrent_trackers(torrent_id, trackers):
|
print "force_call 2"
|
||||||
"""Sets the torrents trackers"""
|
aclient.force_call(block=True)
|
||||||
get_core().call("set_torrent_trackers", None, torrent_id, trackers)
|
print "end force-call 2"
|
||||||
|
|
||||||
def set_torrent_max_connections(torrent_id, value):
|
|
||||||
"""Sets a torrents max number of connections"""
|
|
||||||
get_core().call("set_torrent_max_connections", None, torrent_id, value)
|
|
||||||
|
|
||||||
def set_torrent_max_upload_slots(torrent_id, value):
|
|
||||||
"""Sets a torrents max number of upload slots"""
|
|
||||||
get_core().call("set_torrent_max_upload_slots", None, torrent_id, value)
|
|
||||||
|
|
||||||
def set_torrent_max_upload_speed(torrent_id, value):
|
|
||||||
"""Sets a torrents max upload speed"""
|
|
||||||
get_core().call("set_torrent_max_upload_speed", None, torrent_id, value)
|
|
||||||
|
|
||||||
def set_torrent_max_download_speed(torrent_id, value):
|
|
||||||
"""Sets a torrents max download speed"""
|
|
||||||
get_core().call("set_torrent_max_download_speed", None, torrent_id, value)
|
|
||||||
|
|
||||||
def set_torrent_private_flag(torrent_id, value):
|
print "resume:"
|
||||||
"""Sets a torrents private flag"""
|
aclient.resume_torrent(torrent_ids)
|
||||||
get_core().call("set_torrent_private_flag", None, torrent_id, value)
|
for id in torrent_ids:
|
||||||
|
aclient.get_torrent_status(cb_torrent_status_paused, id , ['paused'])
|
||||||
|
|
||||||
def set_torrent_file_priorities(torrent_id, priorities):
|
aclient.force_call(block=True)
|
||||||
"""Sets a torrents file priorities"""
|
|
||||||
get_core().call("set_torrent_file_priorities", None, torrent_id, priorities)
|
|
||||||
|
|
||||||
def block_ip_range(range):
|
if __name__ == "__main__":
|
||||||
"""Blocks a ip range.. (start, end)"""
|
test_introspection()
|
||||||
get_core().call("block_ip_range", None, range)
|
test_sync()
|
||||||
|
test_async()
|
||||||
|
|
|
@ -37,7 +37,7 @@ import gtk
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
|
|
||||||
class AboutDialog:
|
class AboutDialog:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
@ -38,7 +38,7 @@ import gettext
|
||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.ui.gtkui.listview as listview
|
import deluge.ui.gtkui.listview as listview
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager
|
||||||
|
|
|
@ -42,7 +42,7 @@ import threading
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.xmlrpclib as xmlrpclib
|
import deluge.xmlrpclib as xmlrpclib
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
# statement from all source files in the program, then also delete it here.
|
# statement from all source files in the program, then also delete it here.
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
class CoreConfig(component.Component):
|
class CoreConfig(component.Component):
|
||||||
|
|
|
@ -46,7 +46,7 @@ elif dbus.version >= (0,80,0):
|
||||||
DBusGMainLoop(set_as_default=True)
|
DBusGMainLoop(set_as_default=True)
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.common
|
import deluge.common
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ import gtk, gtk.glade
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ import pkg_resources
|
||||||
import signal
|
import signal
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
from mainwindow import MainWindow
|
from mainwindow import MainWindow
|
||||||
from menubar import MenuBar
|
from menubar import MenuBar
|
||||||
from toolbar import ToolBar
|
from toolbar import ToolBar
|
||||||
|
|
|
@ -37,7 +37,7 @@ import gtk, gtk.glade
|
||||||
import gobject
|
import gobject
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ import gtk, gtk.glade
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.common as common
|
import deluge.common as common
|
||||||
|
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.pluginmanagerbase
|
import deluge.pluginmanagerbase
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ import pkg_resources
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.common
|
import deluge.common
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ import gobject
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.common
|
import deluge.common
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
|
@ -35,7 +35,7 @@ import gtk, gtk.glade
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
# statement from all source files in the program, then also delete it here.
|
# statement from all source files in the program, then also delete it here.
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
from deluge.ui.signalreceiver import SignalReceiver
|
from deluge.ui.signalreceiver import SignalReceiver
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ import gtk
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
class StatusBarItem:
|
class StatusBarItem:
|
||||||
|
|
|
@ -35,7 +35,7 @@ import gtk
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.common
|
import deluge.common
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
|
@ -39,7 +39,7 @@ import gobject
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
from deluge.common import TORRENT_STATE
|
from deluge.common import TORRENT_STATE
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
|
|
||||||
class ToolBar(component.Component):
|
class ToolBar(component.Component):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
|
@ -39,7 +39,7 @@ import gtk, gtk.glade
|
||||||
import gettext
|
import gettext
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.common
|
import deluge.common
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ import traceback
|
||||||
|
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
import deluge.ui.gtkui.listview as listview
|
import deluge.ui.gtkui.listview as listview
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ deluge-shell: Deluge shell.
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301
|
||||||
# USA
|
# USA
|
||||||
|
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.common as common
|
import deluge.common as common
|
||||||
import deluge.error
|
import deluge.error
|
||||||
import readline
|
import readline
|
||||||
|
|
|
@ -37,7 +37,7 @@ import random
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
import deluge.ui.client as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.SimpleXMLRPCServer as SimpleXMLRPCServer
|
import deluge.SimpleXMLRPCServer as SimpleXMLRPCServer
|
||||||
from SocketServer import ThreadingMixIn
|
from SocketServer import ThreadingMixIn
|
||||||
import deluge.xmlrpclib as xmlrpclib
|
import deluge.xmlrpclib as xmlrpclib
|
||||||
|
|
Loading…
Reference in New Issue