Rename classic to standalone

This commit is contained in:
Calum Lind 2016-10-28 10:27:53 +01:00
commit a438f13647
15 changed files with 75 additions and 70 deletions

View file

@ -64,19 +64,19 @@ def is_daemon_running(pid_file):
class Daemon(object): class Daemon(object):
"""The Deluge Daemon class""" """The Deluge Daemon class"""
def __init__(self, listen_interface=None, interface=None, port=None, classic=False, def __init__(self, listen_interface=None, interface=None, port=None, standalone=False,
read_only_config_keys=None): read_only_config_keys=None):
""" """
Args: Args:
listen_interface (str, optional): The IP address to listen to bittorrent connections on. listen_interface (str, optional): The IP address to listen to bittorrent connections on.
interface (str, optional): The IP address the daemon will listen for UI connections on. interface (str, optional): The IP address the daemon will listen for UI connections on.
port (int, optional): The port the daemon will listen for UI connections on. port (int, optional): The port the daemon will listen for UI connections on.
classic (bool, optional): If True the client is in Classic (Standalone) mode otherwise, if standalone (bool, optional): If True the client is in Standalone mode otherwise, if
False, start the daemon as separate process. False, start the daemon as separate process.
read_only_config_keys (list of str, optional): A list of config keys that will not be read_only_config_keys (list of str, optional): A list of config keys that will not be
altered by core.set_config() RPC method. altered by core.set_config() RPC method.
""" """
self.classic = classic self.standalone = standalone
self.pid_file = get_config_dir("deluged.pid") self.pid_file = get_config_dir("deluged.pid")
log.info("Deluge daemon %s", get_version()) log.info("Deluge daemon %s", get_version())
if is_daemon_running(self.pid_file): if is_daemon_running(self.pid_file):
@ -110,7 +110,7 @@ class Daemon(object):
self.rpcserver = RPCServer( self.rpcserver = RPCServer(
port=port, port=port,
allow_remote=self.core.config["allow_remote"], allow_remote=self.core.config["allow_remote"],
listen=not classic, listen=not standalone,
interface=interface interface=interface
) )
@ -124,7 +124,7 @@ class Daemon(object):
# Make sure we start the PreferencesManager first # Make sure we start the PreferencesManager first
component.start("PreferencesManager") component.start("PreferencesManager")
if not self.classic: if not self.standalone:
log.info("Deluge daemon starting...") log.info("Deluge daemon starting...")
# Create pid file to track if deluged is running, also includes the port number. # Create pid file to track if deluged is running, also includes the port number.
pid = os.getpid() pid = os.getpid()
@ -148,7 +148,7 @@ class Daemon(object):
def _shutdown(self, *args, **kwargs): def _shutdown(self, *args, **kwargs):
log.info("Deluge daemon shutting down, waiting for components to shutdown...") log.info("Deluge daemon shutting down, waiting for components to shutdown...")
if not self.classic: if not self.standalone:
return component.shutdown() return component.shutdown()
@export() @export()

View file

@ -31,12 +31,12 @@ class StatsTestCase(BaseTestCase):
def set_up(self): def set_up(self):
defer.setDebugging(True) defer.setDebugging(True)
tests_common.set_tmp_config_dir() tests_common.set_tmp_config_dir()
client.start_classic_mode() client.start_standalone()
client.core.enable_plugin("Stats") client.core.enable_plugin("Stats")
return component.start() return component.start()
def tear_down(self): def tear_down(self):
client.stop_classic_mode() client.stop_standalone()
return component.shutdown() return component.shutdown()
@defer.inlineCallbacks @defer.inlineCallbacks

View file

