From 847f0aadb26b3109ae3a63f4850299161384c180 Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Tue, 2 Mar 2021 02:19:10 -1000 Subject: [PATCH] refactor/config_kwarg_continued (#47) Co-authored-by: jarbasal --- ovos_utils/__init__.py | 1 + ovos_utils/plugins/tts.py | 4 ++-- ovos_utils/signal.py | 13 +++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/ovos_utils/__init__.py b/ovos_utils/__init__.py index f70ffe5..165673d 100644 --- a/ovos_utils/__init__.py +++ b/ovos_utils/__init__.py @@ -103,6 +103,7 @@ def resolve_resource_file(res_name, root_path=None, config=None): Args: res_name (str): a resource path/name + config (dict): mycroft.conf, to read data directory from Returns: str: path to resource or None if no resource found """ diff --git a/ovos_utils/plugins/tts.py b/ovos_utils/plugins/tts.py index 3febb1a..e3c999f 100644 --- a/ovos_utils/plugins/tts.py +++ b/ovos_utils/plugins/tts.py @@ -169,10 +169,10 @@ def __init__(self, lang, config, validator, audio_ext='wav', self.spellings = self.load_spellings() self.tts_name = type(self).__name__ - def load_spellings(self): + def load_spellings(self, config=None): """Load phonetic spellings of words as dictionary.""" path = join('text', self.lang.lower(), 'phonetic_spellings.txt') - spellings_file = resolve_resource_file(path) + spellings_file = resolve_resource_file(path, config=config) if not spellings_file: return {} try: diff --git a/ovos_utils/signal.py b/ovos_utils/signal.py index 605ff6f..1a3bdeb 100644 --- a/ovos_utils/signal.py +++ b/ovos_utils/signal.py @@ -17,6 +17,7 @@ def get_ipc_directory(domain=None, config=None): Args: domain (str): The IPC domain. Basically a subdirectory to prevent overlapping signal filenames. + config (dict): mycroft.conf, to read ipc directory from Returns: str: a path to the IPC directory @@ -75,22 +76,24 @@ def create_file(filename): f.write('') -def create_signal(signal_name): +def create_signal(signal_name, config=None): """Create a named signal Args: signal_name (str): The signal's name. Must only contain characters valid in filenames. + config (dict): mycroft.conf, to read ipc directory from """ try: - path = os.path.join(get_ipc_directory(), "signal", signal_name) + path = os.path.join(get_ipc_directory(config=config), + "signal", signal_name) create_file(path) return os.path.isfile(path) except IOError: return False -def check_for_signal(signal_name, sec_lifetime=0): +def check_for_signal(signal_name, sec_lifetime=0, config=None): """See if a named signal exists Args: @@ -99,11 +102,13 @@ def check_for_signal(signal_name, sec_lifetime=0): sec_lifetime (int, optional): How many seconds the signal should remain valid. If 0 or not specified, it is a single-use signal. If -1, it never expires. + config (dict): mycroft.conf, to read ipc directory from Returns: bool: True if the signal is defined, False otherwise """ - path = os.path.join(get_ipc_directory(), "signal", signal_name) + path = os.path.join(get_ipc_directory(config=config), + "signal", signal_name) if os.path.isfile(path): if sec_lifetime == 0: # consume this single-use signal