Import the 0.6 xmlrpc branch.. Work in progess.

This commit is contained in:
Andrew Resch 2007-10-12 23:37:42 +00:00
parent 2b9d8cc670
commit b4cb4e7bcc
8 changed files with 153 additions and 221 deletions

View File

@ -31,15 +31,17 @@
# this exception statement from your version. If you delete this exception # this exception statement from your version. If you delete this exception
# 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 dbus
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
import gettext import gettext
import locale import locale
import pkg_resources import pkg_resources
import sys
import pickle
import SimpleXMLRPCServer
from SocketServer import ThreadingMixIn
import xmlrpclib
import gobject import gobject
import threading
import deluge.libtorrent as lt import deluge.libtorrent as lt
from deluge.configmanager import ConfigManager from deluge.configmanager import ConfigManager
@ -73,9 +75,27 @@ DEFAULT_PREFS = {
"max_upload_slots_per_torrent": -1, "max_upload_slots_per_torrent": -1,
"enabled_plugins": ["Queue"] "enabled_plugins": ["Queue"]
} }
class Core(threading.Thread, ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
def __init__(self):
log.debug("Core init..")
threading.Thread.__init__(self)
class Core(dbus.service.Object): # Setup the xmlrpc server
def __init__(self, path="/org/deluge_torrent/Core"): try:
SimpleXMLRPCServer.SimpleXMLRPCServer.__init__(
self, ("localhost", 6666), logRequests=False, allow_none=True)
except:
log.info("Daemon already running or port not available..")
sys.exit(0)
# Register all export_* functions
for func in dir(self):
if func.startswith("export_"):
self.register_function(getattr(self, "%s" % func), func[7:])
self.register_introspection_functions()
# Initialize gettext # Initialize gettext
locale.setlocale(locale.LC_MESSAGES, '') locale.setlocale(locale.LC_MESSAGES, '')
locale.bindtextdomain("deluge", locale.bindtextdomain("deluge",
@ -89,13 +109,9 @@ class Core(dbus.service.Object):
gettext.install("deluge", gettext.install("deluge",
pkg_resources.resource_filename( pkg_resources.resource_filename(
"deluge", "i18n")) "deluge", "i18n"))
log.debug("Core init..")
# Setup DBUS def run(self):
bus_name = dbus.service.BusName("org.deluge_torrent.Deluge", """Starts the core"""
bus=dbus.SessionBus())
dbus.service.Object.__init__(self, bus_name, path)
# Get config # Get config
self.config = ConfigManager("core.conf", DEFAULT_PREFS) self.config = ConfigManager("core.conf", DEFAULT_PREFS)
@ -119,29 +135,29 @@ class Core(dbus.service.Object):
# Register set functions in the Config # Register set functions in the Config
self.config.register_set_function("listen_ports", self.config.register_set_function("listen_ports",
self.on_set_listen_ports) self._on_set_listen_ports)
self.config.register_set_function("random_port", self.config.register_set_function("random_port",
self.on_set_random_port) self._on_set_random_port)
self.config.register_set_function("dht", self.on_set_dht) self.config.register_set_function("dht", self._on_set_dht)
self.config.register_set_function("upnp", self.on_set_upnp) self.config.register_set_function("upnp", self._on_set_upnp)
self.config.register_set_function("natpmp", self.on_set_natpmp) self.config.register_set_function("natpmp", self._on_set_natpmp)
self.config.register_set_function("utpex", self.on_set_utpex) self.config.register_set_function("utpex", self._on_set_utpex)
self.config.register_set_function("enc_in_policy", self.config.register_set_function("enc_in_policy",
self.on_set_encryption) self._on_set_encryption)
self.config.register_set_function("enc_out_policy", self.config.register_set_function("enc_out_policy",
self.on_set_encryption) self._on_set_encryption)
self.config.register_set_function("enc_level", self.config.register_set_function("enc_level",
self.on_set_encryption) self._on_set_encryption)
self.config.register_set_function("enc_prefer_rc4", self.config.register_set_function("enc_prefer_rc4",
self.on_set_encryption) self._on_set_encryption)
self.config.register_set_function("max_connections_global", self.config.register_set_function("max_connections_global",
self.on_set_max_connections_global) self._on_set_max_connections_global)
self.config.register_set_function("max_upload_speed", self.config.register_set_function("max_upload_speed",
self.on_set_max_upload_speed) self._on_set_max_upload_speed)
self.config.register_set_function("max_download_speed", self.config.register_set_function("max_download_speed",
self.on_set_max_download_speed) self._on_set_max_download_speed)
self.config.register_set_function("max_upload_slots_global", self.config.register_set_function("max_upload_slots_global",
self.on_set_max_upload_slots_global) self._on_set_max_upload_slots_global)
# Start the AlertManager # Start the AlertManager
self.alerts = AlertManager(self.session) self.alerts = AlertManager(self.session)
@ -154,16 +170,18 @@ class Core(dbus.service.Object):
# Register alert handlers # Register alert handlers
self.alerts.register_handler("torrent_paused_alert", self.alerts.register_handler("torrent_paused_alert",
self.on_alert_torrent_paused) self._on_alert_torrent_paused)
log.debug("Starting main loop..") t = threading.Thread(target=self.serve_forever)
t.start()
gobject.threads_init()
self.loop = gobject.MainLoop() self.loop = gobject.MainLoop()
self.loop.run() self.loop.run()
def _shutdown(self): def _shutdown(self):
"""This is called by a thread from shutdown()""" """This is called by a thread from shutdown()"""
log.info("Shutting down core..") log.info("Shutting down core..")
self.loop.quit()
self.plugins.shutdown() self.plugins.shutdown()
self.torrents.shutdown() self.torrents.shutdown()
# Make sure the config file has been saved # Make sure the config file has been saved
@ -171,25 +189,22 @@ class Core(dbus.service.Object):
del self.config del self.config
del deluge.configmanager del deluge.configmanager
del self.session del self.session
self.loop.quit()
# Exported Methods # Exported Methods
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_shutdown(self):
in_signature="", out_signature="")
def shutdown(self):
"""Shutdown the core""" """Shutdown the core"""
# Make shutdown an async call # Make shutdown an async call
gobject.idle_add(self._shutdown) gobject.idle_add(self._shutdown)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_add_torrent_file(self, filename, save_path, filedump):
in_signature="ssay", out_signature="b")
def add_torrent_file(self, filename, save_path, filedump):
"""Adds a torrent file to the libtorrent session """Adds a torrent file to the libtorrent session
This requires the torrents filename and a dump of it's content This requires the torrents filename and a dump of it's content
""" """
if save_path == "": if save_path == "":
save_path = None save_path = None
torrent_id = self.torrents.add(filename, filedump=filedump, torrent_id = self.torrents.add(filename, filedump=filedump.data,
save_path=save_path) save_path=save_path)
# Run the plugin hooks for 'post_torrent_add' # Run the plugin hooks for 'post_torrent_add'
@ -203,9 +218,7 @@ class Core(dbus.service.Object):
# Return False because the torrent was not added successfully # Return False because the torrent was not added successfully
return False return False
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_add_torrent_url(self, url, save_path):
in_signature="ss", out_signature="b")
def add_torrent_url(self, url, save_path):
log.info("Attempting to add url %s", url) log.info("Attempting to add url %s", url)
# Get the actual filename of the torrent from the url provided. # Get the actual filename of the torrent from the url provided.
@ -224,11 +237,9 @@ class Core(dbus.service.Object):
return False return False
# Add the torrent to session # Add the torrent to session
return self.add_torrent_file(filename, save_path, filedump) return self.export_add_torrent_file(filename, save_path, filedump)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_remove_torrent(self, torrent_id):
in_signature="s", out_signature="")
def remove_torrent(self, torrent_id):
log.debug("Removing torrent %s from the core.", torrent_id) log.debug("Removing torrent %s from the core.", torrent_id)
if self.torrents.remove(torrent_id): if self.torrents.remove(torrent_id):
# Run the plugin hooks for 'post_torrent_remove' # Run the plugin hooks for 'post_torrent_remove'
@ -236,43 +247,32 @@ class Core(dbus.service.Object):
# Emit the torrent_removed signal # Emit the torrent_removed signal
self.torrent_removed(torrent_id) self.torrent_removed(torrent_id)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_force_reannounce(self, torrent_id):
in_signature="s", out_signature="")
def force_reannounce(self, torrent_id):
log.debug("Forcing reannouncment to trackers of torrent %s", torrent_id) log.debug("Forcing reannouncment to trackers of torrent %s", torrent_id)
self.torrents.force_reannounce(torrent_id) self.torrents.force_reannounce(torrent_id)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_pause_torrent(self, torrent_id):
in_signature="s", out_signature="")
def pause_torrent(self, torrent_id):
log.debug("Pausing torrent %s", torrent_id) log.debug("Pausing torrent %s", torrent_id)
if not self.torrents.pause(torrent_id): if not self.torrents.pause(torrent_id):
log.warning("Error pausing torrent %s", torrent_id) log.warning("Error pausing torrent %s", torrent_id)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge") def export_pause_all_torrents(self):
def pause_all_torrents(self):
"""Pause all torrents in the session""" """Pause all torrents in the session"""
if not self.torrents.pause_all(): if not self.torrents.pause_all():
log.warning("Error pausing all torrents..") log.warning("Error pausing all torrents..")
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge") def export_resume_all_torrents(self):
def resume_all_torrents(self):
"""Resume all torrents in the session""" """Resume all torrents in the session"""
if self.torrents.resume_all(): if self.torrents.resume_all():
# Emit the 'torrent_all_resumed' signal # Emit the 'torrent_all_resumed' signal
self.torrent_all_resumed() self.torrent_all_resumed()
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_resume_torrent(self, torrent_id):
in_signature="s", out_signature="")
def resume_torrent(self, torrent_id):
log.debug("Resuming torrent %s", torrent_id) log.debug("Resuming torrent %s", torrent_id)
if self.torrents.resume(torrent_id): if self.torrents.resume(torrent_id):
self.torrent_resumed(torrent_id) self.torrent_resumed(torrent_id)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_get_torrent_status(self, torrent_id, keys):
in_signature="sas",
out_signature="a{sv}")
def get_torrent_status(self, torrent_id, keys):
# Convert the array of strings to a python list of strings # Convert the array of strings to a python list of strings
keys = deluge.common.pythonize(keys) keys = deluge.common.pythonize(keys)
# Build the status dictionary # Build the status dictionary
@ -286,33 +286,23 @@ class Core(dbus.service.Object):
leftover_fields = list(set(keys) - set(status.keys())) leftover_fields = list(set(keys) - set(status.keys()))
if len(leftover_fields) > 0: if len(leftover_fields) > 0:
status.update(self.plugins.get_status(torrent_id, leftover_fields)) status.update(self.plugins.get_status(torrent_id, leftover_fields))
return status return xmlrpclib.Binary(pickle.dumps(status))
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_get_session_state(self):
in_signature="",
out_signature="as")
def get_session_state(self):
"""Returns a list of torrent_ids in the session.""" """Returns a list of torrent_ids in the session."""
# Get the torrent list from the TorrentManager # Get the torrent list from the TorrentManager
return self.torrents.get_torrent_list() return self.torrents.get_torrent_list()
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge") def export_save_state(self):
def save_state(self):
"""Save the current session state to file.""" """Save the current session state to file."""
# Have the TorrentManager save it's state # Have the TorrentManager save it's state
self.torrents.save_state() self.torrents.save_state()
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_get_config(self):
in_signature="",
out_signature="a{sv}")
def get_config(self):
"""Get all the preferences as a dictionary""" """Get all the preferences as a dictionary"""
return self.config.get_config() return self.config.get_config()
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_get_config_value(self, key):
in_signature="s",
out_signature="v")
def get_config_value(self, key):
"""Get the config value for key""" """Get the config value for key"""
try: try:
value = self.config[key] value = self.config[key]
@ -320,105 +310,77 @@ class Core(dbus.service.Object):
return None return None
return value return value
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_set_config(self, config):
in_signature="a{sv}")
def set_config(self, config):
"""Set the config with values from dictionary""" """Set the config with values from dictionary"""
config = deluge.common.pythonize(config) config = deluge.common.pythonize(config)
# Load all the values into the configuration # Load all the values into the configuration
for key in config.keys(): for key in config.keys():
self.config[key] = config[key] self.config[key] = config[key]
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_get_listen_port(self):
out_signature="i")
def get_listen_port(self):
"""Returns the active listen port""" """Returns the active listen port"""
return self.session.listen_port() return self.session.listen_port()
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_get_num_connections(self):
out_signature="i")
def get_num_connections(self):
"""Returns the current number of connections""" """Returns the current number of connections"""
return self.session.num_connections() return self.session.num_connections()
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_get_download_rate(self):
out_signature="d")
def get_download_rate(self):
"""Returns the payload download rate""" """Returns the payload download rate"""
return self.session.status().payload_download_rate return self.session.status().payload_download_rate
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_get_upload_rate(self):
out_signature="d")
def get_upload_rate(self):
"""Returns the payload upload rate""" """Returns the payload upload rate"""
return self.session.status().payload_upload_rate return self.session.status().payload_upload_rate
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_get_available_plugins(self):
out_signature="as")
def get_available_plugins(self):
"""Returns a list of plugins available in the core""" """Returns a list of plugins available in the core"""
return self.plugins.get_available_plugins() return self.plugins.get_available_plugins()
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_get_enabled_plugins(self):
out_signature="as")
def get_enabled_plugins(self):
"""Returns a list of enabled plugins in the core""" """Returns a list of enabled plugins in the core"""
return self.plugins.get_enabled_plugins() return self.plugins.get_enabled_plugins()
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_enable_plugin(self, plugin):
in_signature="s")
def enable_plugin(self, plugin):
self.plugins.enable_plugin(plugin) self.plugins.enable_plugin(plugin)
@dbus.service.method(dbus_interface="org.deluge_torrent.Deluge", def export_disable_plugin(self, plugin):
in_signature="s")
def disable_plugin(self, plugin):
self.plugins.disable_plugin(plugin) self.plugins.disable_plugin(plugin)
# Signals # Signals
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge",
signature="s")
def torrent_added(self, torrent_id): def torrent_added(self, torrent_id):
"""Emitted when a new torrent is added to the core""" """Emitted when a new torrent is added to the core"""
log.debug("torrent_added signal emitted") log.debug("torrent_added signal emitted")
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge",
signature="s")
def torrent_removed(self, torrent_id): def torrent_removed(self, torrent_id):
"""Emitted when a torrent has been removed from the core""" """Emitted when a torrent has been removed from the core"""
log.debug("torrent_remove signal emitted") log.debug("torrent_remove signal emitted")
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge",
signature="s")
def torrent_paused(self, torrent_id): def torrent_paused(self, torrent_id):
"""Emitted when a torrent is paused""" """Emitted when a torrent is paused"""
log.debug("torrent_paused signal emitted") log.debug("torrent_paused signal emitted")
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge",
signature="s")
def torrent_resumed(self, torrent_id): def torrent_resumed(self, torrent_id):
"""Emitted when a torrent is resumed""" """Emitted when a torrent is resumed"""
log.debug("torrent_resumed signal emitted") log.debug("torrent_resumed signal emitted")
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge")
def torrent_all_paused(self): def torrent_all_paused(self):
"""Emitted when all torrents have been paused""" """Emitted when all torrents have been paused"""
log.debug("torrent_all_paused signal emitted") log.debug("torrent_all_paused signal emitted")
@dbus.service.signal(dbus_interface="org.deluge_torrent.Deluge")
def torrent_all_resumed(self): def torrent_all_resumed(self):
"""Emitted when all torrents have been resumed""" """Emitted when all torrents have been resumed"""
log.debug("torrent_all_resumed signal emitted") log.debug("torrent_all_resumed signal emitted")
# Config set functions # Config set functions
def on_set_listen_ports(self, key, value): def _on_set_listen_ports(self, key, value):
# Only set the listen ports if random_port is not true # Only set the listen ports if random_port is not true
if self.config["random_port"] is not True: if self.config["random_port"] is not True:
log.debug("listen port range set to %s-%s", value[0], value[1]) log.debug("listen port range set to %s-%s", value[0], value[1])
self.session.listen_on(value[0], value[1]) self.session.listen_on(value[0], value[1])
def on_set_random_port(self, key, value): def _on_set_random_port(self, key, value):
log.debug("random port value set to %s", value) log.debug("random port value set to %s", value)
# We need to check if the value has been changed to true and false # We need to check if the value has been changed to true and false
# and then handle accordingly. # and then handle accordingly.
@ -436,33 +398,33 @@ class Core(dbus.service.Object):
listen_ports[1]) listen_ports[1])
self.session.listen_on(listen_ports[0], listen_ports[1]) self.session.listen_on(listen_ports[0], listen_ports[1])
def on_set_dht(self, key, value): def _on_set_dht(self, key, value):
log.debug("dht value set to %s", value) log.debug("dht value set to %s", value)
if value: if value:
self.session.start_dht(None) self.session.start_dht(None)
else: else:
self.session.stop_dht() self.session.stop_dht()
def on_set_upnp(self, key, value): def _on_set_upnp(self, key, value):
log.debug("upnp value set to %s", value) log.debug("upnp value set to %s", value)
if value: if value:
self.session.start_upnp() self.session.start_upnp()
else: else:
self.session.stop_upnp() self.session.stop_upnp()
def on_set_natpmp(self, key, value): def _on_set_natpmp(self, key, value):
log.debug("natpmp value set to %s", value) log.debug("natpmp value set to %s", value)
if value: if value:
self.session.start_natpmp() self.session.start_natpmp()
else: else:
self.session.stop_natpmp() self.session.stop_natpmp()
def on_set_utpex(self, key, value): def _on_set_utpex(self, key, value):
log.debug("utpex value set to %s", value) log.debug("utpex value set to %s", value)
if value: if value:
self.session.add_extension(lt.create_ut_pex_plugin) self.session.add_extension(lt.create_ut_pex_plugin)
def on_set_encryption(self, key, value): def _on_set_encryption(self, key, value):
log.debug("encryption value %s set to %s..", key, value) log.debug("encryption value %s set to %s..", key, value)
pe_settings = lt.pe_settings() pe_settings = lt.pe_settings()
pe_settings.out_enc_policy = \ pe_settings.out_enc_policy = \
@ -479,26 +441,26 @@ class Core(dbus.service.Object):
set.allowed_enc_level, set.allowed_enc_level,
set.prefer_rc4) set.prefer_rc4)
def on_set_max_connections_global(self, key, value): def _on_set_max_connections_global(self, key, value):
log.debug("max_connections_global set to %s..", value) log.debug("max_connections_global set to %s..", value)
self.session.set_max_connections(value) self.session.set_max_connections(value)
def on_set_max_upload_speed(self, key, value): def _on_set_max_upload_speed(self, key, value):
log.debug("max_upload_speed set to %s..", value) log.debug("max_upload_speed set to %s..", value)
# We need to convert Kb/s to B/s # We need to convert Kb/s to B/s
self.session.set_upload_rate_limit(int(value * 1024)) self.session.set_upload_rate_limit(int(value * 1024))
def on_set_max_download_speed(self, key, value): def _on_set_max_download_speed(self, key, value):
log.debug("max_download_speed set to %s..", value) log.debug("max_download_speed set to %s..", value)
# We need to convert Kb/s to B/s # We need to convert Kb/s to B/s
self.session.set_download_rate_limit(int(value * 1024)) self.session.set_download_rate_limit(int(value * 1024))
def on_set_max_upload_slots_global(self, key, value): def _on_set_max_upload_slots_global(self, key, value):
log.debug("max_upload_slots_global set to %s..", value) log.debug("max_upload_slots_global set to %s..", value)
self.session.set_max_uploads(value) self.session.set_max_uploads(value)
## Alert handlers ## ## Alert handlers ##
def on_alert_torrent_paused(self, alert): def _on_alert_torrent_paused(self, alert):
log.debug("on_alert_torrent_paused") log.debug("on_alert_torrent_paused")
# Get the torrent_id # Get the torrent_id
torrent_id = str(alert.handle.info_hash()) torrent_id = str(alert.handle.info_hash())

