Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speak update status following an update #56

Merged
merged 5 commits into from
Jun 26, 2023
Merged
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
61 changes: 58 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import os

from random import randint
from typing import Optional
from adapt.intent import IntentBuilder
from neon_utils.validator_utils import numeric_confirmation_validator
from ovos_utils import classproperty
Expand All @@ -43,6 +46,7 @@ def __init__(self, **kwargs):
NeonSkill.__init__(self, **kwargs)
self.current_ver = None
self.latest_ver = None
self._update_filename = "update_signal"

@classproperty
def runtime_requirements(self):
Expand Down Expand Up @@ -79,22 +83,41 @@ def image_drive(self):

# TODO: Move to __init__ after stable ovos-workshop
def initialize(self):
self.add_event('mycroft.ready',
self._check_latest_core_release, once=True)
self.add_event('mycroft.ready', self._on_ready)
self.add_event("update.gui.continue_installation",
self.continue_os_installation)
self.add_event("update.gui.finish_installation",
self.finish_os_installation)
self.add_event("update.gui.install_update", self.handle_update_device)

def _on_ready(self, message):
LOG.debug("Checking latest core version")
self._check_latest_core_release(message)

update_stat = self._check_update_status()
LOG.debug(f"Update status is {update_stat}")
if not update_stat:
# No update was attempted
return
speak_version = self.pronounce_version(self.current_ver)
if update_stat is True:
LOG.debug("Update success")
self.speak_dialog("notify_update_success",
{"version": speak_version})
elif update_stat is False:
LOG.warning("Update failed")
self.speak_dialog("notify_update_failure",
{"version": speak_version})

def _check_latest_core_release(self, message):
"""
Handles checking for a new release version
:param message: message object associated with loaded emit
"""
response = self.bus.wait_for_response(
message.forward("neon.core_updater.check_update",
{'include_prerelease': self.include_prerelease}))
{'include_prerelease': self.include_prerelease}),
timeout=15)
if response:
LOG.debug(f"Got response: {response.data}")
self.current_ver = response.data.get("installed_version")
Expand Down Expand Up @@ -158,12 +181,44 @@ def handle_update_device(self, message):
if resp == "yes":
if message.data.get('notification'):
self._dismiss_notification(message)
self._write_update_signal(self.latest_ver)
self.speak_dialog("starting_update", wait=True)
self.bus.emit(message.forward("neon.core_updater.start_update",
{"version": self.latest_ver}))
else:
self.speak_dialog("not_updating")

def _write_update_signal(self, new_ver: str):
"""
Write a file with the version being updated to that can be checked upon
next boot
:param new_ver: New core version being updated to
"""
with self.file_system.open(self._update_filename, 'w+') as f:
f.write(new_ver)

def _check_update_status(self) -> Optional[bool]:
"""
Check if an update was completed on startup.
Returns:
None if no update was attempted
True if an update was successful
False if an update failed
"""
update_filepath = os.path.join(self.file_system.path,
self._update_filename)
if not os.path.exists(update_filepath):
return None
with open(update_filepath, 'r') as f:
expected_ver = f.read()
os.remove(update_filepath)
LOG.info(f"Removed update signal at {update_filepath}")
if self.current_ver != expected_ver:
LOG.error(f"Update expected {expected_ver} but "
f"{self.current_ver} is installed")
return False
return True

@intent_file_handler("core_version.intent")
def handle_core_version(self, message):
"""
Expand Down
1 change: 1 addition & 0 deletions locale/en-us/dialog/notify_update_failure.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Something went wrong during the update. I am still running version {{version}}. You can ask to "create a support ticket" to get troubleshooting data.
1 change: 1 addition & 0 deletions locale/en-us/dialog/notify_update_success.dialog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I successfully updated to version {{version}}.
2 changes: 2 additions & 0 deletions test/test_resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ dialog:
- "confirm_no_change_update_track"
- "core_version"
- "error_offline"
- "notify_update_success"
- "notify_update_failure"
# regex entities, not necessarily filenames
regex: []
intents:
Expand Down