@ -424,18 +424,18 @@ class DaemonSSLProxy(DaemonProxy):
return self.protocol.get_bytes_sent() return self.protocol.get_bytes_sent()
class DaemonClassicProxy(DaemonProxy): class DaemonStandaloneProxy(DaemonProxy):
def __init__(self, event_handlers=None): def __init__(self, event_handlers=None):
if event_handlers is None: if event_handlers is None:
event_handlers = {} event_handlers = {}
from deluge.core import daemon from deluge.core import daemon
self.__daemon = daemon.Daemon(classic=True) self.__daemon = daemon.Daemon(standalone=True)
self.__daemon.start() self.__daemon.start()
log.debug("daemon created!") log.debug("daemon created!")
self.connected = True self.connected = True
self.host = "localhost" self.host = "localhost"
self.port = 58846 self.port = 58846
# Running in classic mode, it's safe to import auth level # Running in standalone mode, it's safe to import auth level
from deluge.core.authmanager import (AUTH_LEVEL_ADMIN, from deluge.core.authmanager import (AUTH_LEVEL_ADMIN,
AUTH_LEVELS_MAPPING, AUTH_LEVELS_MAPPING,
AUTH_LEVELS_MAPPING_REVERSE) AUTH_LEVELS_MAPPING_REVERSE)
@ -528,7 +528,7 @@ class Client(object):
def __init__(self): def __init__(self):
self._daemon_proxy = None self._daemon_proxy = None
self.disconnect_callback = None self.disconnect_callback = None
self.__started_in_classic = False self.__started_standalone = False
def connect(self, host="127.0.0.1", port=58846, username="", password="", def connect(self, host="127.0.0.1", port=58846, username="", password="",
skip_authentication=False): skip_authentication=False):
@ -586,27 +586,35 @@ class Client(object):
""" """
Disconnects from the daemon. Disconnects from the daemon.
""" """
if self.is_classicmode(): if self.is_standalone():
self._daemon_proxy.disconnect() self._daemon_proxy.disconnect()
self.stop_classic_mode() self.stop_standalone()
return defer.succeed(True) return defer.succeed(True)
if self._daemon_proxy: if self._daemon_proxy:
return self._daemon_proxy.disconnect() return self._daemon_proxy.disconnect()
def start_classic_mode(self): def start_standalone(self):
""" """
Starts a daemon in the same process as the client. Starts a daemon in the same process as the client.
""" """
self._daemon_proxy = DaemonClassicProxy(self.__event_handlers) self._daemon_proxy = DaemonStandaloneProxy(self.__event_handlers)
self.__started_in_classic = True self.__started_standalone = True
def stop_classic_mode(self): def stop_standalone(self):
""" """
Stops the daemon process in the client. Stops the daemon process in the client.
""" """
self._daemon_proxy = None self._daemon_proxy = None
self.__started_in_classic = False self.__started_standalone = False
def start_classic_mode(self):
"""Deprecated"""
self.start_standalone()
def stop_classic_mode(self):
"""Deprecated"""
self.stop_standalone()
def start_daemon(self, port, config): def start_daemon(self, port, config):
""" """
@ -649,18 +657,22 @@ that you forgot to install the deluged package or it's not in your PATH."))
""" """
if (self._daemon_proxy and self._daemon_proxy.host in ("127.0.0.1", "localhost") or if (self._daemon_proxy and self._daemon_proxy.host in ("127.0.0.1", "localhost") or
isinstance(self._daemon_proxy, DaemonClassicProxy)): isinstance(self._daemon_proxy, DaemonStandaloneProxy)):
return True return True
return False return False
def is_standalone(self):
"""
Checks to see if the client has been started in standalone mode.
:returns: bool, True if in standalone mode
"""
return self.__started_standalone
def is_classicmode(self): def is_classicmode(self):
""" """Deprecated"""
Checks to see if the client has been started in classic mode. self.is_standalone()
:returns: bool, True if in classic mode
"""
return self.__started_in_classic
def connected(self): def connected(self):
""" """

View file