View File

@ -31,23 +31,13 @@
# this exception statement from your version. If you delete this exception # this exception statement from your version. If you delete this exception
# 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 dbus
from dbus.mainloop.glib import DBusGMainLoop
from deluge.core.core import Core from deluge.core.core import Core
from deluge.log import LOG as log from deluge.log import LOG as log
class Daemon: class Daemon:
def __init__(self): def __init__(self):
# Check to see if the daemon is already running and if not, start it # Start the core as a thread and join it until it's done
bus = dbus.SessionBus() self.core = Core()
obj = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus") self.core.start()
iface = dbus.Interface(obj, "org.freedesktop.DBus") self.core.join()
if iface.NameHasOwner("org.deluge_torrent.Deluge"):
# Daemon is running so lets tell the user
log.info("Daemon is already running..")
else:
# Daemon is not running so lets start up the core
log.debug("Daemon is not running..")
self.core = Core()

View File

@ -32,10 +32,12 @@
# 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 os.path import os.path
import pickle
import dbus import xmlrpclib
from dbus.mainloop.glib import DBusGMainLoop #import dbus
DBusGMainLoop(set_as_default=True) #from dbus.mainloop.glib import DBusGMainLoop
#DBusGMainLoop(set_as_default=True)
import pygtk import pygtk
pygtk.require('2.0') pygtk.require('2.0')
@ -44,16 +46,22 @@ import gtk, gtk.glade
import deluge.common import deluge.common
from deluge.log import LOG as log from deluge.log import LOG as log
class CoreProxy:
def __init__(self):
self._core = None
def get_core(self):
if self._core is None:
log.debug("Creating ServerProxy..")
self._core = xmlrpclib.ServerProxy("http://localhost:6666")
return self._core
_core = CoreProxy()
def get_core(): def get_core():
"""Get the core object and return it""" """Get the core object and return it"""
log.debug("Getting core proxy object from DBUS..") return _core.get_core()
# Get the proxy object from DBUS
bus = dbus.SessionBus()
proxy = bus.get_object("org.deluge_torrent.Deluge",
"/org/deluge_torrent/Core")
core = dbus.Interface(proxy, "org.deluge_torrent.Deluge")
log.debug("Got core proxy object..")
return core
def get_core_plugin(plugin): def get_core_plugin(plugin):
"""Get the core plugin object and return it""" """Get the core plugin object and return it"""
@ -66,9 +74,7 @@ def get_core_plugin(plugin):
def shutdown(): def shutdown():
"""Shutdown the core daemon""" """Shutdown the core daemon"""
core = get_core() get_core().shutdown()
core.shutdown()
return
def add_torrent_file(torrent_files): def add_torrent_file(torrent_files):
"""Adds torrent files to the core """Adds torrent files to the core
@ -78,25 +84,25 @@ def add_torrent_file(torrent_files):
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)
core = get_core()
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.
f = open(torrent_file, "rb") f = open(torrent_file, "rb")
# Get the filename because the core doesn't want a path. # Get the filename because the core doesn't want a path.
(path, filename) = os.path.split(torrent_file) (path, filename) = os.path.split(torrent_file)
result = core.add_torrent_file(filename, str(), f.read()) fdump = xmlrpclib.Binary(f.read())
f.close() f.close()
result = get_core().add_torrent_file(filename, str(), fdump)
if result is False: if result is False:
# The torrent was not added successfully. # The torrent was not added successfully.
log.warning("Torrent %s was not added successfully.", filename) log.warning("Torrent %s was not added successfully.", filename)
def add_torrent_url(torrent_url): def add_torrent_url(torrent_url):
"""Adds torrents to the core via url""" """Adds torrents to the core via url"""
core = get_core()
from deluge.common import is_url from deluge.common import is_url
if is_url(torrent_url): if is_url(torrent_url):
result = core.add_torrent_url(torrent_url, str()) result = get_core().add_torrent_url(torrent_url, str())
if result is False: if result is False:
# The torrent url was not added successfully. # The torrent url was not added successfully.
log.warning("Torrent %s was not added successfully.", torrent_url) log.warning("Torrent %s was not added successfully.", torrent_url)
@ -106,69 +112,52 @@ def add_torrent_url(torrent_url):
def remove_torrent(torrent_ids): def remove_torrent(torrent_ids):
"""Removes torrent_ids from the core.. Expects a list of torrent_ids""" """Removes torrent_ids from the core.. Expects a list of torrent_ids"""
log.debug("Attempting to removing torrents: %s", torrent_ids) log.debug("Attempting to removing torrents: %s", torrent_ids)
core = get_core()
for torrent_id in torrent_ids: for torrent_id in torrent_ids:
core.remove_torrent(torrent_id) get_core().remove_torrent(torrent_id)
def pause_torrent(torrent_ids): def pause_torrent(torrent_ids):
"""Pauses torrent_ids""" """Pauses torrent_ids"""
core = get_core()
for torrent_id in torrent_ids: for torrent_id in torrent_ids:
core.pause_torrent(torrent_id) get_core().pause_torrent(torrent_id)
def resume_torrent(torrent_ids): def resume_torrent(torrent_ids):
"""Resume torrent_ids""" """Resume torrent_ids"""
core = get_core()
for torrent_id in torrent_ids: for torrent_id in torrent_ids:
core.resume_torrent(torrent_id) get_core().resume_torrent(torrent_id)
def force_reannounce(torrent_ids): def force_reannounce(torrent_ids):
"""Reannounce to trackers""" """Reannounce to trackers"""
core = get_core()
for torrent_id in torrent_ids: for torrent_id in torrent_ids:
core.force_reannounce(torrent_id) get_core().force_reannounce(torrent_id)
def get_torrent_status(core, torrent_id, keys): def get_torrent_status(torrent_id, keys):
"""Builds the status dictionary and returns it""" """Builds the status dictionary and returns it"""
return deluge.common.pythonize(core.get_torrent_status(torrent_id, keys)) status = get_core().get_torrent_status(torrent_id, keys)
return pickle.loads(status.data)
def get_session_state(core=None): def get_session_state():
# Get the core if not supplied return get_core().get_session_state()
if core is None:
core = get_core()
return deluge.common.pythonize(core.get_session_state())
def get_config(core=None):
if core is None:
core = get_core()
return deluge.common.pythonize(core.get_config())
def get_config_value(key, core=None): def get_config():
if core is None: return get_core().get_config()
core = get_core()
return deluge.common.pythonize(core.get_config_value(key)) def get_config_value(key):
return get_core().get_config_value(key)
def set_config(config, core=None): def set_config(config):
if config == {}: if config == {}:
return return
if core is None: get_core().set_config(config)
core = get_core()
core.set_config(config)
def get_listen_port(core=None): def get_listen_port():
if core is None: return int(get_core().get_listen_port())
core = get_core()
return int(core.get_listen_port())
def get_available_plugins(core=None): def get_available_plugins():
if core is None: return get_core().get_available_plugins()
core = get_core()
return deluge.common.pythonize(core.get_available_plugins())
def get_enabled_plugins(core=None): def get_enabled_plugins():
if core is None: return get_core().get_enabled_plugins()
core = get_core()
return deluge.common.pythonize(core.get_enabled_plugins())
def open_url_in_browser(url): def open_url_in_browser(url):
"""Opens link in the desktop's default browser""" """Opens link in the desktop's default browser"""

