mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
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:
parent
ac19238e91
commit
7cf47bbcb2
@ -55,52 +55,22 @@ def parse_arguments():
|
|||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
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')
|
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')
|
subparsers.add_parser('disable', help='Disable deluge-web site')
|
||||||
|
|
||||||
return parser.parse_args()
|
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(_):
|
def subcommand_enable(_):
|
||||||
"""Enable deluge-web site and start deluge-web."""
|
"""Enable deluge-web site and start deluge-web."""
|
||||||
setup()
|
setup()
|
||||||
enable()
|
action_utils.service_enable('deluge-web')
|
||||||
|
action_utils.webserver_enable('deluge-plinth')
|
||||||
|
|
||||||
|
|
||||||
def subcommand_disable(_):
|
def subcommand_disable(_):
|
||||||
"""Disable deluge-web site and stop deluge-web."""
|
"""Disable deluge-web site and stop deluge-web."""
|
||||||
disable()
|
action_utils.webserver_disable('deluge-plinth')
|
||||||
|
|
||||||
|
|
||||||
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.service_disable('deluge-web')
|
action_utils.service_disable('deluge-web')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,7 @@ Plinth module to configure a Deluge web client.
|
|||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
|
from plinth import action_utils
|
||||||
from plinth import cfg
|
from plinth import cfg
|
||||||
from plinth import service as service_module
|
from plinth import service as service_module
|
||||||
|
|
||||||
@ -37,10 +38,18 @@ def init():
|
|||||||
menu.add_urlname(_('BitTorrent (Deluge)'), 'glyphicon-magnet',
|
menu.add_urlname(_('BitTorrent (Deluge)'), 'glyphicon-magnet',
|
||||||
'deluge:index', 60)
|
'deluge:index', 60)
|
||||||
|
|
||||||
output = actions.run('deluge', ['get-enabled'])
|
|
||||||
enabled = (output.strip() == 'yes')
|
|
||||||
|
|
||||||
global service
|
global service
|
||||||
service = service_module.Service(
|
service = service_module.Service(
|
||||||
'deluge', _('Deluge BitTorrent'), ['http', 'https'],
|
'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')
|
||||||
|
|||||||
@ -25,7 +25,6 @@ from gettext import gettext as _
|
|||||||
|
|
||||||
from .forms import DelugeForm
|
from .forms import DelugeForm
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
from plinth import action_utils
|
|
||||||
from plinth import package
|
from plinth import package
|
||||||
from plinth.modules import deluge
|
from plinth.modules import deluge
|
||||||
|
|
||||||
@ -55,11 +54,8 @@ def index(request):
|
|||||||
|
|
||||||
def get_status():
|
def get_status():
|
||||||
"""Get the current settings."""
|
"""Get the current settings."""
|
||||||
output = actions.run('deluge', ['get-enabled'])
|
status = {'enabled': deluge.is_enabled(),
|
||||||
enabled = (output.strip() == 'yes')
|
'is_running': deluge.is_running()}
|
||||||
|
|
||||||
status = {'enabled': enabled,
|
|
||||||
'is_running': action_utils.service_is_running('deluge-web')}
|
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user