mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
minidlna: Use single action to set media dir and restart
Style config path as constant. Signed-off-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
3bad37a749
commit
f19a5b746f
@ -25,10 +25,10 @@ import subprocess
|
||||
from os import fdopen, remove, chmod, stat
|
||||
|
||||
import augeas
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth.utils import grep
|
||||
|
||||
config_path = '/etc/minidlna.conf'
|
||||
CONFIG_PATH = '/etc/minidlna.conf'
|
||||
|
||||
|
||||
def parse_arguments():
|
||||
@ -67,17 +67,19 @@ def subcommand_setup(arguments):
|
||||
|
||||
def subcommand_get_media_dir(arguments):
|
||||
"""Retrieve media directory from minidlna.conf"""
|
||||
line = grep('^media_dir=', config_path)
|
||||
line = grep('^media_dir=', CONFIG_PATH)
|
||||
|
||||
print(line[0].split("=")[1])
|
||||
|
||||
|
||||
def subcommand_set_media_dir(arguments):
|
||||
"""Set media directory in minidlna.conf"""
|
||||
line = grep('^media_dir=', config_path)[0]
|
||||
line = grep('^media_dir=', CONFIG_PATH)[0]
|
||||
|
||||
new_line = 'media_dir=%s\n' % arguments.dir
|
||||
replace_in_config_file(config_path, line, new_line)
|
||||
replace_in_config_file(CONFIG_PATH, line, new_line)
|
||||
if action_utils.service_is_running('minidlna'):
|
||||
action_utils.service_restart('minidlna')
|
||||
|
||||
|
||||
def replace_in_config_file(file_path, pattern, subst):
|
||||
|
||||
@ -59,7 +59,6 @@ class MiniDLNAAppView(AppView):
|
||||
'minidlna',
|
||||
['set-media-dir', '--dir', new_config['media_dir']]
|
||||
)
|
||||
actions.superuser_run('service', ['restart', 'minidlna'])
|
||||
messages.success(self.request, _('Updated media directory'))
|
||||
|
||||
return super().form_valid(form)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user