From 2e2851dc13d73352530dd4495c7e05603b2e520d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 23:38:38 +0200 Subject: Adding upstream version 2.1.2~dev0+20240219. Signed-off-by: Daniel Baumann --- deluge/plugins/WebUi/create_dev_link.sh | 11 ++ deluge/plugins/WebUi/deluge_webui/__init__.py | 37 ++++++ deluge/plugins/WebUi/deluge_webui/common.py | 20 ++++ deluge/plugins/WebUi/deluge_webui/core.py | 117 +++++++++++++++++++ deluge/plugins/WebUi/deluge_webui/data/config.ui | 127 +++++++++++++++++++++ deluge/plugins/WebUi/deluge_webui/gtkui.py | 97 ++++++++++++++++ .../plugins/WebUi/deluge_webui/tests/__init__.py | 0 .../WebUi/deluge_webui/tests/test_plugin_webui.py | 44 +++++++ deluge/plugins/WebUi/setup.py | 43 +++++++ 9 files changed, 496 insertions(+) create mode 100755 deluge/plugins/WebUi/create_dev_link.sh create mode 100644 deluge/plugins/WebUi/deluge_webui/__init__.py create mode 100644 deluge/plugins/WebUi/deluge_webui/common.py create mode 100644 deluge/plugins/WebUi/deluge_webui/core.py create mode 100644 deluge/plugins/WebUi/deluge_webui/data/config.ui create mode 100644 deluge/plugins/WebUi/deluge_webui/gtkui.py create mode 100644 deluge/plugins/WebUi/deluge_webui/tests/__init__.py create mode 100644 deluge/plugins/WebUi/deluge_webui/tests/test_plugin_webui.py create mode 100644 deluge/plugins/WebUi/setup.py (limited to 'deluge/plugins/WebUi') diff --git a/deluge/plugins/WebUi/create_dev_link.sh b/deluge/plugins/WebUi/create_dev_link.sh new file mode 100755 index 0000000..f4d60d2 --- /dev/null +++ b/deluge/plugins/WebUi/create_dev_link.sh @@ -0,0 +1,11 @@ +#!/bin/bash +BASEDIR=$(cd `dirname $0` && pwd) +CONFIG_DIR=$( test -z $1 && echo "/home/damien/.config/deluge/" || echo "$1") +[ -d "$CONFIG_DIR/plugins" ] || echo "Config dir "$CONFIG_DIR" is either not a directory or is not a proper deluge config directory. Exiting" +[ -d "$CONFIG_DIR/plugins" ] || exit 1 +cd $BASEDIR +test -d $BASEDIR/temp || mkdir $BASEDIR/temp +export PYTHONPATH=$BASEDIR/temp +python setup.py build develop --install-dir $BASEDIR/temp +cp $BASEDIR/temp/*.egg-link $CONFIG_DIR/plugins +rm -fr $BASEDIR/temp diff --git a/deluge/plugins/WebUi/deluge_webui/__init__.py b/deluge/plugins/WebUi/deluge_webui/__init__.py new file mode 100644 index 0000000..ba978b2 --- /dev/null +++ b/deluge/plugins/WebUi/deluge_webui/__init__.py @@ -0,0 +1,37 @@ +# +# Copyright (C) 2009 Damien Churchill +# +# Basic plugin template created by: +# Copyright (C) 2008 Martijn Voncken +# Copyright (C) 2007-2009 Andrew Resch +# +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. +# + +from deluge.plugins.init import PluginInitBase + + +class CorePlugin(PluginInitBase): + def __init__(self, plugin_name): + from .core import Core as _pluginCls + + self._plugin_cls = _pluginCls + super().__init__(plugin_name) + + +class GtkUIPlugin(PluginInitBase): + def __init__(self, plugin_name): + from .gtkui import GtkUI as _pluginCls + + self._plugin_cls = _pluginCls + super().__init__(plugin_name) + + +class WebUIPlugin(PluginInitBase): + def __init__(self, plugin_name): + from webui import WebUI as _pluginCls + + self._plugin_cls = _pluginCls + super().__init__(plugin_name) diff --git a/deluge/plugins/WebUi/deluge_webui/common.py b/deluge/plugins/WebUi/deluge_webui/common.py new file mode 100644 index 0000000..eb47f13 --- /dev/null +++ b/deluge/plugins/WebUi/deluge_webui/common.py @@ -0,0 +1,20 @@ +# +# Basic plugin template created by: +# Copyright (C) 2008 Martijn Voncken +# 2007-2009 Andrew Resch +# 2009 Damien Churchill +# 2010 Pedro Algarvio +# 2017 Calum Lind +# +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. +# + +import os.path + +from pkg_resources import resource_filename + + +def get_resource(filename): + return resource_filename(__package__, os.path.join('data', filename)) diff --git a/deluge/plugins/WebUi/deluge_webui/core.py b/deluge/plugins/WebUi/deluge_webui/core.py new file mode 100644 index 0000000..f18203e --- /dev/null +++ b/deluge/plugins/WebUi/deluge_webui/core.py @@ -0,0 +1,117 @@ +# +# Copyright (C) 2009 Damien Churchill +# +# Basic plugin template created by: +# Copyright (C) 2008 Martijn Voncken +# Copyright (C) 2007-2009 Andrew Resch +# +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. +# + +import logging + +from twisted.internet import defer +from twisted.internet.error import CannotListenError + +import deluge.component as component +from deluge import configmanager +from deluge.core.rpcserver import export +from deluge.plugins.pluginbase import CorePluginBase + +try: + from deluge.ui.web import server +except ImportError: + server = False + +log = logging.getLogger(__name__) + +DEFAULT_PREFS = {'enabled': False, 'ssl': False, 'port': 8112} + + +class Core(CorePluginBase): + server = None + + def enable(self): + self.config = configmanager.ConfigManager('web_plugin.conf', DEFAULT_PREFS) + if self.config['enabled']: + self.start_server() + + def disable(self): + self.stop_server() + + def update(self): + pass + + def _on_stop(self, *args): + return self.start_server() + + @export + def got_deluge_web(self): + """Status of deluge-web module installation. + + Check if deluge.ui.web.server modulge is installed and has been successfully imported. + + Returns: + bool: True is deluge-web is installed and available, otherwise False. + + """ + + return bool(server) + + def start_server(self): + if not self.server: + if not self.got_deluge_web(): + return False + + try: + self.server = component.get('DelugeWeb') + except KeyError: + self.server = server.DelugeWeb(daemon=False) + + self.server.port = self.config['port'] + self.server.https = self.config['ssl'] + try: + self.server.start() + except CannotListenError as ex: + log.warning('Failed to start WebUI server: %s', ex) + raise + return True + + def stop_server(self): + if self.server: + return self.server.stop() + return defer.succeed(True) + + def restart_server(self): + return self.stop_server().addCallback(self._on_stop) + + @export + def set_config(self, config): + """Sets the config dictionary.""" + + action = None + if 'enabled' in config: + if config['enabled'] != self.config['enabled']: + action = config['enabled'] and 'start' or 'stop' + + if 'ssl' in config: + if not action: + action = 'restart' + + for key in config: + self.config[key] = config[key] + self.config.save() + + if action == 'start': + return self.start_server() + elif action == 'stop': + return self.stop_server() + elif action == 'restart': + return self.restart_server() + + @export + def get_config(self): + """Returns the config dictionary.""" + return self.config.config diff --git a/deluge/plugins/WebUi/deluge_webui/data/config.ui b/deluge/plugins/WebUi/deluge_webui/data/config.ui new file mode 100644 index 0000000..c58edd0 --- /dev/null +++ b/deluge/plugins/WebUi/deluge_webui/data/config.ui @@ -0,0 +1,127 @@ + + + + + + 99999 + 8112 + 1 + 10 + + + False + + + + + + True + False + vertical + + + True + False + 0 + none + + + True + False + 10 + 12 + + + True + False + 5 + vertical + + + Enable web interface + True + True + False + True + + + False + False + 0 + + + + + Enable SSL + True + True + False + True + + + False + False + 1 + + + + + True + False + 5 + + + True + False + Listening port: + + + False + False + 0 + + + + + True + True + + adjustment1 + True + + + True + True + 1 + + + + + False + False + 2 + + + + + + + + + True + False + <b>Settings</b> + True + + + + + True + True + 0 + + + + + + diff --git a/deluge/plugins/WebUi/deluge_webui/gtkui.py b/deluge/plugins/WebUi/deluge_webui/gtkui.py new file mode 100644 index 0000000..3d19417 --- /dev/null +++ b/deluge/plugins/WebUi/deluge_webui/gtkui.py @@ -0,0 +1,97 @@ +# +# Copyright (C) 2009 Damien Churchill +# +# Basic plugin template created by: +# Copyright (C) 2008 Martijn Voncken +# Copyright (C) 2007-2009 Andrew Resch +# +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. +# + +import logging + +from gi.repository import Gtk + +import deluge.component as component +from deluge.plugins.pluginbase import Gtk3PluginBase +from deluge.ui.client import client + +from .common import get_resource + +log = logging.getLogger(__name__) + + +class GtkUI(Gtk3PluginBase): + def enable(self): + self.builder = Gtk.Builder() + self.builder.add_from_file(get_resource('config.ui')) + + component.get('Preferences').add_page( + _('WebUi'), self.builder.get_object('prefs_box') + ) + component.get('PluginManager').register_hook( + 'on_apply_prefs', self.on_apply_prefs + ) + component.get('PluginManager').register_hook( + 'on_show_prefs', self.on_show_prefs + ) + client.webui.get_config().addCallback(self.cb_get_config) + client.webui.got_deluge_web().addCallback(self.cb_chk_deluge_web) + + def disable(self): + component.get('Preferences').remove_page(_('WebUi')) + component.get('PluginManager').deregister_hook( + 'on_apply_prefs', self.on_apply_prefs + ) + component.get('PluginManager').deregister_hook( + 'on_show_prefs', self.on_show_prefs + ) + + def on_apply_prefs(self): + if not self.have_web: + return + log.debug('applying prefs for WebUi') + config = { + 'enabled': self.builder.get_object('enabled_checkbutton').get_active(), + 'ssl': self.builder.get_object('ssl_checkbutton').get_active(), + 'port': self.builder.get_object('port_spinbutton').get_value_as_int(), + } + client.webui.set_config(config) + + def on_show_prefs(self): + client.webui.get_config().addCallback(self.cb_get_config) + + def cb_get_config(self, config): + """Callback for on show_prefs.""" + self.builder.get_object('enabled_checkbutton').set_active(config['enabled']) + self.builder.get_object('ssl_checkbutton').set_active(config['ssl']) + self.builder.get_object('port_spinbutton').set_value(config['port']) + + def cb_chk_deluge_web(self, have_web): + self.have_web = have_web + if have_web: + return + self.builder.get_object('settings_vbox').set_sensitive(False) + + vbox = self.builder.get_object('prefs_box') + + hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, spacing=0) + icon = Gtk.Image.new_from_icon_name('dialog-error', Gtk.IconSize.BUTTON) + icon.set_padding(5, 5) + hbox.pack_start(icon, False, False, 0) + + label = Gtk.Label( + _( + 'The Deluge web interface is not installed, ' + 'please install the\ninterface and try again' + ) + ) + label.set_alignment(0, 0.5) + label.set_padding(5, 5) + hbox.pack_start(label, False, False, 0) + + vbox.pack_start(hbox, False, False, 10) + vbox.reorder_child(hbox, 0) + vbox.show_all() diff --git a/deluge/plugins/WebUi/deluge_webui/tests/__init__.py b/deluge/plugins/WebUi/deluge_webui/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/deluge/plugins/WebUi/deluge_webui/tests/test_plugin_webui.py b/deluge/plugins/WebUi/deluge_webui/tests/test_plugin_webui.py new file mode 100644 index 0000000..413d259 --- /dev/null +++ b/deluge/plugins/WebUi/deluge_webui/tests/test_plugin_webui.py @@ -0,0 +1,44 @@ +# +# Copyright (C) 2016 bendikro +# +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. +# +import pytest +import pytest_twisted + +from deluge.core.core import Core +from deluge.core.rpcserver import RPCServer +from deluge.tests import common + +common.disable_new_release_check() + + +class TestWebUIPlugin: + @pytest_twisted.async_yield_fixture(autouse=True) + async def set_up(self, request, component): + self = request.instance + self.rpcserver = RPCServer(listen=False) + self.core = Core() + await component.start() + + yield + + await component.shutdown() + del self.rpcserver + del self.core + + def test_enable_webui(self): + if 'WebUi' not in self.core.get_available_plugins(): + pytest.skip('WebUi plugin not available for testing') + + d = self.core.enable_plugin('WebUi') + + def result_cb(result): + if 'WebUi' not in self.core.get_enabled_plugins(): + self.fail('Failed to enable WebUi plugin') + assert result + + d.addBoth(result_cb) + return d diff --git a/deluge/plugins/WebUi/setup.py b/deluge/plugins/WebUi/setup.py new file mode 100644 index 0000000..5f2184c --- /dev/null +++ b/deluge/plugins/WebUi/setup.py @@ -0,0 +1,43 @@ +# +# Copyright (C) 2009 Damien Churchill +# +# Basic plugin template created by: +# Copyright (C) 2008 Martijn Voncken +# Copyright (C) 2007-2009 Andrew Resch +# +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. +# + +from setuptools import find_packages, setup + +__plugin_name__ = 'WebUi' +__author__ = 'Damien Churchill' +__author_email__ = 'damoxc@gmail.com' +__version__ = '0.2' +__url__ = 'http://deluge-torrent.org' +__license__ = 'GPLv3' +__description__ = 'Allows starting the web interface within the daemon.' +__long_description__ = """""" +__pkg_data__ = {'deluge_' + __plugin_name__.lower(): ['data/*']} + +setup( + name=__plugin_name__, + version=__version__, + description=__description__, + author=__author__, + author_email=__author_email__, + url=__url__, + license=__license__, + long_description=__long_description__ if __long_description__ else __description__, + packages=find_packages(), + package_data=__pkg_data__, + entry_points=""" + [deluge.plugin.core] + %s = deluge_%s:CorePlugin + [deluge.plugin.gtk3ui] + %s = deluge_%s:GtkUIPlugin + """ + % ((__plugin_name__, __plugin_name__.lower()) * 2), +) -- cgit v1.2.3