View File

@ -93,7 +93,7 @@ class GtkUI:
self.mainwindow = MainWindow() self.mainwindow = MainWindow()
# Start the signal receiver # Start the signal receiver
self.signal_receiver = Signals(self) #self.signal_receiver = Signals(self)
# Initalize the plugins # Initalize the plugins
self.plugins = PluginManager(self) self.plugins = PluginManager(self)
@ -112,6 +112,6 @@ class GtkUI:
# Clean-up # Clean-up
del self.mainwindow del self.mainwindow
del self.signal_receiver #del self.signal_receiver
del self.plugins del self.plugins
del deluge.configmanager del deluge.configmanager

View File

@ -74,8 +74,7 @@ class StatusBar:
def update(self): def update(self):
# Set the max connections label # Set the max connections label
max_connections = functions.get_config_value("max_connections_global", max_connections = functions.get_config_value("max_connections_global")
core=self.core)
if max_connections < 0: if max_connections < 0:
max_connections = _("Unlimited") max_connections = _("Unlimited")
@ -83,8 +82,7 @@ class StatusBar:
self.core.get_num_connections(), max_connections)) self.core.get_num_connections(), max_connections))
# Set the download speed label # Set the download speed label
max_download_speed = functions.get_config_value("max_download_speed", max_download_speed = functions.get_config_value("max_download_speed")
core=self.core)
if max_download_speed < 0: if max_download_speed < 0:
max_download_speed = _("Unlimited") max_download_speed = _("Unlimited")
else: else:
@ -95,8 +93,7 @@ class StatusBar:
max_download_speed)) max_download_speed))
# Set the upload speed label # Set the upload speed label
max_upload_speed = functions.get_config_value("max_upload_speed", max_upload_speed = functions.get_config_value("max_upload_speed")
core=self.core)
if max_upload_speed < 0: if max_upload_speed < 0:
max_upload_speed = _("Unlimited") max_upload_speed = _("Unlimited")
else: else:

