Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,16 @@ jobs:
env:
GITHUB_TOKEN: ${{secrets.neon_token}}

- name: Test Skill Utils
- name: Test Util
run: |
pytest test/test_skill_utils.py --doctest-modules --junitxml=tests/skill-utils-test-results.xml
pytest test/test_util.py --doctest-modules --junitxml=tests/util-test-results.xml
env:
GITHUB_TOKEN: ${{secrets.neon_token}}
- name: Upload Skill Utils test results
- name: Upload Util test results
uses: actions/upload-artifact@v2
with:
name: skill-utils-test-results
path: tests/skill-utils-test-results.xml

- name: Test Diagnostic Utils
run: |
pytest test/test_diagnostic_utils.py --doctest-modules --junitxml=tests/diagnostic-utils-test-results.xml
env:
GITHUB_TOKEN: ${{secrets.neon_token}}
- name: Upload Diagnostic Utils test results
uses: actions/upload-artifact@v2
with:
name: diagnostic-utils-test-results
path: tests/diagnostic-utils-test-results.xml
path: tests/util-test-results.xml

unit_tests:
strategy:
Expand Down
27 changes: 27 additions & 0 deletions neon_core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,33 @@ def install_skill_requirements(skill_dir):
click.echo(e)


@neon_core_cli.command(help="Export Core Configuration")
@click.argument("output_directory")
def export_configuration(output_directory):
from neon_core.util.device_utils import export_user_config
from neon_utils.configuration_utils import init_config_dir
try:
init_config_dir()
output = export_user_config(output_directory)
click.echo(f"Exported configuration to: {output}")
except Exception as e:
click.echo(e)


@neon_core_cli.command(help="Import Core Configuration")
@click.argument("exported_configuration")
def export_configuration(exported_configuration):
from neon_core.util.device_utils import import_user_config
from neon_utils.configuration_utils import init_config_dir
try:
init_config_dir()
config_path = import_user_config(exported_configuration)
click.echo(f"Imported configuration to: {config_path}. Services may "
f"need to be restarted to load these changes")
except Exception as e:
click.echo(e)


@neon_core_cli.command(help="Start Neon Skills module")
@click.option("--install-skills", "-i", default=None,
help="Path to local skills for which to install dependencies")
Expand Down
69 changes: 69 additions & 0 deletions neon_core/util/device_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# NEON AI (TM) SOFTWARE, Software Development Kit & Application Framework
# All trademark and other rights reserved by their respective owners
# Copyright 2008-2022 Neongecko.com Inc.
# Contributors: Daniel McKnight, Guy Daniels, Elon Gasper, Richard Leeds,
# Regina Bloomstine, Casimiro Ferreira, Andrii Pernatii, Kirill Hrymailo
# BSD-3 License
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from this
# software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import shutil

from os import makedirs
from os.path import expanduser, isdir, exists, join, isfile
from ovos_utils.xdg_utils import xdg_config_home


def export_user_config(output_path: str, config_path: str = None) -> str:
"""
Export user configuration to an archive for backup/migration
@param output_path: Directory to write output archive to
@param config_path: Configuration path to export (else use XDG)
@return: Path to generated output file
"""
output_path = join(expanduser(output_path), "neon_export")
if exists(output_path) and not isdir(output_path):
raise FileExistsError(f"Expected output directory but got file: "
f"{output_path}")
if exists(f"{output_path}.zip"):
raise FileExistsError(f"Export already exists: {output_path}.zip")
config_path = config_path or join(xdg_config_home(), "neon")
shutil.copytree(config_path, output_path)
output_file = shutil.make_archive(output_path, "zip", config_path,
config_path)
shutil.rmtree(output_path)
return output_file


def import_user_config(input_file: str, config_path: str = None) -> str:
"""
Export user configuration to an archive for backup/migration
@param input_file: Exported configuration archive to import
@param config_path: Configuration path to import to (else use XDG)
@return: Path configuration was imported to
"""
input_file = expanduser(input_file)
if not isfile(input_file):
raise FileNotFoundError(f"Invalid input file: {input_file}")
config_path = config_path or join(xdg_config_home(), "neon")
shutil.unpack_archive(input_file, config_path, "zip")
return config_path
1 change: 1 addition & 0 deletions neon_core/util/diagnostic_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def send_diagnostics(allow_logs=True, allow_transcripts=True, allow_config=True)
return data


# TODO: Deprecate method
def cli_send_diags():
"""
CLI Entry Point to Send Diagnostics
Expand Down
1 change: 1 addition & 0 deletions test/test_config_export/config/neon.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test_skill_key": "value"
}
Empty file.
Binary file added test/test_config_import/neon_export.zip
Binary file not shown.
132 changes: 0 additions & 132 deletions test/test_diagnostic_utils.py

This file was deleted.

Loading