@ -254,7 +254,7 @@ class AboutDialog(object):
self.about.set_logo(gtk.gdk.pixbuf_new_from_file(get_pixmap("deluge-about.png"))) self.about.set_logo(gtk.gdk.pixbuf_new_from_file(get_pixmap("deluge-about.png")))
if client.connected(): if client.connected():
if not client.is_classicmode(): if not client.is_standalone():
self.about.set_comments( self.about.set_comments(
self.about.get_comments() + _("Server:") + " %coreversion%\n") self.about.get_comments() + _("Server:") + " %coreversion%\n")
@ -272,7 +272,7 @@ class AboutDialog(object):
self.about.set_comments(c) self.about.set_comments(c)
client.core.get_libtorrent_version().addCallback(on_lt_version) client.core.get_libtorrent_version().addCallback(on_lt_version)
if not client.is_classicmode(): if not client.is_standalone():
client.daemon.info().addCallback(on_info) client.daemon.info().addCallback(on_info)
else: else:
client.core.get_libtorrent_version().addCallback(on_lt_version) client.core.get_libtorrent_version().addCallback(on_lt_version)

View file

@ -374,7 +374,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkRadioButton" id="radio_classic"> <object class="GtkRadioButton" id="radio_standalone">
<property name="label" translatable="yes">Standalone</property> <property name="label" translatable="yes">Standalone</property>
<property name="use_action_appearance">False</property> <property name="use_action_appearance">False</property>
<property name="visible">True</property> <property name="visible">True</property>
@ -399,7 +399,7 @@
<property name="receives_default">False</property> <property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Connect to a Deluge daemon (deluged)</property> <property name="tooltip_text" translatable="yes">Connect to a Deluge daemon (deluged)</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
<property name="group">radio_classic</property> <property name="group">radio_standalone</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>

View file

@ -71,7 +71,7 @@ except ImportError:
DEFAULT_PREFS = { DEFAULT_PREFS = {
"classic_mode": True, "standalone": True,
"interactive_add": True, "interactive_add": True,
"focus_add_dialog": True, "focus_add_dialog": True,
"enable_system_tray": True, "enable_system_tray": True,
@ -167,10 +167,6 @@ class GtkUI(object):
if not os.path.exists(os.path.join(get_config_dir(), "gtkui_state")): if not os.path.exists(os.path.join(get_config_dir(), "gtkui_state")):
os.makedirs(os.path.join(get_config_dir(), "gtkui_state")) os.makedirs(os.path.join(get_config_dir(), "gtkui_state"))
# We need to check on exit if it was started in classic mode to ensure we
# shutdown the daemon.
self.started_in_classic = self.config["classic_mode"]
# Set language # Set language
if self.config["language"] is not None: if self.config["language"] is not None:
lang.set_language(self.config["language"]) lang.set_language(self.config["language"])
@ -246,7 +242,7 @@ class GtkUI(object):
def shutdown(self, *args, **kwargs): def shutdown(self, *args, **kwargs):
log.debug("GTKUI shutting down...") log.debug("GTKUI shutting down...")
# Shutdown all components # Shutdown all components
if self.started_in_classic: if client.is_standalone:
return component.shutdown() return component.shutdown()
@defer.inlineCallbacks @defer.inlineCallbacks
@ -287,19 +283,19 @@ class GtkUI(object):
log.debug("_on_reactor_start") log.debug("_on_reactor_start")
self.mainwindow.first_show() self.mainwindow.first_show()
if self.config["classic_mode"]: if self.config["standalone"]:
def on_dialog_response(response): def on_dialog_response(response):
if response != gtk.RESPONSE_YES: if response != gtk.RESPONSE_YES:
# The user does not want to turn Standalone Mode off, so just quit # The user does not want to turn Standalone Mode off, so just quit
self.mainwindow.quit() self.mainwindow.quit()
return return
# Turning off classic_mode # Turning off standalone
self.config["classic_mode"] = False self.config["standalone"] = False
self.__start_non_classic() self.__start_thinclient()
try: try:
try: try:
client.start_classic_mode() client.start_standalone()
except DaemonRunningError: except DaemonRunningError:
d = YesNoDialog( d = YesNoDialog(
_("Switch to Thin Client Mode?"), _("Switch to Thin Client Mode?"),
@ -307,7 +303,6 @@ class GtkUI(object):
"To use Standalone mode, stop this daemon and restart Deluge." "To use Standalone mode, stop this daemon and restart Deluge."
"\n\n" "\n\n"
"Continue in Thin Client mode?")).run() "Continue in Thin Client mode?")).run()
self.started_in_classic = False
d.addCallback(on_dialog_response) d.addCallback(on_dialog_response)
except ImportError as ex: except ImportError as ex:
if "No module named libtorrent" in ex.message: if "No module named libtorrent" in ex.message:
@ -316,7 +311,6 @@ class GtkUI(object):
_("Only Thin Client mode is available because libtorrent is not installed." _("Only Thin Client mode is available because libtorrent is not installed."
"\n\n" "\n\n"
"To use Deluge Standalone mode, please install libtorrent.")).run() "To use Deluge Standalone mode, please install libtorrent.")).run()
self.started_in_classic = False
d.addCallback(on_dialog_response) d.addCallback(on_dialog_response)
else: else:
raise ex raise ex
@ -337,14 +331,13 @@ class GtkUI(object):
_("Switch to Thin Client Mode?"), _("Switch to Thin Client Mode?"),
_("Unable to start Standalone mode would you like to continue in Thin Client mode?") _("Unable to start Standalone mode would you like to continue in Thin Client mode?")
).run() ).run()
self.started_in_classic = False
d.addCallback(on_dialog_response) d.addCallback(on_dialog_response)
ed.addCallback(on_ed_response) ed.addCallback(on_ed_response)
else: else:
self.rpc_stats.start(10) self.rpc_stats.start(10)
self.__start_non_classic() self.__start_thinclient()
def __start_non_classic(self): def __start_thinclient(self):
# Autoconnect to a host # Autoconnect to a host
if self.config["autoconnect"]: if self.config["autoconnect"]:

