transmission: Remove get-enabled from actions

This commit is contained in:
Sunil Mohan Adapa 2015-07-12 11:57:57 +05:30 committed by James Valleroy
parent 384867dc25
commit c9d918157c
3 changed files with 19 additions and 52 deletions

View File

@ -37,10 +37,6 @@ 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 Transmission service is enabled')
# Enable service # Enable service
subparsers.add_parser('enable', help='Enable Transmission service') subparsers.add_parser('enable', help='Enable Transmission service')
@ -58,50 +54,16 @@ def parse_arguments():
return parser.parse_args() return parser.parse_args()
def subcommand_get_enabled(_):
"""Get whether Transmission service is enabled."""
try:
with open(SERVICE_CONFIG, 'r') as file_handle:
for line in file_handle:
if line.startswith('ENABLE_DAEMON'):
value = line.split('=')[1].strip()
print('yes' if int(value) else 'no')
return
except IOError:
pass
print('no')
def subcommand_enable(_): def subcommand_enable(_):
"""Start Transmission service.""" """Start Transmission service."""
set_service_enable(enable=True) action_utils.service_enable('transmission-daemon')
action_utils.service_start('transmission-daemon') action_utils.webserver_enable('transmission-plinth')
subprocess.call(['a2enconf', 'transmission-plinth'])
action_utils.service_reload('apache2')
def subcommand_disable(_): def subcommand_disable(_):
"""Stop Transmission service.""" """Stop Transmission service."""
subprocess.call(['a2disconf', 'transmission-plinth']) action_utils.webserver_disable('transmission-plinth')
action_utils.service_reload('apache2') action_utils.service_disable('transmission-daemon')
action_utils.service_stop('transmission-daemon')
set_service_enable(enable=False)
def set_service_enable(enable):
"""Enable/disable Transmission daemon; enable: boolean."""
newline = 'ENABLE_DAEMON=1\n' if enable else 'ENABLE_DAEMON=0\n'
with open(SERVICE_CONFIG, 'r') as file_handle:
lines = file_handle.readlines()
for index, line in enumerate(lines):
if line.startswith('ENABLE_DAEMON'):
lines[index] = newline
break
with open(SERVICE_CONFIG, 'w') as file_handle:
file_handle.writelines(lines)
def subcommand_merge_configuration(arguments): def subcommand_merge_configuration(arguments):

View File

@ -22,6 +22,7 @@ Plinth module to configure Transmission 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,18 @@ def init():
menu.add_urlname(_('BitTorrent (Transmission)'), 'glyphicon-save', menu.add_urlname(_('BitTorrent (Transmission)'), 'glyphicon-save',
'transmission:index', 100) 'transmission:index', 100)
output = actions.run('transmission', ['get-enabled'])
enabled = (output.strip() == 'yes')
global service global service
service = service_module.Service( service = service_module.Service(
'transmission', _('Transmission BitTorrent'), ['http', 'https'], 'transmission', _('Transmission 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.service_is_enabled('transmission-daemon') and
action_utils.webserver_is_enabled('transmission-plinth'))
def is_running():
"""Return whether the service is running."""
return action_utils.service_is_running('transmission-daemon')

View File

@ -28,7 +28,6 @@ import socket
from .forms import TransmissionForm from .forms import TransmissionForm
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 transmission from plinth.modules import transmission
@ -67,15 +66,12 @@ def index(request):
def get_status(): def get_status():
"""Get the current settings from Transmission server.""" """Get the current settings from Transmission server."""
output = actions.run('transmission', ['get-enabled'])
enabled = (output.strip() == 'yes')
configuration = open(TRANSMISSION_CONFIG, 'r').read() configuration = open(TRANSMISSION_CONFIG, 'r').read()
status = json.loads(configuration) status = json.loads(configuration)
status = {key.translate(str.maketrans({'-': '_'})): value status = {key.translate(str.maketrans({'-': '_'})): value
for key, value in status.items()} for key, value in status.items()}
status['enabled'] = enabled status['enabled'] = transmission.is_enabled()
status['is_running'] = action_utils.service_is_running('transmission-daemon') status['is_running'] = transmission.is_running()
status['hostname'] = socket.gethostname() status['hostname'] = socket.gethostname()
return status return status