mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
mumble: Remove get-enabled from actions
This commit is contained in:
parent
48da6862b9
commit
cedec9b624
@ -22,7 +22,6 @@ Configuration helper for Mumble server
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import subprocess
|
||||
|
||||
from plinth import action_utils
|
||||
|
||||
@ -35,60 +34,20 @@ def parse_arguments():
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||
|
||||
# Get whether service is enabled
|
||||
subparsers.add_parser('get-enabled',
|
||||
help='Get whether Mumble service is enabled')
|
||||
|
||||
# Enable service
|
||||
subparsers.add_parser('enable', help='Enable Mumble service')
|
||||
|
||||
# Disable service
|
||||
subparsers.add_parser('disable', help='Disable Mumble service')
|
||||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def subcommand_get_enabled(_):
|
||||
"""Get whether service is enabled."""
|
||||
try:
|
||||
with open(SERVICE_CONFIG, 'r') as file:
|
||||
for line in file:
|
||||
if line.startswith('MURMUR_DAEMON_START'):
|
||||
value = line.split('=')[1].strip()
|
||||
print('yes' if int(value) else 'no')
|
||||
return
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
print('no')
|
||||
|
||||
|
||||
def subcommand_enable(_):
|
||||
"""Start service."""
|
||||
set_service_enable(enable=True)
|
||||
action_utils.service_start('mumble-server')
|
||||
action_utils.service_enable('mumble-server')
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
"""Stop service."""
|
||||
action_utils.service_stop('mumble-server')
|
||||
set_service_enable(enable=False)
|
||||
|
||||
|
||||
def set_service_enable(enable):
|
||||
"""Enable/disable daemon; enable: boolean."""
|
||||
newline = 'MURMUR_DAEMON_START=1\n' if enable \
|
||||
else 'MURMUR_DAEMON_START=0\n'
|
||||
|
||||
with open(SERVICE_CONFIG, 'r') as file:
|
||||
lines = file.readlines()
|
||||
for index, line in enumerate(lines):
|
||||
if line.startswith('MURMUR_DAEMON_START'):
|
||||
lines[index] = newline
|
||||
break
|
||||
|
||||
with open(SERVICE_CONFIG, 'w') as file:
|
||||
file.writelines(lines)
|
||||
action_utils.service_disable('mumble-server')
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@ -22,6 +22,7 @@ Plinth module to configure Mumble server
|
||||
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,17 @@ def init():
|
||||
menu.add_urlname(_('Voice Chat (Mumble)'), 'glyphicon-headphones',
|
||||
'mumble:index', 50)
|
||||
|
||||
output = actions.run('mumble', ['get-enabled'])
|
||||
enabled = (output.strip() == 'yes')
|
||||
|
||||
global service
|
||||
service = service_module.Service(
|
||||
'mumble-plinth', _('Mumble Voice Chat Server'),
|
||||
is_external=True, enabled=enabled)
|
||||
is_external=True, enabled=is_enabled())
|
||||
|
||||
|
||||
def is_enabled():
|
||||
"""Return whether the module is enabled."""
|
||||
return action_utils.service_is_enabled('mumble-server')
|
||||
|
||||
|
||||
def is_running():
|
||||
"""Return whether the service is running."""
|
||||
return action_utils.service_is_running('mumble-server')
|
||||
|
||||
@ -26,7 +26,6 @@ import logging
|
||||
|
||||
from .forms import MumbleForm
|
||||
from plinth import actions
|
||||
from plinth import action_utils
|
||||
from plinth import package
|
||||
from plinth.modules import mumble
|
||||
|
||||
@ -63,13 +62,8 @@ def index(request):
|
||||
|
||||
def get_status():
|
||||
"""Get the current settings from server."""
|
||||
output = actions.run('mumble', ['get-enabled'])
|
||||
enabled = (output.strip() == 'yes')
|
||||
|
||||
status = {'enabled': enabled,
|
||||
'is_running': action_utils.service_is_running('mumble')}
|
||||
|
||||
return status
|
||||
return {'enabled': mumble.is_enabled(),
|
||||
'is_running': mumble.is_running()}
|
||||
|
||||
|
||||
def _apply_changes(request, old_status, new_status):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user