Skip to content

Commit

Permalink
Upadate internal references to ovos_config.config with ImportError …
Browse files Browse the repository at this point in the history
…handling
  • Loading branch information
NeonDaniel committed Apr 11, 2023
1 parent 164a15d commit a11d518
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 23 deletions.
6 changes: 5 additions & 1 deletion ovos_utils/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pathlib import Path

from ovos_utils.bracket_expansion import expand_options
from ovos_utils.configuration import read_mycroft_config
from ovos_utils.file_utils import resolve_resource_file
from ovos_utils.lang import translate_word
from ovos_utils.log import LOG
Expand Down Expand Up @@ -146,9 +145,14 @@ def get_dialog(phrase, lang=None, context=None):

if not lang:
try:
from ovos_config.config import read_mycroft_config
conf = read_mycroft_config()
lang = conf.get('lang')
except ImportError:
LOG.warning("Config not provided and ovos_config not available")
lang = "en-us"
except FileNotFoundError:
LOG.warning("Configuration file not found, default lang to 'en-us'")
lang = "en-us"

filename = join('text', lang.lower(), phrase + '.dialog')
Expand Down
8 changes: 6 additions & 2 deletions ovos_utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from watchdog.observers import Observer

from ovos_utils.bracket_expansion import expand_options
from ovos_utils.configuration import read_mycroft_config
from ovos_utils.log import LOG
from ovos_utils.system import search_mycroft_core_location

Expand Down Expand Up @@ -105,7 +104,12 @@ def resolve_resource_file(res_name, root_path=None, config=None):
str: path to resource or None if no resource found
"""
if config is None:
config = read_mycroft_config()
try:
from ovos_config.config import read_mycroft_config
config = read_mycroft_config()
except ImportError:
LOG.warning("Config not provided and ovos_config not available")
config = dict()

# First look for fully qualified file (e.g. a user setting)
if os.path.isfile(res_name):
Expand Down
9 changes: 7 additions & 2 deletions ovos_utils/fingerprinting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import socket
from enum import Enum
from os.path import join, isfile
from ovos_utils.log import LOG
from ovos_utils.system import is_installed, is_running_from_module, has_screen, \
get_desktop_environment, search_mycroft_core_location, is_process_running
from ovos_utils.configuration import read_mycroft_config


class MycroftPlatform(str, Enum):
Expand All @@ -28,7 +28,12 @@ def detect_platform():

def get_config_fingerprint(config=None):
if not config:
config = read_mycroft_config()
try:
from ovos_config.config import read_mycroft_config
config = read_mycroft_config()
except ImportError:
LOG.warning("Config not provided and ovos_config not available")
config = dict()
conf = config
listener_conf = conf.get("listener", {})
skills_conf = conf.get("skills", {})
Expand Down
10 changes: 8 additions & 2 deletions ovos_utils/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from ovos_utils.log import LOG
from ovos_utils.messagebus import wait_for_reply, get_mycroft_bus, Message
from ovos_utils.system import is_installed, has_screen, is_process_running
from ovos_utils.configuration import read_mycroft_config


def can_display():
Expand Down Expand Up @@ -461,7 +460,14 @@ class GUIInterface:
"""

def __init__(self, skill_id, bus=None, remote_server=None, config=None):
self.config = config or read_mycroft_config().get("gui", {})
if not config:
try:
from ovos_config.config import read_mycroft_config
config = read_mycroft_config().get("gui", {})
except ImportError:
LOG.warning("Config not provided and ovos_config not available")
config = dict()
self.config = config
if remote_server:
self.config["remote-server"] = remote_server
self._bus = bus
Expand Down
11 changes: 8 additions & 3 deletions ovos_utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ def __init__(cls, name='OVOS'):
@classmethod
def init(cls, config=None):

from ovos_utils.configuration import get_xdg_base
try:
from ovos_config.meta import get_xdg_base
default_base = get_xdg_base()
except ImportError:
default_base = "mycroft"
from ovos_utils.xdg_utils import xdg_state_home

config = config or {}
cls.base_path = config.get("path") or f"{xdg_state_home()}/{get_xdg_base()}"
cls.base_path = config.get("path") or \
f"{xdg_state_home()}/{default_base}"
cls.max_bytes = config.get("max_bytes", 50000000)
cls.backup_count = config.get("backup_count", 3)
cls.level = config.get("level", "INFO")
Expand Down Expand Up @@ -147,7 +152,7 @@ def init_service_logger(service_name):
# this is makes all logs from this service be configured to write to service_name.log file
# if this is not called in every __main__.py entrypoint logs will be written
# to a generic OVOS.log file shared across all services
from ovos_utils.configuration import read_mycroft_config
from ovos_config.config import read_mycroft_config

_cfg = read_mycroft_config()
_log_level = _cfg.get("log_level", "INFO")
Expand Down
13 changes: 11 additions & 2 deletions ovos_utils/messagebus.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from inspect import signature
from threading import Event

from ovos_utils.configuration import read_mycroft_config, get_default_lang
# from ovos_utils.configuration import read_mycroft_config, get_default_lang
from pyee import BaseEventEmitter

