Remove the decorator class and just raise the NoCoreError in
CoreProxy.call().
This commit is contained in:
parent
e95be5d131
commit
72cb14f1d7
|
@ -43,18 +43,7 @@ import deluge.xmlrpclib as xmlrpclib
|
|||
import deluge.common
|
||||
import deluge.error
|
||||
from deluge.log import LOG as log
|
||||
|
||||
class no_core_error:
|
||||
# This decorator class will throw a NoCoreError exception if core is None
|
||||
def __init__(self, func):
|
||||
self.func = func
|
||||
|
||||
def __call__(self, *__args, **__kw):
|
||||
if _core.get_core() == None:
|
||||
raise deluge.error.NoCoreError("The core proxy is invalid.")
|
||||
else:
|
||||
return self.func(*__args, **__kw)
|
||||
|
||||
|
||||
class CoreProxy(gobject.GObject):
|
||||
__gsignals__ = {
|
||||
"new_core" : (
|
||||
|
@ -74,6 +63,7 @@ class CoreProxy(gobject.GObject):
|
|||
def call(self, func, callback, *args):
|
||||
if self._core is None or self._multi is None:
|
||||
if self.get_core() is None:
|
||||
raise deluge.error.NoCoreError("The core proxy is invalid.")
|
||||
return
|
||||
_func = getattr(self._multi, func)
|
||||
|
||||
|
@ -188,15 +178,12 @@ def connected():
|
|||
return True
|
||||
return False
|
||||
|
||||
@no_core_error
|
||||
def register_client(port):
|
||||
get_core().call("register_client", None, port)
|
||||
|
||||
@no_core_error
|
||||
def deregister_client():
|
||||
get_core().call("deregister_client", None)
|
||||
|
||||
@no_core_error
|
||||
|
||||
def shutdown():
|
||||
"""Shutdown the core daemon"""
|
||||
try:
|
||||
|
@ -206,13 +193,11 @@ def shutdown():
|
|||
# Ignore everything
|
||||
set_core_uri(None)
|
||||
|
||||
@no_core_error
|
||||
def force_call(block=True):
|
||||
"""Forces the multicall batch to go now and not wait for the timer. This
|
||||
call also blocks until all callbacks have been dealt with."""
|
||||
get_core().do_multicall(block=block)
|
||||
|
||||
@no_core_error
|
||||
|
||||
def add_torrent_file(torrent_files, torrent_options=None):
|
||||
"""Adds torrent files to the core
|
||||
Expects a list of torrent files
|
||||
|
@ -248,7 +233,6 @@ def add_torrent_file(torrent_files, torrent_options=None):
|
|||
get_core().call("add_torrent_file", None,
|
||||
filename, str(), fdump, options)
|
||||
|
||||
@no_core_error
|
||||
def add_torrent_url(torrent_url, options=None):
|
||||
"""Adds torrents to the core via url"""
|
||||
from deluge.common import is_url
|
||||
|
@ -257,121 +241,97 @@ def add_torrent_url(torrent_url, options=None):
|
|||
torrent_url, str(), options)
|
||||
else:
|
||||
log.warning("Invalid URL %s", torrent_url)
|
||||
|
||||
@no_core_error
|
||||
|
||||
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 removing torrents: %s", torrent_ids)
|
||||
for torrent_id in torrent_ids:
|
||||
get_core().call("remove_torrent", None, torrent_id, remove_torrent, remove_data)
|
||||
|
||||
@no_core_error
|
||||
def pause_torrent(torrent_ids):
|
||||
"""Pauses torrent_ids"""
|
||||
for torrent_id in torrent_ids:
|
||||
get_core().call("pause_torrent", None, torrent_id)
|
||||
|
||||
@no_core_error
|
||||
def move_torrent(torrent_ids, folder):
|
||||
"""Pauses torrent_ids"""
|
||||
for torrent_id in torrent_ids:
|
||||
get_core().call("move_torrent", None, torrent_id, folder)
|
||||
|
||||
@no_core_error
|
||||
def pause_all_torrents():
|
||||
"""Pauses all torrents"""
|
||||
get_core().call("pause_all_torrents", None)
|
||||
|
||||
@no_core_error
|
||||
def resume_all_torrents():
|
||||
"""Resumes all torrents"""
|
||||
get_core().call("resume_all_torrents", None)
|
||||
|
||||
@no_core_error
|
||||
|
||||
def resume_torrent(torrent_ids):
|
||||
"""Resume torrent_ids"""
|
||||
for torrent_id in torrent_ids:
|
||||
get_core().call("resume_torrent", None, torrent_id)
|
||||
|
||||
@no_core_error
|
||||
|
||||
def force_reannounce(torrent_ids):
|
||||
"""Reannounce to trackers"""
|
||||
for torrent_id in torrent_ids:
|
||||
get_core().call("force_reannounce", None, torrent_id)
|
||||
|
||||
@no_core_error
|
||||
def get_torrent_status(callback, torrent_id, keys):
|
||||
"""Builds the status dictionary and returns it"""
|
||||
get_core().call("get_torrent_status", callback, torrent_id, keys)
|
||||
|
||||
@no_core_error
|
||||
def get_torrents_status(callback, torrent_ids, keys):
|
||||
"""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)
|
||||
|
||||
@no_core_error
|
||||
def get_session_state(callback):
|
||||
get_core().call("get_session_state", callback)
|
||||
|
||||
@no_core_error
|
||||
def get_config(callback):
|
||||
get_core().call("get_config", callback)
|
||||
|
||||
@no_core_error
|
||||
def get_config_value(callback, key):
|
||||
get_core().call("get_config_value", callback, key)
|
||||
|
||||
@no_core_error
|
||||
|
||||
def set_config(config):
|
||||
if config == {}:
|
||||
return
|
||||
get_core().call("set_config", None, config)
|
||||
|
||||
@no_core_error
|
||||
def get_listen_port(callback):
|
||||
get_core().call("get_listen_port", callback)
|
||||
|
||||
@no_core_error
|
||||
def get_available_plugins(callback):
|
||||
get_core().call("get_available_plugins", callback)
|
||||
|
||||
@no_core_error
|
||||
def get_enabled_plugins(callback):
|
||||
get_core().call("get_enabled_plugins", callback)
|
||||
|
||||
@no_core_error
|
||||
def get_download_rate(callback):
|
||||
get_core().call("get_download_rate", callback)
|
||||
|
||||
@no_core_error
|
||||
def get_upload_rate(callback):
|
||||
get_core().call("get_upload_rate", callback)
|
||||
|
||||
@no_core_error
|
||||
def get_num_connections(callback):
|
||||
get_core().call("get_num_connections", callback)
|
||||
|
||||
@no_core_error
|
||||
def get_dht_nodes(callback):
|
||||
get_core().call("get_dht_nodes", callback)
|
||||
|
||||
@no_core_error
|
||||
def enable_plugin(plugin):
|
||||
get_core().call("enable_plugin", None, plugin)
|
||||
|
||||
@no_core_error
|
||||
|
||||
def disable_plugin(plugin):
|
||||
get_core().call("disable_plugin", None, plugin)
|
||||
|
||||
@no_core_error
|
||||
def force_recheck(torrent_ids):
|
||||
"""Forces a data recheck on torrent_ids"""
|
||||
for torrent_id in torrent_ids:
|
||||
get_core().call("force_recheck", None, torrent_id)
|
||||
|
||||
@no_core_error
|
||||
def set_torrent_trackers(torrent_id, trackers):
|
||||
"""Sets the torrents trackers"""
|
||||
get_core().call("set_torrent_trackers", None, torrent_id, trackers)
|
||||
|
|
Loading…
Reference in New Issue