From 7cf47bbcb2c5909a2a9f2f25140f6184a5a2d2b5 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 12 Jul 2015 11:51:09 +0530 Subject: [PATCH] deluge: Remove get-enabled from actions - Use webserver action utilites. - Move status getting to module __init__.py so that it can be turned into an API in future for further simplificaiton. - Apply this to other modules too in future commits. --- actions/deluge | 36 +++---------------------------- plinth/modules/deluge/__init__.py | 17 +++++++++++---- plinth/modules/deluge/views.py | 8 ++----- 3 files changed, 18 insertions(+), 43 deletions(-) diff --git a/actions/deluge b/actions/deluge index 1aae2cd47..846ab40fb 100755 --- a/actions/deluge +++ b/actions/deluge @@ -55,52 +55,22 @@ def parse_arguments(): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(dest='subcommand', help='Sub command') - # Get whether deluge-web site is enabled - subparsers.add_parser('get-enabled', - help='Get whether deluge-web site is enabled') - - # Enable deluge-web site and start deluge-web subparsers.add_parser('enable', help='Enable deluge-web site') - - # Disable deluge-web site and stop deluge-web subparsers.add_parser('disable', help='Disable deluge-web site') return parser.parse_args() -def subcommand_get_enabled(_): - """Get whether deluge-web site is enabled.""" - try: - subprocess.check_output(['a2query', '-c', 'deluge-plinth'], - stderr=subprocess.STDOUT) - subprocess.check_output(['systemctl', 'is-enabled', 'deluge-web']) - print('yes') - except subprocess.CalledProcessError: - print('no') - - def subcommand_enable(_): """Enable deluge-web site and start deluge-web.""" setup() - enable() + action_utils.service_enable('deluge-web') + action_utils.webserver_enable('deluge-plinth') def subcommand_disable(_): """Disable deluge-web site and stop deluge-web.""" - disable() - - -def enable(): - """Start and enable deluge-web service.""" - action_utils.service_enable('deluge-web') - subprocess.check_call(['a2enconf', 'deluge-plinth']) - action_utils.service_reload('apache2') - - -def disable(): - """Stop and disable deluge-web service.""" - subprocess.check_call(['a2disconf', 'deluge-plinth']) - action_utils.service_reload('apache2') + action_utils.webserver_disable('deluge-plinth') action_utils.service_disable('deluge-web') diff --git a/plinth/modules/deluge/__init__.py b/plinth/modules/deluge/__init__.py index 9d75208e3..62ee7dfdb 100644 --- a/plinth/modules/deluge/__init__.py +++ b/plinth/modules/deluge/__init__.py @@ -22,6 +22,7 @@ Plinth module to configure a Deluge web client. from gettext import gettext as _ from plinth import actions +from plinth import action_utils from plinth import cfg from plinth import service as service_module @@ -37,10 +38,18 @@ def init(): menu.add_urlname(_('BitTorrent (Deluge)'), 'glyphicon-magnet', 'deluge:index', 60) - output = actions.run('deluge', ['get-enabled']) - enabled = (output.strip() == 'yes') - global service service = service_module.Service( 'deluge', _('Deluge BitTorrent'), ['http', 'https'], - is_external=True, enabled=enabled) + is_external=True, enabled=is_enabled()) + + +def is_enabled(): + """Return whether the module is enabled.""" + return (action_utils.webserver_is_enabled('deluge-plinth') and + action_utils.service_is_enabled('deluge-web')) + + +def is_running(): + """Return whether the service is running.""" + return action_utils.service_is_running('deluge-web') diff --git a/plinth/modules/deluge/views.py b/plinth/modules/deluge/views.py index 25115ac51..af68a3807 100644 --- a/plinth/modules/deluge/views.py +++ b/plinth/modules/deluge/views.py @@ -25,7 +25,6 @@ from gettext import gettext as _ from .forms import DelugeForm from plinth import actions -from plinth import action_utils from plinth import package from plinth.modules import deluge @@ -55,11 +54,8 @@ def index(request): def get_status(): """Get the current settings.""" - output = actions.run('deluge', ['get-enabled']) - enabled = (output.strip() == 'yes') - - status = {'enabled': enabled, - 'is_running': action_utils.service_is_running('deluge-web')} + status = {'enabled': deluge.is_enabled(), + 'is_running': deluge.is_running()} return status