diff --git a/ovos_utils/enclosure/__init__.py b/ovos_utils/enclosure/__init__.py index bbebc37f..e9135711 100644 --- a/ovos_utils/enclosure/__init__.py +++ b/ovos_utils/enclosure/__init__.py @@ -3,9 +3,9 @@ from enum import Enum from os.path import exists from typing import Optional -from ovos_utils.log import LOG, deprecated +from ovos_utils.log import deprecated, log_deprecation -LOG.warning("ovos_utils.enclosure has been deprecated! this module will be removed in version 0.1.0") +log_deprecation("ovos_utils.enclosure has been deprecated!", "0.1.0") class MycroftEnclosures(str, Enum): diff --git a/ovos_utils/enclosure/api.py b/ovos_utils/enclosure/api.py index 7f48e48e..c3c2f59a 100644 --- a/ovos_utils/enclosure/api.py +++ b/ovos_utils/enclosure/api.py @@ -1,6 +1,7 @@ -from ovos_utils.log import LOG +from ovos_utils.log import log_deprecation + +log_deprecation("EnclosureApi has moved to ovos_bus_client.apis.enclosure", "0.1.0") -LOG.warning("EnclosureApi has moved to ovos_bus_client.apis.enclosure") try: from ovos_bus_client.apis.enclosure import EnclosureApi diff --git a/ovos_utils/enclosure/mark1/__init__.py b/ovos_utils/enclosure/mark1/__init__.py index 5e4766ac..6f51bbdd 100644 --- a/ovos_utils/enclosure/mark1/__init__.py +++ b/ovos_utils/enclosure/mark1/__init__.py @@ -1,8 +1,7 @@ from ovos_utils.enclosure.api import EnclosureAPI -from ovos_utils.log import LOG +from ovos_utils.log import log_deprecation -LOG.warning("ovos_utils.enclosure.mark1 moved to https://github.com/OpenVoiceOS/ovos-mark1-utils ;" - " this module will be removed in version 0.1.0") +log_deprecation("ovos_utils.enclosure.mark1 moved to https://github.com/OpenVoiceOS/ovos-mark1-utils", "0.1.0") class Mark1EnclosureAPI(EnclosureAPI): diff --git a/ovos_utils/enclosure/mark1/eyes/__init__.py b/ovos_utils/enclosure/mark1/eyes/__init__.py index 48743c48..334161eb 100644 --- a/ovos_utils/enclosure/mark1/eyes/__init__.py +++ b/ovos_utils/enclosure/mark1/eyes/__init__.py @@ -1,7 +1,7 @@ -from ovos_utils.log import LOG +from ovos_utils.log import log_deprecation + +log_deprecation("ovos_utils.enclosure.mark1.eyes moved to https://github.com/OpenVoiceOS/ovos-mark1-utils", "0.1.0") -LOG.warning("ovos_utils.enclosure.mark1.faceplate moved to https://github.com/OpenVoiceOS/ovos-mark1-utils ;" - " this module will be removed in version 0.1.0") try: from ovos_mark1.eyes import * diff --git a/ovos_utils/enclosure/mark1/faceplate/__init__.py b/ovos_utils/enclosure/mark1/faceplate/__init__.py index 64ebcce4..f6fedfbd 100644 --- a/ovos_utils/enclosure/mark1/faceplate/__init__.py +++ b/ovos_utils/enclosure/mark1/faceplate/__init__.py @@ -1,14 +1,13 @@ from ovos_utils.enclosure.mark1 import Mark1EnclosureAPI from ovos_utils import create_loop -from ovos_utils.log import LOG +from ovos_utils.log import LOG, log_deprecation from ovos_utils.messagebus import get_mycroft_bus import random from time import sleep from collections.abc import MutableSequence import copy -LOG.warning("ovos_utils.enclosure.mark1.faceplate moved to https://github.com/OpenVoiceOS/ovos-mark1-utils ;" - " this module will be removed in version 0.1.0") +log_deprecation("ovos_utils.enclosure.mark1.faceplate moved to https://github.com/OpenVoiceOS/ovos-mark1-utils", "0.1.0") try: diff --git a/ovos_utils/enclosure/mark1/faceplate/animations.py b/ovos_utils/enclosure/mark1/faceplate/animations.py index 93042170..cc50e40f 100644 --- a/ovos_utils/enclosure/mark1/faceplate/animations.py +++ b/ovos_utils/enclosure/mark1/faceplate/animations.py @@ -1,10 +1,10 @@ import copy import random -from ovos_utils.log import LOG +from ovos_utils.log import log_deprecation + +log_deprecation("ovos_utils.enclosure.mark1.faceplate moved to https://github.com/OpenVoiceOS/ovos-mark1-utils", "0.1.0") -LOG.warning("ovos_utils.enclosure.mark1.faceplate moved to https://github.com/OpenVoiceOS/ovos-mark1-utils ;" - " this module will be removed in version 0.1.0") try: from ovos_mark1.faceplate.animations import * diff --git a/ovos_utils/enclosure/mark1/faceplate/cellular_automaton.py b/ovos_utils/enclosure/mark1/faceplate/cellular_automaton.py index 92d43245..23198546 100644 --- a/ovos_utils/enclosure/mark1/faceplate/cellular_automaton.py +++ b/ovos_utils/enclosure/mark1/faceplate/cellular_automaton.py @@ -1,10 +1,10 @@ import copy import random -from ovos_utils.log import LOG +from ovos_utils.log import log_deprecation + +log_deprecation("ovos_utils.enclosure.mark1.faceplate moved to https://github.com/OpenVoiceOS/ovos-mark1-utils", "0.1.0") -LOG.warning("ovos_utils.enclosure.mark1.faceplate moved to https://github.com/OpenVoiceOS/ovos-mark1-utils ;" - " this module will be removed in version 0.1.0") try: from ovos_mark1.faceplate.cellular_automaton import * diff --git a/ovos_utils/enclosure/mark1/faceplate/icons.py b/ovos_utils/enclosure/mark1/faceplate/icons.py index 3db4ae83..f49c1e02 100644 --- a/ovos_utils/enclosure/mark1/faceplate/icons.py +++ b/ovos_utils/enclosure/mark1/faceplate/icons.py @@ -1,7 +1,7 @@ -from ovos_utils.log import LOG +from ovos_utils.log import log_deprecation + +log_deprecation("ovos_utils.enclosure.mark1.faceplate moved to https://github.com/OpenVoiceOS/ovos-mark1-utils", "0.1.0") -LOG.warning("ovos_utils.enclosure.mark1.faceplate moved to https://github.com/OpenVoiceOS/ovos-mark1-utils ;" - " this module will be removed in version 0.1.0") try: from ovos_mark1.faceplate.icons import * diff --git a/ovos_utils/intents/__init__.py b/ovos_utils/intents/__init__.py index 2f14e69d..2d329971 100644 --- a/ovos_utils/intents/__init__.py +++ b/ovos_utils/intents/__init__.py @@ -2,9 +2,9 @@ IntentServiceInterface from ovos_utils.intents.converse import ConverseTracker from ovos_utils.intents.layers import IntentLayers -from ovos_utils.log import LOG +from ovos_utils.log import log_deprecation -LOG.warning("ovos_utils.intents moved to ovos_workshop.intents") +log_deprecation("ovos_utils.intents moved to ovos_workshop.intents", "0.1.0") try: from ovos_workshop.intents import * diff --git a/ovos_utils/intents/converse.py b/ovos_utils/intents/converse.py index 05b545a1..ca8995ea 100644 --- a/ovos_utils/intents/converse.py +++ b/ovos_utils/intents/converse.py @@ -2,9 +2,9 @@ import ovos_utils.messagebus from ovos_utils.intents.intent_service_interface import IntentQueryApi -from ovos_utils.log import LOG +from ovos_utils.log import LOG, log_deprecation -LOG.warning("ConverseTracker has been deprecated without replacement, it will be removed in 0.1.0") +log_deprecation("ConverseTracker has been deprecated without replacement", "0.1.0") class ConverseTracker: diff --git a/ovos_utils/intents/intent_service_interface.py b/ovos_utils/intents/intent_service_interface.py index db6448b2..6fd52a2d 100644 --- a/ovos_utils/intents/intent_service_interface.py +++ b/ovos_utils/intents/intent_service_interface.py @@ -5,8 +5,7 @@ import ovos_utils.messagebus from ovos_utils.log import LOG, log_deprecation -LOG.warning("ovos_utils.intents moved to ovos_workshop.intents") - +log_deprecation("ovos_utils.intents moved to ovos_workshop.intents", "0.1.0") try: from ovos_workshop.intents import * diff --git a/ovos_utils/intents/layers.py b/ovos_utils/intents/layers.py index a699bf62..56097604 100644 --- a/ovos_utils/intents/layers.py +++ b/ovos_utils/intents/layers.py @@ -1,6 +1,6 @@ -from ovos_utils.log import LOG +from ovos_utils.log import LOG, log_deprecation -LOG.warning("IntentLayers moved to ovos_workshop.decorators.layers") +log_deprecation("IntentLayers moved to ovos_workshop.decorators.layers", "0.1.0") try: from ovos_workshop.decorators.layers import IntentLayers diff --git a/ovos_utils/messagebus.py b/ovos_utils/messagebus.py index 6bea298e..5251ef93 100644 --- a/ovos_utils/messagebus.py +++ b/ovos_utils/messagebus.py @@ -1,7 +1,6 @@ import json import time from copy import deepcopy -from inspect import signature from threading import Event # from ovos_utils.configuration import read_mycroft_config, get_default_lang @@ -9,15 +8,11 @@ from ovos_utils import create_loop from ovos_utils.json_helper import merge_dict -from ovos_utils.log import LOG, log_deprecation -from ovos_utils.metrics import Stopwatch -from ovos_utils.events import EventContainer, get_handler_name, create_basic_wrapper, create_wrapper, unmunge_message +from ovos_utils.log import LOG, log_deprecation, deprecated - -_DEFAULT_WS_CONFIG = {"host": "0.0.0.0", - "port": 8181, - "route": "/core", - "ssl": False} +log_deprecation("decode_binary_message, send_binary_file_message, send_binary_data_message, \ + send_message, wait_for_reply, listen_once_for_message, get_message_lang, get_websocket, get_mycroft_bus, \ + listen_for_message have moved to ovos_bus_client.util", "0.1.0") def dig_for_message(): @@ -360,187 +355,195 @@ def __int__(self, *args, **kwargs): FakeMessage.__init__(self, *args, **kwargs) -def get_message_lang(message=None): - """Get the language from the message or the default language. - Args: - message: message to check for language code. - Returns: - The language code from the message or the default language. - """ - try: - from ovos_config.locale import get_default_lang - default_lang = get_default_lang() - except ImportError: - LOG.warning("ovos_config not available. Using default lang en-us") - default_lang = "en-us" - message = message or dig_for_message() - if not message: - return default_lang - lang = message.data.get("lang") or message.context.get("lang") or default_lang - return lang.lower() +try: + from ovos_bus_client.util import decode_binary_message, send_binary_file_message, send_binary_data_message, \ + send_message, wait_for_reply, listen_once_for_message, get_message_lang, get_websocket, get_mycroft_bus, \ + listen_for_message +except: + _DEFAULT_WS_CONFIG = {"host": "0.0.0.0", + "port": 8181, + "route": "/core", + "ssl": False} -def get_websocket(host, port, route='/', ssl=False, threaded=True): - """ - Returns a connection to a websocket - """ - from ovos_bus_client import MessageBusClient + @deprecated("moved to ovos_bus_client.util", "0.1.0") + def get_message_lang(message=None): + """Get the language from the message or the default language. + Args: + message: message to check for language code. + Returns: + The language code from the message or the default language. + """ + try: + from ovos_config.locale import get_default_lang + default_lang = get_default_lang() + except ImportError: + LOG.warning("ovos_config not available. Using default lang en-us") + default_lang = "en-us" + message = message or dig_for_message() + if not message: + return default_lang + lang = message.data.get("lang") or message.context.get("lang") or default_lang + return lang.lower() - client = MessageBusClient(host, port, route, ssl) - if threaded: - client.run_in_thread() - return client + @deprecated("moved to ovos_bus_client.util", "0.1.0") + def get_websocket(host, port, route='/', ssl=False, threaded=True): + """ + Returns a connection to a websocket + """ + from ovos_bus_client import MessageBusClient -def get_mycroft_bus(host: str = None, port: int = None, route: str = None, - ssl: bool = None): - """ - Returns a connection to the mycroft messagebus - """ - try: - from ovos_config.config import read_mycroft_config - config = read_mycroft_config().get('websocket') or dict() - except ImportError: - LOG.warning("ovos_config not available. Falling back to default WS") - config = dict() - host = host or config.get('host') or _DEFAULT_WS_CONFIG['host'] - port = port or config.get('port') or _DEFAULT_WS_CONFIG['port'] - route = route or config.get('route') or _DEFAULT_WS_CONFIG['route'] - if ssl is None: - ssl = config.get('ssl') if 'ssl' in config else \ - _DEFAULT_WS_CONFIG['ssl'] - return get_websocket(host, port, route, ssl) - - -def listen_for_message(msg_type, handler, bus=None): - """ - Continuously listens and reacts to a specific messagetype on the mycroft messagebus + client = MessageBusClient(host, port, route, ssl) + if threaded: + client.run_in_thread() + return client - NOTE: when finished you should call bus.remove(msg_type, handler) - """ - bus = bus or get_mycroft_bus() - bus.on(msg_type, handler) - return bus + @deprecated("moved to ovos_bus_client.util", "0.1.0") + def get_mycroft_bus(host: str = None, port: int = None, route: str = None, + ssl: bool = None): + """ + Returns a connection to the mycroft messagebus + """ + try: + from ovos_config.config import read_mycroft_config + config = read_mycroft_config().get('websocket') or dict() + except ImportError: + LOG.warning("ovos_config not available. Falling back to default WS") + config = dict() + host = host or config.get('host') or _DEFAULT_WS_CONFIG['host'] + port = port or config.get('port') or _DEFAULT_WS_CONFIG['port'] + route = route or config.get('route') or _DEFAULT_WS_CONFIG['route'] + if ssl is None: + ssl = config.get('ssl') if 'ssl' in config else \ + _DEFAULT_WS_CONFIG['ssl'] + return get_websocket(host, port, route, ssl) + + + @deprecated("moved to ovos_bus_client.util", "0.1.0") + def listen_for_message(msg_type, handler, bus=None): + """ + Continuously listens and reacts to a specific messagetype on the mycroft messagebus -def listen_once_for_message(msg_type, handler, bus=None): - """ - listens and reacts once to a specific messagetype on the mycroft messagebus - """ - auto_close = bus is None - bus = bus or get_mycroft_bus() + NOTE: when finished you should call bus.remove(msg_type, handler) + """ + bus = bus or get_mycroft_bus() + bus.on(msg_type, handler) + return bus - def _handler(message): - handler(message) - if auto_close: - bus.close() - bus.once(msg_type, _handler) - return bus + @deprecated("moved to ovos_bus_client.util", "0.1.0") + def listen_once_for_message(msg_type, handler, bus=None): + """ + listens and reacts once to a specific messagetype on the mycroft messagebus + """ + auto_close = bus is None + bus = bus or get_mycroft_bus() + def _handler(message): + handler(message) + if auto_close: + bus.close() -def wait_for_reply(message, reply_type=None, timeout=3.0, bus=None): - """Send a message and wait for a response. + bus.once(msg_type, _handler) + return bus - Args: - message (FakeMessage or str or dict): message object or type to send - reply_type (str): the message type of the expected reply. - Defaults to ".response". - timeout: seconds to wait before timeout, defaults to 3 - Returns: - The received message or None if the response timed out - """ - auto_close = bus is None - bus = bus or get_mycroft_bus() - if isinstance(message, str): - try: - message = json.loads(message) - except: - pass - if isinstance(message, str): - message = FakeMessage(message) - elif isinstance(message, dict): - message = FakeMessage(message["type"], - message.get("data"), - message.get("context")) - elif not isinstance(message, FakeMessage): - raise ValueError - response = bus.wait_for_response(message, reply_type, timeout) - if auto_close: - bus.close() - return response - - -def send_message(message, data=None, context=None, bus=None): - auto_close = bus is None - bus = bus or get_mycroft_bus() - if isinstance(message, str): - if isinstance(data, dict) or isinstance(context, dict): - message = FakeMessage(message, data, context) - else: + + @deprecated("moved to ovos_bus_client.util", "0.1.0") + def wait_for_reply(message, reply_type=None, timeout=3.0, bus=None): + """Send a message and wait for a response. + + Args: + message (FakeMessage or str or dict): message object or type to send + reply_type (str): the message type of the expected reply. + Defaults to ".response". + timeout: seconds to wait before timeout, defaults to 3 + Returns: + The received message or None if the response timed out + """ + auto_close = bus is None + bus = bus or get_mycroft_bus() + if isinstance(message, str): try: message = json.loads(message) except: - message = FakeMessage(message) - if isinstance(message, dict): - message = FakeMessage(message["type"], - message.get("data"), - message.get("context")) - if not isinstance(message, FakeMessage): - raise ValueError - bus.emit(message) - if auto_close: - bus.close() - - -def send_binary_data_message(binary_data, msg_type="mycroft.binary.data", - msg_data=None, msg_context=None, bus=None): - msg_data = msg_data or {} - msg = { - "type": msg_type, - "data": merge_dict(msg_data, {"binary": binary_data.hex()}), - "context": msg_context or None - } - send_message(msg, bus=bus) - - -def send_binary_file_message(filepath, msg_type="mycroft.binary.file", - msg_context=None, bus=None): - with open(filepath, 'rb') as f: - binary_data = f.read() - msg_data = {"path": filepath} - send_binary_data_message(binary_data, msg_type=msg_type, msg_data=msg_data, - msg_context=msg_context, bus=bus) - - -def decode_binary_message(message): - if isinstance(message, str): - try: # json string - message = json.loads(message) + pass + if isinstance(message, str): + message = FakeMessage(message) + elif isinstance(message, dict): + message = FakeMessage(message["type"], + message.get("data"), + message.get("context")) + elif not isinstance(message, FakeMessage): + raise ValueError + response = bus.wait_for_response(message, reply_type, timeout) + if auto_close: + bus.close() + return response + + + @deprecated("moved to ovos_bus_client.util", "0.1.0") + def send_message(message, data=None, context=None, bus=None): + auto_close = bus is None + bus = bus or get_mycroft_bus() + if isinstance(message, str): + if isinstance(data, dict) or isinstance(context, dict): + message = FakeMessage(message, data, context) + else: + try: + message = json.loads(message) + except: + message = FakeMessage(message) + if isinstance(message, dict): + message = FakeMessage(message["type"], + message.get("data"), + message.get("context")) + if not isinstance(message, FakeMessage): + raise ValueError + bus.emit(message) + if auto_close: + bus.close() + + + @deprecated("moved to ovos_bus_client.util", "0.1.0") + def send_binary_data_message(binary_data, msg_type="mycroft.binary.data", + msg_data=None, msg_context=None, bus=None): + msg_data = msg_data or {} + msg = { + "type": msg_type, + "data": merge_dict(msg_data, {"binary": binary_data.hex()}), + "context": msg_context or None + } + send_message(msg, bus=bus) + + + @deprecated("moved to ovos_bus_client.util", "0.1.0") + def send_binary_file_message(filepath, msg_type="mycroft.binary.file", + msg_context=None, bus=None): + with open(filepath, 'rb') as f: + binary_data = f.read() + msg_data = {"path": filepath} + send_binary_data_message(binary_data, msg_type=msg_type, msg_data=msg_data, + msg_context=msg_context, bus=bus) + + + @deprecated("moved to ovos_bus_client.util", "0.1.0") + def decode_binary_message(message): + if isinstance(message, str): + try: # json string + message = json.loads(message) + binary_data = message.get("binary") or message["data"]["binary"] + except: # hex string + binary_data = message + elif isinstance(message, dict): + # data field or serialized message binary_data = message.get("binary") or message["data"]["binary"] - except: # hex string - binary_data = message - elif isinstance(message, dict): - # data field or serialized message - binary_data = message.get("binary") or message["data"]["binary"] - else: - # message object - binary_data = message.data["binary"] - # decode hex string - return bytearray.fromhex(binary_data) - - -def to_alnum(skill_id): - """Convert a skill id to only alphanumeric characters - - Non alpha-numeric characters are converted to "_" - - Args: - skill_id (str): identifier to be converted - Returns: - (str) String of letters - """ - return ''.join(c if c.isalnum() else '_' for c in str(skill_id)) + else: + # message object + binary_data = message.data["binary"] + # decode hex string + return bytearray.fromhex(binary_data) class BusService: @@ -557,6 +560,7 @@ class BusService: """ + @deprecated("deprecated without replacement", "0.1.0") def __init__(self, message, trigger_messages=None, bus=None): self.bus = bus or get_mycroft_bus() self.response = message @@ -604,6 +608,7 @@ def handle_get_time(self, message): """ + @deprecated("deprecated without replacement", "0.1.0") def __init__(self, trigger_message, name=None, bus=None, config=None): """ initialize responder @@ -691,6 +696,7 @@ class BusQuery: """ + @deprecated("deprecated without replacement", "0.1.0") def __init__(self, message, bus=None): self.bus = bus or get_mycroft_bus() self._waiting = False @@ -757,6 +763,7 @@ def __init__(self, name="clock_receiver", timeout=3, bus=None): """ + @deprecated("deprecated without replacement", "0.1.0") def __init__(self, query_message, name=None, timeout=5, bus=None, config=None): self.query_message = query_message diff --git a/ovos_utils/skills/api.py b/ovos_utils/skills/api.py index f85b0908..ee91f08c 100644 --- a/ovos_utils/skills/api.py +++ b/ovos_utils/skills/api.py @@ -1,6 +1,6 @@ -from ovos_utils.log import LOG +from ovos_utils.log import LOG, log_deprecation -LOG.warning("ovos_utils.skills.api moved to ovos_workshop.skills.api") +log_deprecation("ovos_utils.skills.api moved to ovos_workshop.skills.api", "0.1.0") try: from ovos_workshop.skills.api import SkillApi diff --git a/ovos_utils/skills/audioservice.py b/ovos_utils/skills/audioservice.py index 8c01c940..d583c95a 100644 --- a/ovos_utils/skills/audioservice.py +++ b/ovos_utils/skills/audioservice.py @@ -14,9 +14,9 @@ # from datetime import timedelta -from ovos_utils.log import LOG, deprecated +from ovos_utils.log import deprecated, log_deprecation -LOG.warning("ClassicAudioServiceInterface and OCPInterface moved to ovos_bus_client.apis.ocp") +log_deprecation("ClassicAudioServiceInterface and OCPInterface moved to ovos_bus_client.apis.ocp", "0.1.0") try: from ovos_bus_client.apis.ocp import OCPInterface, ClassicAudioServiceInterface, ensure_uri diff --git a/ovos_utils/skills/locations.py b/ovos_utils/skills/locations.py index f3296916..9ab84428 100644 --- a/ovos_utils/skills/locations.py +++ b/ovos_utils/skills/locations.py @@ -7,7 +7,7 @@ from ovos_utils.log import LOG, log_deprecation -LOG.warning("ovos_utils.skills.locations moved to ovos_plugin_manager.skills") +log_deprecation("ovos_utils.skills.locations moved to ovos_plugin_manager.skills", "0.1.0") try: from ovos_plugin_manager.skills import * diff --git a/ovos_utils/skills/settings.py b/ovos_utils/skills/settings.py index e44a49a8..1d476040 100644 --- a/ovos_utils/skills/settings.py +++ b/ovos_utils/skills/settings.py @@ -6,7 +6,7 @@ from ovos_utils.log import LOG, log_deprecation, deprecated -LOG.warning("ovos_utils.skills.settings moved to ovos_workshop.settings") +log_deprecation("ovos_utils.skills.settings moved to ovos_workshop.settings", "0.1.0") try: from ovos_workshop.settings import *