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.
This commit is contained in:
Sunil Mohan Adapa 2015-07-12 11:51:09 +05:30 committed by James Valleroy
parent ac19238e91
commit 7cf47bbcb2
3 changed files with 18 additions and 43 deletions

View File

@ -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')

View File

@ -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')

View File

@ -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