Create simple load_dialogs function

This function replaces the class since the class doesn't provide any
functionality
pull/2422/head
Åke Forslund 2019-12-09 09:34:04 +01:00
parent 24071cdea0
commit 2697cb8d56
1 changed files with 26 additions and 13 deletions

View File

@ -133,8 +133,7 @@ class DialogLoader:
self.__renderer = renderer_factory()
def load(self, dialog_dir):
"""
Load all dialog files within the specified directory.
"""Load all dialog files within the specified directory.
Args:
dialog_dir (str): directory that contains dialog files
@ -142,18 +141,32 @@ class DialogLoader:
Returns:
a loaded instance of a dialog renderer
"""
directory = Path(dialog_dir)
if not directory.exists() or not directory.is_dir():
LOG.warning("No dialog files found: {}".format(dialog_dir))
return self.__renderer
return load_dialogs(dialog_dir, self.__renderer)
for path, _, files in os.walk(str(directory)):
for f in files:
if f.endswith(".dialog"):
self.__renderer.load_template_file(
f.replace('.dialog', ''),
join(path, f))
return self.__renderer
def load_dialogs(dialog_dir, renderer=None):
"""Load all dialog files within the specified directory.
Arguments:
dialog_dir (str): directory that contains dialog files
Returns:
a loaded instance of a dialog renderer
"""
if renderer is None:
renderer = MustacheDialogRenderer()
directory = Path(dialog_dir)
if not directory.exists() or not directory.is_dir():
LOG.warning("No dialog files found: {}".format(dialog_dir))
return renderer
for path, _, files in os.walk(str(directory)):
for f in files:
if f.endswith(".dialog"):
renderer.load_template_file(f.replace('.dialog', ''),
join(path, f))
return renderer
def get(phrase, lang=None, context=None):