mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +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:
2 files changed
+7
-6
No files matched your search
+7
-5
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user