View file

@ -216,7 +216,7 @@ class MainWindow(component.Component):
if shutdown: if shutdown:
client.daemon.shutdown().addCallback(stop_gtk_reactor) client.daemon.shutdown().addCallback(stop_gtk_reactor)
elif not client.is_classicmode() and client.connected(): elif not client.is_standalone() and client.connected():
client.disconnect().addCallback(stop_gtk_reactor) client.disconnect().addCallback(stop_gtk_reactor)
else: else:
stop_gtk_reactor() stop_gtk_reactor()

View file

@ -176,9 +176,9 @@ class MenuBar(component.Component):
self.builder.get_object(widget).hide() self.builder.get_object(widget).hide()
self.builder.get_object(widget).set_no_show_all(True) self.builder.get_object(widget).set_no_show_all(True)
self.main_builder.get_object("separatormenuitem").set_visible(not self.config["classic_mode"]) self.main_builder.get_object("separatormenuitem").set_visible(not self.config["standalone"])
self.main_builder.get_object("menuitem_quitdaemon").set_visible(not self.config["classic_mode"]) self.main_builder.get_object("menuitem_quitdaemon").set_visible(not self.config["standalone"])
self.main_builder.get_object("menuitem_connectionmanager").set_visible(not self.config["classic_mode"]) self.main_builder.get_object("menuitem_connectionmanager").set_visible(not self.config["standalone"])
# Show the Torrent menu because we're connected to a host # Show the Torrent menu because we're connected to a host
self.menu_torrent.show() self.menu_torrent.show()

View file

@ -68,7 +68,7 @@ def menubar_osx(gtkui, osxapp):
osxapp.insert_app_menu_item(about_item, 0) osxapp.insert_app_menu_item(about_item, 0)
osxapp.insert_app_menu_item(gtk.SeparatorMenuItem(), 1) osxapp.insert_app_menu_item(gtk.SeparatorMenuItem(), 1)
osxapp.insert_app_menu_item(pref_item, 2) osxapp.insert_app_menu_item(pref_item, 2)
if not config["classic_mode"]: if not config["standalone"]:
osxapp.insert_app_menu_item(conn_item, 3) osxapp.insert_app_menu_item(conn_item, 3)
if quit_all_item.get_visible(): if quit_all_item.get_visible():
osxapp.insert_app_menu_item(gtk.SeparatorMenuItem(), 4) osxapp.insert_app_menu_item(gtk.SeparatorMenuItem(), 4)

View file

