minidlna: Minor refactor of media directory handling

Tests performed:

- Functional tests work as expected.

- Updating the media directory works newly updated media directory is show.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2021-01-28 16:14:50 -08:00 committed by James Valleroy
parent 3255a7e658
commit 5cd1289198
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 13 additions and 7 deletions

View File

@ -93,3 +93,13 @@ def setup(helper, old_version=None):
helper.call('post', actions.superuser_run, 'minidlna', ['setup'])
if not old_version:
helper.call('post', app.enable)
def get_media_dir():
"""Return the currently set media directory."""
return actions.superuser_run('minidlna', ['get-media-dir'])
def set_media_dir(media_dir):
"""Set the media directory from which files will be scanned for sharing."""
actions.superuser_run('minidlna', ['set-media-dir', '--dir', media_dir])

View File

@ -7,7 +7,7 @@ import os
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _
from plinth import actions
from plinth.modules import minidlna
from plinth.views import AppView
from .forms import MiniDLNAServerForm
@ -20,9 +20,7 @@ class MiniDLNAAppView(AppView):
def get_initial(self):
"""Initial form value as found in the minidlna.conf"""
initial = super().get_initial()
initial.update({
'media_dir': actions.superuser_run('minidlna', ['get-media-dir']),
})
initial.update({'media_dir': minidlna.get_media_dir()})
return initial
@ -36,9 +34,7 @@ class MiniDLNAAppView(AppView):
messages.error(self.request,
_('Specified directory does not exist.'))
else:
actions.superuser_run(
'minidlna',
['set-media-dir', '--dir', new_config['media_dir']])
minidlna.set_media_dir(new_config['media_dir'])
messages.success(self.request, _('Updated media directory'))
return super().form_valid(form)