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 1 commit
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
49 changes: 47 additions & 2 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,14 +83,26 @@ 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, once=True)
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):
self._check_latest_core_release(message)

update_stat = self._check_update_status()
if update_stat is True:
LOG.debug("Update success")
self.speak_dialog("notify_update_success",
{"version": self.current_ver})
elif update_stat is False:
LOG.warning("Update failed")
self.speak_dialog("notify_update_failure",
{"version": self.current_ver})

def _check_latest_core_release(self, message):
"""
Handles checking for a new release version
Expand Down Expand Up @@ -158,12 +174,41 @@ 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
"""
if not self.file_system.exists(self._update_filename):
return None
with self.file_system.open(self._update_filename, 'r') as f:
expected_ver = f.read()
os.remove(os.path.join(self.file_system.path, self._update_filename))
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}}.
NeonDaniel marked this conversation as resolved.
Show resolved Hide resolved
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