View File

@ -86,14 +86,13 @@ class SystemTray:
# Create the Download speed list sub-menu # Create the Download speed list sub-menu
submenu_bwdownset = self.build_menu_radio_list( submenu_bwdownset = self.build_menu_radio_list(
self.config["tray_download_speed_list"], self.tray_setbwdown, self.config["tray_download_speed_list"], self.tray_setbwdown,
functions.get_config_value("max_download_speed", functions.get_config_value("max_download_speed"),
core=self.core), _("KiB/s"), show_notset=True, _("KiB/s"), show_notset=True, show_other=True)
show_other=True)
# Create the Upload speed list sub-menu # Create the Upload speed list sub-menu
submenu_bwupset = self.build_menu_radio_list( submenu_bwupset = self.build_menu_radio_list(
self.config["tray_upload_speed_list"], self.tray_setbwup, self.config["tray_upload_speed_list"], self.tray_setbwup,
functions.get_config_value("max_upload_speed", core=self.core), functions.get_config_value("max_upload_speed"),
_("KiB/s"), show_notset=True, show_other=True) _("KiB/s"), show_notset=True, show_other=True)
# Add the sub-menus to the tray menu # Add the sub-menus to the tray menu
@ -282,7 +281,7 @@ class SystemTray:
spin_title.set_text(_("%s Speed (KiB/s):" % string)) spin_title.set_text(_("%s Speed (KiB/s):" % string))
spin_speed = dialog_glade.get_widget("spin_speed") spin_speed = dialog_glade.get_widget("spin_speed")
spin_speed.set_value( spin_speed.set_value(
functions.get_config_value(core_key, core=self.core)) functions.get_config_value(core_key))
spin_speed.select_region(0, -1) spin_speed.select_region(0, -1)
response = speed_dialog.run() response = speed_dialog.run()
if response == 1: # OK Response if response == 1: # OK Response
@ -295,7 +294,7 @@ class SystemTray:
# Set the config in the core # Set the config in the core
value = float(value) value = float(value)
config_to_set = {core_key: value} config_to_set = {core_key: value}
functions.set_config(config_to_set, core=self.core) functions.set_config(config_to_set)
# Update the tray speed limit list # Update the tray speed limit list
if value not in self.config[ui_key] and value >= 0: if value not in self.config[ui_key] and value >= 0:

