Get Classic mode working somewhat. There are still some issues to

resolve with it.
This commit is contained in:
Andrew Resch 2009-01-28 17:59:27 +00:00
parent 9f369388e6
commit e9f8c7b0e8
8 changed files with 63 additions and 39 deletions

View File

@ -22,8 +22,7 @@
# Boston, MA 02110-1301, USA. # Boston, MA 02110-1301, USA.
# #
from twisted.internet.task import LoopingCall
import gobject
from deluge.log import LOG as log from deluge.log import LOG as log
COMPONENT_STATE = [ COMPONENT_STATE = [
@ -49,7 +48,7 @@ class Component(object):
def _start(self): def _start(self):
self._state = COMPONENT_STATE.index("Started") self._state = COMPONENT_STATE.index("Started")
if self._update(): if self._update():
self._timer = gobject.timeout_add(self._interval, self._update) self._timer = LoopingCall(self._interval, self._update)
def stop(self): def stop(self):
pass pass
@ -57,14 +56,14 @@ class Component(object):
def _stop(self): def _stop(self):
self._state = COMPONENT_STATE.index("Stopped") self._state = COMPONENT_STATE.index("Stopped")
try: try:
gobject.source_remove(self._timer) self._timer.stop()
except: except:
pass pass
def _pause(self): def _pause(self):
self._state = COMPONENT_STATE.index("Paused") self._state = COMPONENT_STATE.index("Paused")
try: try:
gobject.source_remove(self._timer) self._timer.stop()
except: except:
pass pass

View File

@ -36,7 +36,7 @@ from deluge.core.rpcserver import RPCServer, export
from deluge.log import LOG as log from deluge.log import LOG as log
class Daemon(object): class Daemon(object):
def __init__(self, options, args): def __init__(self, options=None, args=None, classic=False):
# Initialize gettext # Initialize gettext
try: try:
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
@ -74,29 +74,36 @@ class Daemon(object):
log.debug("options: %s", options) log.debug("options: %s", options)
log.debug("args: %s", args) log.debug("args: %s", args)
# Set the config directory # Set the config directory
deluge.configmanager.set_config_dir(options.config) if options:
deluge.configmanager.set_config_dir(options.config)
from deluge.core.core import Core from deluge.core.core import Core
# Start the core as a thread and join it until it's done # Start the core as a thread and join it until it's done
self.core = Core() self.core = Core()
port = self.core.config["daemon_port"]
if options and options.port:
port = options.port
self.rpcserver = RPCServer( self.rpcserver = RPCServer(
port=options.port if options.port else self.core.config["daemon_port"], port=port,
allow_remote=self.core.config["allow_remote"] allow_remote=self.core.config["allow_remote"],
listen=not classic
) )
# Register the daemon and the core RPCs
self.rpcserver.register_object(self.core) self.rpcserver.register_object(self.core)
self.rpcserver.register_object(self) self.rpcserver.register_object(self)
# Make sure we start the PreferencesManager first # Make sure we start the PreferencesManager first
component.start("PreferencesManager") component.start("PreferencesManager")
component.start()
# reactor.run() if not classic:
try: component.start()
reactor.run() try:
except KeyboardInterrupt: reactor.run()
self.shutdown() except KeyboardInterrupt:
self.shutdown()
@export() @export()
def shutdown(self, *args, **kwargs): def shutdown(self, *args, **kwargs):

View File

@ -236,11 +236,22 @@ class RPCServer(component.Component):
:param port: int, the port the RPCServer will listen on :param port: int, the port the RPCServer will listen on
:param interface: str, the interface to listen on, this may override the `:param:allow_remote` setting :param interface: str, the interface to listen on, this may override the `:param:allow_remote` setting
:param allow_remote: bool, set True if the server should allow remote connections :param allow_remote: bool, set True if the server should allow remote connections
:param listen: bool, if False, will not start listening.. This is only useful in Classic Mode
""" """
def __init__(self, port=58846, interface="", allow_remote=False): def __init__(self, port=58846, interface="", allow_remote=False, listen=True):
component.Component.__init__(self, "RPCServer") component.Component.__init__(self, "RPCServer")
self.factory = Factory()
self.factory.protocol = DelugeRPCProtocol
# Holds the registered methods
self.factory.methods = {}
# Holds the session_ids and auth levels
self.factory.authorized_sessions = {}
if not listen:
return
if allow_remote: if allow_remote:
hostname = "" hostname = ""
else: else:
@ -251,13 +262,6 @@ class RPCServer(component.Component):
log.info("Starting DelugeRPC server %s:%s", hostname, port) log.info("Starting DelugeRPC server %s:%s", hostname, port)
self.factory = Factory()
self.factory.protocol = DelugeRPCProtocol
# Holds the registered methods
self.factory.methods = {}
# Holds the session_ids and auth levels
self.factory.authorized_sessions = {}
# Check for SSL cert/key and create them if necessary # Check for SSL cert/key and create them if necessary
ssl_dir = deluge.configmanager.get_config_dir("ssl") ssl_dir = deluge.configmanager.get_config_dir("ssl")
if not os.path.exists(ssl_dir): if not os.path.exists(ssl_dir):
@ -297,7 +301,6 @@ class RPCServer(component.Component):
self.factory.methods[name + "." + d] = getattr(obj, d) self.factory.methods[name + "." + d] = getattr(obj, d)
def get_object_method(self, name): def get_object_method(self, name):
log.debug(self.factory.methods)
return self.factory.methods[name] return self.factory.methods[name]
def __generate_ssl_keys(self): def __generate_ssl_keys(self):

View File

@ -391,21 +391,36 @@ class DaemonSSLProxy(DaemonProxy):
class DaemonClassicProxy(DaemonProxy): class DaemonClassicProxy(DaemonProxy):
def __init__(self): def __init__(self):
import daemon import deluge.core.daemon
self.__daemon = daemon.Daemon() self.__daemon = deluge.core.daemon.Daemon(classic=True)
log.debug("daemon created!")
self.connected = True self.connected = True
self.host = "localhost"
self.port = 58846
self.user = "localclient"
def disconnect(self):
self.__daemon = None
def call(self, method, *args, **kwargs): def call(self, method, *args, **kwargs):
log.debug("call: %s %s %s", method, args, kwargs) log.debug("call: %s %s %s", method, args, kwargs)
m = self.__daemon.rpcserver.get_object_method(method)
d = defer.Deferred() d = defer.Deferred()
try:
m = self.__daemon.rpcserver.get_object_method(method)
except Exception, e:
log.exception(e)
d.errback(e)
return d
try: try:
result = m(*args, **kwargs) result = m(*args, **kwargs)
except Exception, e: except Exception, e:
d.errback(e) d.errback(e)
else: else:
d.callbacks(result) d.callback(result)
return d return d
@ -502,7 +517,8 @@ class Client(object):
:returns: bool, True if connected to a localhost :returns: bool, True if connected to a localhost
""" """
if self._daemon_proxy and self._daemon_proxy.host in ("127.0.0.1", "localhost"): if self._daemon_proxy and self._daemon_proxy.host in ("127.0.0.1", "localhost") or\
isinstance(self._daemon_proxy, DaemonClassicProxy):
return True return True
return False return False

View File

@ -152,4 +152,4 @@ def get_localhost_auth():
if username == "localclient": if username == "localclient":
return (username, password) return (username, password)
return None return ("", "")

View File

@ -85,10 +85,6 @@ class ConnectionManager(component.Component):
component.Component.__init__(self, "ConnectionManager") component.Component.__init__(self, "ConnectionManager")
self.gtkui_config = ConfigManager("gtkui.conf") self.gtkui_config = ConfigManager("gtkui.conf")
if self.gtkui_config["classic_mode"]:
client.start_classic_mode()
return
self.config = ConfigManager("hostlist.conf.1.2", DEFAULT_CONFIG) self.config = ConfigManager("hostlist.conf.1.2", DEFAULT_CONFIG)
# Component overrides # Component overrides

View File

@ -243,11 +243,16 @@ class GtkUI:
def _on_reactor_start(self): def _on_reactor_start(self):
log.debug("_on_reactor_start") log.debug("_on_reactor_start")
# XXX: We need to call a simulate() here, but this could be a bug in twisted
reactor.simulate()
if self.config["show_connection_manager_on_start"] and not self.config["classic_mode"]: if self.config["show_connection_manager_on_start"] and not self.config["classic_mode"]:
# XXX: We need to call a simulate() here, but this could be a bug in twisted
reactor.simulate()
self.connectionmanager.show() self.connectionmanager.show()
if self.config["classic_mode"]:
client.start_classic_mode()
self._on_new_core()
return
def _on_new_core(self): def _on_new_core(self):
component.start() component.start()

View File

@ -174,15 +174,13 @@ class Preferences(component.Component):
# Update the preferences dialog to reflect current config settings # Update the preferences dialog to reflect current config settings
self.core_config = {} self.core_config = {}
try: if client.connected():
client.core.get_config().addCallback(self._on_get_config) client.core.get_config().addCallback(self._on_get_config)
client.core.get_available_plugins().addCallback(self._on_get_available_plugins) client.core.get_available_plugins().addCallback(self._on_get_available_plugins)
client.core.get_enabled_plugins().addCallback(self._on_get_enabled_plugins) client.core.get_enabled_plugins().addCallback(self._on_get_enabled_plugins)
client.core.get_listen_port().addCallback(self._on_get_listen_port) client.core.get_listen_port().addCallback(self._on_get_listen_port)
# Force these calls and block until we've done them all # Force these calls and block until we've done them all
client.force_call() client.force_call()
except deluge.error.NoCoreError:
log.debug("Not connected to a daemon..")
if self.core_config != {} and self.core_config != None: if self.core_config != {} and self.core_config != None:
core_widgets = { core_widgets = {