From 79ba925afa7f4f60d635eb2516df090bc241cfba Mon Sep 17 00:00:00 2001 From: JarbasAI <33701864+JarbasAl@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:43:40 +0000 Subject: [PATCH 1/3] fix: drop deprecated dependency (#13) * fix: drop deprecated dependency OpenVoiceOS/ovos_skill_installer has been archived for a LONG time * Update __init__.py * Delete requirements.txt * Update requirements.txt --- ovos_ww_plugin_vosk/__init__.py | 113 +++++++++++++++++++++++++++++++- requirements.txt | 3 - requirements/requirements.txt | 5 +- 3 files changed, 113 insertions(+), 8 deletions(-) delete mode 100644 requirements.txt diff --git a/ovos_ww_plugin_vosk/__init__.py b/ovos_ww_plugin_vosk/__init__.py index c37f0dc..324634b 100644 --- a/ovos_ww_plugin_vosk/__init__.py +++ b/ovos_ww_plugin_vosk/__init__.py @@ -12,11 +12,18 @@ # import enum import json -from os.path import join, exists +import os +import shutil +import tarfile +import zipfile +from os import makedirs +from os.path import isdir, join, exists +from tempfile import mkstemp + +import requests from ovos_bus_client.message import Message from ovos_bus_client.util import get_mycroft_bus from ovos_plugin_manager.templates.hotwords import HotWordEngine -from ovos_skill_installer import download_extract_zip, download_extract_tar from ovos_utils.log import LOG from ovos_utils.parse import fuzzy_match, MatchStrategy from ovos_utils.xdg_utils import xdg_data_home @@ -373,3 +380,105 @@ def found_wake_word(self, frame_data): return False return True return False + + +def download(url, file=None, session=None): + """ + Pass file as a filename, open file object, or None to return the request bytes + + Args: + url (str): URL of file to download + file (Union[str, io, None]): One of the following: + - Filename of output file + - File opened in binary write mode + - None: Return raw bytes instead + + Returns: + Union[bytes, None]: Bytes of file if file is None + """ + + if isinstance(file, str): + file = open(file, 'wb') + try: + if session: + content = session.get(url).content + else: + content = requests.get(url).content + if file: + file.write(content) + else: + return content + finally: + if file: + file.close() + + +def download_extract_tar(tar_url, folder, tar_filename='', + skill_folder_name=None, session=None): + """ + Download and extract the tar at the url to the given folder + + Args: + tar_url (str): URL of tar file to download + folder (str): Location of parent directory to extract to. Doesn't have to exist + tar_filename (str): Location to download tar. Default is to a temp file + skill_folder_name (str): rename extracted skill folder to this + """ + try: + makedirs(folder) + except OSError: + if not isdir(folder): + raise + if not tar_filename: + fd, tar_filename = mkstemp('.tar.gz') + download(tar_url, os.fdopen(fd, 'wb'), session=session) + else: + download(tar_url, tar_filename, session=session) + + with tarfile.open(tar_filename) as tar: + tar.extractall(path=folder) + + if skill_folder_name: + with tarfile.open(tar_filename) as tar: + for p in tar.getnames(): + original_folder = p.split("/")[0] + break + original_folder = join(folder, original_folder) + final_folder = join(folder, skill_folder_name) + shutil.move(original_folder, final_folder) + + +def download_extract_zip(zip_url, folder, zip_filename="", + skill_folder_name=None, session=None): + """ + Download and extract the zip at the url to the given folder + + Args: + zip_url (str): URL of zip file to download + folder (str): Location of parent directory to extract to. Doesn't have to exist + zip_filename (str): Location to download zip. Default is to a temp file + skill_folder_name (str): rename extracted skill folder to this + """ + try: + makedirs(folder) + except OSError: + if not isdir(folder): + raise + if not zip_filename: + fd, zip_filename = mkstemp('.tar.gz') + download(zip_url, os.fdopen(fd, 'wb'), session=session) + else: + download(zip_url, zip_filename, session=session) + + with zipfile.ZipFile(zip_filename, 'r') as zip_ref: + zip_ref.extractall(folder) + + if skill_folder_name: + with zipfile.ZipFile(zip_filename, 'r') as zip_ref: + for p in zip_ref.namelist(): + original_folder = p.split("/")[0] + break + + original_folder = join(folder, original_folder) + final_folder = join(folder, skill_folder_name) + shutil.move(original_folder, final_folder) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 5c86bfc..0000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -numpy -vosk -ovos-plugin-manager>=0.0.1,<1.0.0 \ No newline at end of file diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 3c64214..861ee3e 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,5 +1,4 @@ numpy vosk -ovos-plugin-manager~=0.0, >=0.0.1 -ovos-skill-installer~=0.0 -ovos-bus-client >=0.0.6 +ovos-plugin-manager>=0.0.1 +ovos-bus-client>=0.0.6 From 1662134a6584f67cc6f6183459f03919c47d49f9 Mon Sep 17 00:00:00 2001 From: JarbasAl Date: Wed, 20 Nov 2024 13:43:56 +0000 Subject: [PATCH 2/3] Increment Version to 0.1.3a1 --- ovos_ww_plugin_vosk/version.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ovos_ww_plugin_vosk/version.py b/ovos_ww_plugin_vosk/version.py index 815acd1..9846811 100644 --- a/ovos_ww_plugin_vosk/version.py +++ b/ovos_ww_plugin_vosk/version.py @@ -1,6 +1,6 @@ # START_VERSION_BLOCK VERSION_MAJOR = 0 VERSION_MINOR = 1 -VERSION_BUILD = 2 -VERSION_ALPHA = 0 +VERSION_BUILD = 3 +VERSION_ALPHA = 1 # END_VERSION_BLOCK From d0ab37fa86808c35d9c08439c54ef16255107288 Mon Sep 17 00:00:00 2001 From: JarbasAl Date: Wed, 20 Nov 2024 13:44:16 +0000 Subject: [PATCH 3/3] Update Changelog --- CHANGELOG.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52ceb10..4a3244b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,16 @@ # Changelog -## [0.1.2a2](https://github.com/OpenVoiceOS/ovos-ww-plugin-vosk/tree/0.1.2a2) (2024-09-11) +## [0.1.3a1](https://github.com/OpenVoiceOS/ovos-ww-plugin-vosk/tree/0.1.3a1) (2024-11-20) -[Full Changelog](https://github.com/OpenVoiceOS/ovos-ww-plugin-vosk/compare/V0.1.2a1...0.1.2a2) +[Full Changelog](https://github.com/OpenVoiceOS/ovos-ww-plugin-vosk/compare/V0.1.2...0.1.3a1) **Merged pull requests:** -- feat:semver [\#9](https://github.com/OpenVoiceOS/ovos-ww-plugin-vosk/pull/9) ([JarbasAl](https://github.com/JarbasAl)) +- fix: drop deprecated dependency [\#13](https://github.com/OpenVoiceOS/ovos-ww-plugin-vosk/pull/13) ([JarbasAl](https://github.com/JarbasAl)) -## [V0.1.2a1](https://github.com/OpenVoiceOS/ovos-ww-plugin-vosk/tree/V0.1.2a1) (2024-01-21) +## [V0.1.2](https://github.com/OpenVoiceOS/ovos-ww-plugin-vosk/tree/V0.1.2) (2024-09-11) -[Full Changelog](https://github.com/OpenVoiceOS/ovos-ww-plugin-vosk/compare/V0.1.1...V0.1.2a1) - -**Merged pull requests:** - -- update for utils \>0.1.0 [\#8](https://github.com/OpenVoiceOS/ovos-ww-plugin-vosk/pull/8) ([builderjer](https://github.com/builderjer)) +[Full Changelog](https://github.com/OpenVoiceOS/ovos-ww-plugin-vosk/compare/0.1.2...V0.1.2)