View File

@ -47,8 +47,6 @@ class TorrentDetails:
self.window = window self.window = window
glade = self.window.main_glade glade = self.window.main_glade
self.core = functions.get_core()
self.notebook = glade.get_widget("torrent_info") self.notebook = glade.get_widget("torrent_info")
self.details_tab = glade.get_widget("torrentdetails_tab") self.details_tab = glade.get_widget("torrentdetails_tab")
@ -95,9 +93,7 @@ class TorrentDetails:
"upload_payload_rate", "num_peers", "num_seeds", "total_peers", "upload_payload_rate", "num_peers", "num_seeds", "total_peers",
"total_seeds", "eta", "ratio", "tracker", "next_announce", "total_seeds", "eta", "ratio", "tracker", "next_announce",
"tracker_status", "save_path"] "tracker_status", "save_path"]
status = functions.get_torrent_status(self.core, status = functions.get_torrent_status(selected, status_keys)
selected,
status_keys)
# Check to see if we got valid data from the core # Check to see if we got valid data from the core
if status is None: if status is None:

View File

@ -104,7 +104,6 @@ class TorrentView(listview.ListView):
listview.ListView.__init__(self, listview.ListView.__init__(self,
self.window.main_glade.get_widget("torrent_view")) self.window.main_glade.get_widget("torrent_view"))
log.debug("TorrentView Init..") log.debug("TorrentView Init..")
self.core = functions.get_core()
# Register the columns menu with the listview so it gets updated # Register the columns menu with the listview so it gets updated
# accordingly. # accordingly.
@ -166,7 +165,7 @@ class TorrentView(listview.ListView):
# We need to get the core session state to know which torrents are in # We need to get the core session state to know which torrents are in
# the session so we can add them to our list. # the session so we can add them to our list.
session_state = functions.get_session_state(self.core) session_state = functions.get_session_state()
for torrent_id in session_state: for torrent_id in session_state:
self.add_row(torrent_id) self.add_row(torrent_id)
@ -213,7 +212,7 @@ class TorrentView(listview.ListView):
# Remove duplicates from status_key list # Remove duplicates from status_key list
status_keys = list(set(status_keys)) status_keys = list(set(status_keys))
status = functions.get_torrent_status(self.core, torrent_id, status = functions.get_torrent_status(torrent_id,
status_keys) status_keys)
# Set values for each column in the row # Set values for each column in the row