mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +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 argparse
|
||||||
import subprocess
|
|
||||||
|
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
|
|
||||||
@ -35,60 +34,20 @@ 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 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')
|
subparsers.add_parser('enable', help='Enable Mumble service')
|
||||||
|
|
||||||
# Disable service
|
|
||||||
subparsers.add_parser('disable', help='Disable Mumble service')
|
subparsers.add_parser('disable', help='Disable Mumble service')
|
||||||
|
|
||||||
return parser.parse_args()
|
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(_):
|
def subcommand_enable(_):
|
||||||
"""Start service."""
|
"""Start service."""
|
||||||
set_service_enable(enable=True)
|
action_utils.service_enable('mumble-server')
|
||||||
action_utils.service_start('mumble-server')
|
|
||||||
|
|
||||||
|
|
||||||
def subcommand_disable(_):
|
def subcommand_disable(_):
|
||||||
"""Stop service."""
|
"""Stop service."""
|
||||||
action_utils.service_stop('mumble-server')
|
action_utils.service_disable('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)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@ -22,6 +22,7 @@ Plinth module to configure Mumble server
|
|||||||
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,17 @@ def init():
|
|||||||
menu.add_urlname(_('Voice Chat (Mumble)'), 'glyphicon-headphones',
|
menu.add_urlname(_('Voice Chat (Mumble)'), 'glyphicon-headphones',
|
||||||
'mumble:index', 50)
|
'mumble:index', 50)
|
||||||
|
|
||||||
output = actions.run('mumble', ['get-enabled'])
|
|
||||||
enabled = (output.strip() == 'yes')
|
|
||||||
|
|
||||||
global service
|
global service
|
||||||
service = service_module.Service(
|
service = service_module.Service(
|
||||||
'mumble-plinth', _('Mumble Voice Chat Server'),
|
'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 .forms import MumbleForm
|
||||||
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 mumble
|
from plinth.modules import mumble
|
||||||
|
|
||||||
@ -63,13 +62,8 @@ def index(request):
|
|||||||
|
|
||||||
def get_status():
|
def get_status():
|
||||||
"""Get the current settings from server."""
|
"""Get the current settings from server."""
|
||||||
output = actions.run('mumble', ['get-enabled'])
|
return {'enabled': mumble.is_enabled(),
|
||||||
enabled = (output.strip() == 'yes')
|
'is_running': mumble.is_running()}
|
||||||
|
|
||||||
status = {'enabled': enabled,
|
|
||||||
'is_running': action_utils.service_is_running('mumble')}
|
|
||||||
|
|
||||||
return status
|
|
||||||
|
|
||||||
|
|
||||||
def _apply_changes(request, old_status, new_status):
|
def _apply_changes(request, old_status, new_status):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user