Get Classic mode working somewhat. There are still some issues to
resolve with it.
This commit is contained in:
parent
9f369388e6
commit
e9f8c7b0e8
|
@ -22,8 +22,7 @@
|
|||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
|
||||
import gobject
|
||||
from twisted.internet.task import LoopingCall
|
||||
from deluge.log import LOG as log
|
||||
|
||||
COMPONENT_STATE = [
|
||||
|
@ -49,7 +48,7 @@ class Component(object):
|
|||
def _start(self):
|
||||
self._state = COMPONENT_STATE.index("Started")
|
||||
if self._update():
|
||||
self._timer = gobject.timeout_add(self._interval, self._update)
|
||||
self._timer = LoopingCall(self._interval, self._update)
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
@ -57,14 +56,14 @@ class Component(object):
|
|||
def _stop(self):
|
||||
self._state = COMPONENT_STATE.index("Stopped")
|
||||
try:
|
||||
gobject.source_remove(self._timer)
|
||||
self._timer.stop()
|
||||
except:
|
||||
pass
|
||||
|
||||
def _pause(self):
|
||||
self._state = COMPONENT_STATE.index("Paused")
|
||||
try:
|
||||
gobject.source_remove(self._timer)
|
||||
self._timer.stop()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ from deluge.core.rpcserver import RPCServer, export
|
|||
from deluge.log import LOG as log
|
||||
|
||||
class Daemon(object):
|
||||
def __init__(self, options, args):
|
||||
def __init__(self, options=None, args=None, classic=False):
|
||||
# Initialize gettext
|
||||
try:
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
|
@ -74,29 +74,36 @@ class Daemon(object):
|
|||
log.debug("options: %s", options)
|
||||
log.debug("args: %s", args)
|
||||
# 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
|
||||
# Start the core as a thread and join it until it's done
|
||||
self.core = Core()
|
||||
|
||||
port = self.core.config["daemon_port"]
|
||||
if options and options.port:
|
||||
port = options.port
|
||||
self.rpcserver = RPCServer(
|
||||
port=options.port if options.port else self.core.config["daemon_port"],
|
||||
allow_remote=self.core.config["allow_remote"]
|
||||
port=port,
|
||||
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)
|
||||
|
||||
|
||||
# Make sure we start the PreferencesManager first
|
||||
component.start("PreferencesManager")
|
||||
component.start()
|
||||
|
||||
# reactor.run()
|
||||
try:
|
||||
reactor.run()
|
||||
except KeyboardInterrupt:
|
||||
self.shutdown()
|
||||
if not classic:
|
||||
component.start()
|
||||
try:
|
||||
reactor.run()
|
||||
except KeyboardInterrupt:
|
||||
self.shutdown()
|
||||
|
||||
@export()
|
||||
def shutdown(self, *args, **kwargs):
|
||||
|
|
|
@ -236,11 +236,22 @@ class RPCServer(component.Component):
|
|||
: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 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")
|
||||
|
||||
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:
|
||||
hostname = ""
|
||||
else:
|
||||
|
@ -251,13 +262,6 @@ class RPCServer(component.Component):
|
|||
|
||||
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
|
||||
ssl_dir = deluge.configmanager.get_config_dir("ssl")
|
||||
if not os.path.exists(ssl_dir):
|
||||
|
@ -297,7 +301,6 @@ class RPCServer(component.Component):
|
|||
self.factory.methods[name + "." + d] = getattr(obj, d)
|
||||
|
||||
def get_object_method(self, name):
|
||||
log.debug(self.factory.methods)
|
||||
return self.factory.methods[name]
|
||||
|
||||
def __generate_ssl_keys(self):
|
||||
|
|
|
@ -391,21 +391,36 @@ class DaemonSSLProxy(DaemonProxy):
|
|||
|
||||
class DaemonClassicProxy(DaemonProxy):
|
||||
def __init__(self):
|
||||
import daemon
|
||||
self.__daemon = daemon.Daemon()
|
||||
import deluge.core.daemon
|
||||
self.__daemon = deluge.core.daemon.Daemon(classic=True)
|
||||
log.debug("daemon created!")
|
||||
self.connected = True
|
||||
self.host = "localhost"
|
||||
self.port = 58846
|
||||
self.user = "localclient"
|
||||
|
||||
|
||||
|
||||
def disconnect(self):
|
||||
self.__daemon = None
|
||||
|
||||
def call(self, method, *args, **kwargs):
|
||||
log.debug("call: %s %s %s", method, args, kwargs)
|
||||
|
||||
m = self.__daemon.rpcserver.get_object_method(method)
|
||||
d = defer.Deferred()
|
||||
try:
|
||||
m = self.__daemon.rpcserver.get_object_method(method)
|
||||
except Exception, e:
|
||||
log.exception(e)
|
||||
d.errback(e)
|
||||
return d
|
||||
|
||||
try:
|
||||
result = m(*args, **kwargs)
|
||||
except Exception, e:
|
||||
d.errback(e)
|
||||
else:
|
||||
d.callbacks(result)
|
||||
d.callback(result)
|
||||
return d
|
||||
|
||||
|
||||
|
@ -502,7 +517,8 @@ class Client(object):
|
|||
: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 False
|
||||
|
||||
|
|
|
@ -152,4 +152,4 @@ def get_localhost_auth():
|
|||
|
||||
if username == "localclient":
|
||||
return (username, password)
|
||||
return None
|
||||
return ("", "")
|
||||
|
|
|
@ -85,10 +85,6 @@ class ConnectionManager(component.Component):
|
|||
component.Component.__init__(self, "ConnectionManager")
|
||||
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)
|
||||
|
||||
# Component overrides
|
||||
|
|
|
@ -243,11 +243,16 @@ class GtkUI:
|
|||
|
||||
def _on_reactor_start(self):
|
||||
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"]:
|
||||
# XXX: We need to call a simulate() here, but this could be a bug in twisted
|
||||
reactor.simulate()
|
||||
self.connectionmanager.show()
|
||||
|
||||
if self.config["classic_mode"]:
|
||||
client.start_classic_mode()
|
||||
self._on_new_core()
|
||||
return
|
||||
|
||||
def _on_new_core(self):
|
||||
component.start()
|
||||
|
||||
|
|
|
@ -174,15 +174,13 @@ class Preferences(component.Component):
|
|||
|
||||
# Update the preferences dialog to reflect current config settings
|
||||
self.core_config = {}
|
||||
try:
|
||||
if client.connected():
|
||||
client.core.get_config().addCallback(self._on_get_config)
|
||||
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_listen_port().addCallback(self._on_get_listen_port)
|
||||
# Force these calls and block until we've done them all
|
||||
client.force_call()
|
||||
except deluge.error.NoCoreError:
|
||||
log.debug("Not connected to a daemon..")
|
||||
|
||||
if self.core_config != {} and self.core_config != None:
|
||||
core_widgets = {
|
||||
|
|
Loading…
Reference in New Issue