@ -43,7 +43,7 @@ class NewReleaseDialog(object):
builder.get_object("label_server_version").show() builder.get_object("label_server_version").show()
builder.get_object("label_server_version_text").show() builder.get_object("label_server_version_text").show()
if not client.is_classicmode(): if not client.is_standalone():
builder.get_object("label_client_version_text").set_label(_("<i>Client Version</i>")) builder.get_object("label_client_version_text").set_label(_("<i>Client Version</i>"))
client.daemon.info().addCallback(on_info) client.daemon.info().addCallback(on_info)

View file

@ -449,8 +449,8 @@ class Preferences(component.Component):
self.builder.get_object("chk_start_in_tray").set_active(self.gtkui_config["start_in_tray"]) self.builder.get_object("chk_start_in_tray").set_active(self.gtkui_config["start_in_tray"])
self.builder.get_object("radio_appind").set_active(self.gtkui_config["enable_appindicator"]) self.builder.get_object("radio_appind").set_active(self.gtkui_config["enable_appindicator"])
self.builder.get_object("chk_lock_tray").set_active(self.gtkui_config["lock_tray"]) self.builder.get_object("chk_lock_tray").set_active(self.gtkui_config["lock_tray"])
self.builder.get_object("radio_classic").set_active(self.gtkui_config["classic_mode"]) self.builder.get_object("radio_standalone").set_active(self.gtkui_config["standalone"])
self.builder.get_object("radio_thinclient").set_active(not self.gtkui_config["classic_mode"]) self.builder.get_object("radio_thinclient").set_active(not self.gtkui_config["standalone"])
self.builder.get_object("chk_show_rate_in_title").set_active(self.gtkui_config["show_rate_in_title"]) self.builder.get_object("chk_show_rate_in_title").set_active(self.gtkui_config["show_rate_in_title"])
self.builder.get_object("chk_focus_main_window_on_add").set_active( self.builder.get_object("chk_focus_main_window_on_add").set_active(
self.gtkui_config["focus_main_window_on_add"]) self.gtkui_config["focus_main_window_on_add"])
@ -492,7 +492,6 @@ class Preferences(component.Component):
:param hide: bool, if True, will not re-show the dialog and will hide it instead :param hide: bool, if True, will not re-show the dialog and will hide it instead
""" """
classic_mode_was_set = self.gtkui_config["classic_mode"]
# Get the values from the dialog # Get the values from the dialog
new_core_config = {} new_core_config = {}
@ -583,8 +582,9 @@ class Preferences(component.Component):
if passhex != "c07eb5a8c0dc7bb81c217b67f11c3b7a5e95ffd7": if passhex != "c07eb5a8c0dc7bb81c217b67f11c3b7a5e95ffd7":
new_gtkui_config["tray_password"] = passhex new_gtkui_config["tray_password"] = passhex
new_gtkui_in_classic_mode = self.builder.get_object("radio_classic").get_active() was_standalone = self.gtkui_config["standalone"]
new_gtkui_config["classic_mode"] = new_gtkui_in_classic_mode new_gtkui_standalone = self.builder.get_object("radio_standalone").get_active()
new_gtkui_config["standalone"] = new_gtkui_standalone
new_gtkui_config["show_rate_in_title"] = self.builder.get_object( new_gtkui_config["show_rate_in_title"] = self.builder.get_object(
"chk_show_rate_in_title").get_active() "chk_show_rate_in_title").get_active()
@ -698,19 +698,19 @@ class Preferences(component.Component):
# Re-show the dialog to make sure everything has been updated # Re-show the dialog to make sure everything has been updated
self.show() self.show()
if classic_mode_was_set != new_gtkui_in_classic_mode: if was_standalone != new_gtkui_standalone:
def on_response(response): def on_response(response):
if response == gtk.RESPONSE_YES: if response == gtk.RESPONSE_YES:
shutdown_daemon = (not client.is_classicmode() and shutdown_daemon = (not client.is_standalone() and
client.connected() and client.connected() and
client.is_localhost()) client.is_localhost())
component.get("MainWindow").quit(shutdown=shutdown_daemon) component.get("MainWindow").quit(shutdown=shutdown_daemon)
else: else:
self.gtkui_config["classic_mode"] = not new_gtkui_in_classic_mode self.gtkui_config["standalone"] = not new_gtkui_standalone
self.builder.get_object("radio_classic").set_active( self.builder.get_object("radio_standalone").set_active(
self.gtkui_config["classic_mode"]) self.gtkui_config["standalone"])
self.builder.get_object("radio_thinclient").set_active( self.builder.get_object("radio_thinclient").set_active(
not self.gtkui_config["classic_mode"]) not self.gtkui_config["standalone"])
dialog = YesNoDialog( dialog = YesNoDialog(
_("Switching client mode..."), _("Switching client mode..."),
_("Your current session will be stopped. Do you wish to continue?") _("Your current session will be stopped. Do you wish to continue?")

View file

@ -66,7 +66,7 @@ class QueuedTorrents(component.Component):
# We only want the add button sensitive if we're connected to a host # We only want the add button sensitive if we're connected to a host
self.builder.get_object("button_add").set_sensitive(True) self.builder.get_object("button_add").set_sensitive(True)
if self.config["autoadd_queued"] or self.config["classic_mode"]: if self.config["autoadd_queued"] or self.config["standalone"]:
self.on_button_add_clicked(None) self.on_button_add_clicked(None)
else: else:
self.run() self.run()

View file

@ -128,7 +128,7 @@ class SystemTray(component.Component):
def __start(self): def __start(self):
if self.config["enable_system_tray"]: if self.config["enable_system_tray"]:
if self.config["classic_mode"]: if self.config["standalone"]:
try: try:
self.hide_widget_list.remove("menuitem_quitdaemon") self.hide_widget_list.remove("menuitem_quitdaemon")
self.hide_widget_list.remove("separatormenuitem4") self.hide_widget_list.remove("separatormenuitem4")

View file

@ -55,7 +55,7 @@ class ToolBar(component.Component):
def start(self): def start(self):
self.window.get_builder().get_object("toolbutton_connectionmanager").set_visible( self.window.get_builder().get_object("toolbutton_connectionmanager").set_visible(
not self.config["classic_mode"]) not self.config["standalone"])
for widget in self.change_sensitivity: for widget in self.change_sensitivity:
self.window.get_builder().get_object(widget).set_sensitive(True) self.window.get_builder().get_object(widget).set_sensitive(True)

View file

@ -90,7 +90,7 @@ class JSON(resource.Resource, component.Component):
component.Component.__init__(self, "JSON") component.Component.__init__(self, "JSON")
self._remote_methods = [] self._remote_methods = []
self._local_methods = {} self._local_methods = {}
if client.is_classicmode(): if client.is_standalone():
self.get_remote_methods() self.get_remote_methods()
def get_remote_methods(self, result=None): def get_remote_methods(self, result=None):
@ -378,7 +378,7 @@ class WebApi(JSONComponent):
client.deregister_event_handler("PluginEnabledEvent", self._json.get_remote_methods) client.deregister_event_handler("PluginEnabledEvent", self._json.get_remote_methods)
client.deregister_event_handler("PluginDisabledEvent", self._json.get_remote_methods) client.deregister_event_handler("PluginDisabledEvent", self._json.get_remote_methods)
if client.is_classicmode(): if client.is_standalone():
component.get("Web.PluginManager").stop() component.get("Web.PluginManager").stop()
else: else:
client.disconnect() client.disconnect()
@ -388,7 +388,7 @@ class WebApi(JSONComponent):
client.register_event_handler("PluginEnabledEvent", self._json.get_remote_methods) client.register_event_handler("PluginEnabledEvent", self._json.get_remote_methods)
client.register_event_handler("PluginDisabledEvent", self._json.get_remote_methods) client.register_event_handler("PluginDisabledEvent", self._json.get_remote_methods)
if client.is_classicmode(): if client.is_standalone():
component.get("Web.PluginManager").start() component.get("Web.PluginManager").start()
else: else:
client.set_disconnect_callback(self._on_client_disconnect) client.set_disconnect_callback(self._on_client_disconnect)