from ovos_utils import create_loop
Expand Down Expand Up @@ -315,6 +315,7 @@ def get_message_lang(message=None):
Returns:
The language code from the message or the default language.
"""
from ovos_config.locale import get_default_lang
message = message or dig_for_message()
default_lang = get_default_lang()
if not message:
Expand All @@ -340,6 +341,7 @@ def get_mycroft_bus(host: str = None, port: int = None, route: str = None,
"""
Returns a connection to the mycroft messagebus
"""
from ovos_config.config import read_mycroft_config
config = read_mycroft_config().get('websocket') or dict()
host = host or config.get('host') or _DEFAULT_WS_CONFIG['host']
port = port or config.get('port') or _DEFAULT_WS_CONFIG['port']
Expand Down Expand Up @@ -742,6 +744,7 @@ def __init__(self, trigger_message, name=None, bus=None, config=None):
name(str): name identifier for .conf settings
bus (WebsocketClient): mycroft messagebus websocket
"""
from ovos_config.config import read_mycroft_config
config = config or read_mycroft_config()
self.trigger_message = trigger_message
self.name = name or self.__class__.__name__
Expand Down Expand Up @@ -885,7 +888,13 @@ def __init__(self, query_message, name=None, timeout=5, bus=None,
self.query_message.context["source"] = self.name
self.name = name or self.__class__.__name__
self.bus = bus or get_mycroft_bus()
config = config or read_mycroft_config()
if not config:
try:
from ovos_config.config import read_mycroft_config
config = read_mycroft_config()
except ImportError:
LOG.warning("Config not provided and ovos_config not available")
config = dict()
self.config = config.get(self.name, {})
self.timeout = timeout
self.query = None
Expand Down
8 changes: 6 additions & 2 deletions ovos_utils/network_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


from ovos_utils.log import LOG
from ovos_utils.configuration import read_mycroft_config


_DEFAULT_TEST_CONFIG = {
Expand All @@ -20,7 +19,12 @@

def get_network_tests_config():
"""Get network_tests object from mycroft.configuration."""
config = read_mycroft_config()
try:
from ovos_config.config import read_mycroft_config
config = read_mycroft_config()
except ImportError:
LOG.warning("ovos_config not available. Falling back to default config")
config = dict()
return config.get("network_tests", _DEFAULT_TEST_CONFIG)


Expand Down
10 changes: 8 additions & 2 deletions ovos_utils/process_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@


from ovos_utils.log import LOG
from ovos_utils.configuration import get_xdg_base
from ovos_utils.file_utils import get_temp_path


Expand Down Expand Up @@ -293,7 +292,14 @@ class PIDLock: # python 3+ 'class Lock'
"""
@classmethod
def init(cls):
cls.DIRECTORY = cls.DIRECTORY or get_temp_path(get_xdg_base())
try:
from ovos_config.meta import get_xdg_base
base_dir = get_xdg_base()
except ImportError:
LOG.warning("ovos-config not available, using default "
"'mycroft' basedir")
base_dir = "mycroft"
cls.DIRECTORY = cls.DIRECTORY or get_temp_path(base_dir)
#
# Class constants
DIRECTORY = None
Expand Down
8 changes: 6 additions & 2 deletions ovos_utils/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


from ovos_utils.log import LOG
from ovos_utils.configuration import read_mycroft_config


def get_ipc_directory(domain=None, config=None):
Expand All @@ -24,7 +23,12 @@ def get_ipc_directory(domain=None, config=None):
str: a path to the IPC directory
"""
if config is None:
config = read_mycroft_config()
try:
from ovos_config.config import read_mycroft_config
config = read_mycroft_config()
except ImportError:
LOG.warning("Config not provided and ovos_config not available")
config = dict()
path = config.get("ipc_path")
if not path:
# If not defined, use /tmp/mycroft/ipc
Expand Down
2 changes: 1 addition & 1 deletion ovos_utils/skills/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ovos_utils.configuration import read_mycroft_config, update_mycroft_config
from ovos_config.config import read_mycroft_config, update_mycroft_config
from ovos_utils.messagebus import wait_for_reply
from ovos_utils.skills.locations import get_default_skills_directory, get_installed_skill_ids
from ovos_utils.log import LOG
Expand Down
3 changes: 2 additions & 1 deletion ovos_utils/skills/locations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from os.path import join, isdir, dirname, expanduser, isfile
from os import makedirs, listdir
from typing import List, Optional
from ovos_utils.configuration import read_mycroft_config, get_xdg_data_save_path, get_xdg_data_dirs
from ovos_config.config import read_mycroft_config
from ovos_config.locations import get_xdg_data_save_path, get_xdg_data_dirs
from ovos_utils.log import LOG


Expand Down
10 changes: 8 additions & 2 deletions ovos_utils/smtp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from email.mime.text import MIMEText
from smtplib import SMTP_SSL

from ovos_utils.configuration import read_mycroft_config
from ovos_utils.log import LOG


def send_smtp(user, pswd, sender,
Expand All @@ -19,7 +19,13 @@ def send_smtp(user, pswd, sender,


def send_email(subject, body, recipient=None):
mail_config = read_mycroft_config().get("email") or {}
try:
from ovos_config.config import read_mycroft_config
config = read_mycroft_config()
except ImportError:
LOG.warning("Config not provided and ovos_config not available")
config = dict()
mail_config = config.get("email") or {}
if not mail_config:
raise KeyError("email configuration not set")

Expand Down
2 changes: 1 addition & 1 deletion ovos_utils/sound/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from distutils.spawn import find_executable


from ovos_utils.configuration import read_mycroft_config
from ovos_config.config import read_mycroft_config

from ovos_utils.file_utils import resolve_resource_file
from ovos_utils.log import LOG
Expand Down

0 comments on commit a11d518

Please sign in to comment.