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

Catch empty server release check response, config references, neon_utils refactor, cleanup #20

Merged
merged 3 commits into from
May 7, 2021
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
142 changes: 78 additions & 64 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from random import randint
from mycroft_bus_client import Message
from neon_utils.skills.neon_skill import NeonSkill, LOG

from .data_utils import refresh_neon
# from mycroft.skills.core import MycroftSkill
# from mycroft.messagebus.message import Message
# from mycroft.util.log import LOG
Expand Down Expand Up @@ -79,9 +81,9 @@ def initialize(self):
self.register_intent(stop_solo_intent, self.handle_use_wake_words)

# When first run or demo prompt not dismissed, wait for load and prompt user
if self.configuration_available.get("prefFlags", {}).get("showDemo", False) and not self.server:
if self.local_config.get("prefFlags", {}).get("showDemo", False) and not self.server:
self.bus.once('mycroft.ready', self._show_demo_prompt)
elif self.configuration_available.get("prefFlags", {}).get("notifyRelease", False) and not self.server:
elif self.local_config.get("prefFlags", {}).get("notifyRelease", False) and not self.server:
self.bus.once('mycroft.ready', self._check_release)

def _show_demo_prompt(self, message):
Expand All @@ -102,15 +104,20 @@ def _check_release(self, message):
"""
LOG.debug("Checking release!")
resp = self.bus.wait_for_response(Message("neon.client.check_release"))
if not resp:
LOG.error(f"No response from server!")
return False
# TODO: Use versioning checks in neon_utils DM
version_file = glob.glob(
f'{self.configuration_available.get("dirVars", {}).get("ngiDir") or os.path.expanduser("~/neon")}'
f'{self.local_config.get("dirVars", {}).get("ngiDir") or os.path.expanduser("~/.neon")}'
f'/*.release')[0]
version = os.path.splitext(os.path.basename(version_file))[0] # 2009.0
major, minor = version.split('.')
new_major = resp.data.get("version_major", 0)
new_minor = resp.data.get("version_minor", 0)
# LOG.debug(str(result))
if new_major > major or (new_major == major and new_minor > minor):
# TODO: Dialog update when moved to packaged core DM
# Server Reported Release Different than Install
self.speak("There is a new release available from Neon Gecko. "
"Please pull changes on GitHub.", private=True, message=message)
Expand All @@ -125,7 +132,7 @@ def handle_skip_wake_words(self, message):
"""
if self.neon_in_request(message):
user = self.get_utterance_user(message)
if self.configuration_available.get("interface", {}).get("wake_word_enabled", True):
if self.local_config.get("interface", {}).get("wake_word_enabled", True):
self.clear_signals("DCC")
self.await_confirmation(user, "StartSWW")
self.speak_dialog("AskStartSkipping", expect_response=True, private=True)
Expand All @@ -137,7 +144,7 @@ def handle_use_wake_words(self, message):
Enable wake words and stop always-listening recognizer
:param message: message object associated with request
"""
if not self.configuration_available.get("interface", {}).get("wake_word_enabled", True):
if not self.local_config.get("interface", {}).get("wake_word_enabled", False):
user = self.get_utterance_user(message)
self.await_confirmation(user, "StopSWW")
self.speak_dialog("AskStartRequiring", expect_response=True, private=True)
Expand Down Expand Up @@ -206,12 +213,13 @@ def handle_update_neon(self, message):
self.clear_signals("DCC")
if self.check_for_signal('CORE_useHesitation', -1):
self.speak("Understood. Give me a moment to check for available updates.", private=True)
current_version = self.configuration_available.get("devVars", {}).get("version", "0000-00-00")
current_version = self.local_config.get("devVars", {}).get("version", "0000-00-00")

try:
new_version = git.Git(self.configuration_available["dirVars"]["coreDir"]).log(
# TODO: Support packaged installations here DM
new_version = git.Git(self.local_config["dirVars"]["coreDir"]).log(
"-1", "--format=%ai",
f'origin/{self.configuration_available.get("remoteVars", {}).get("coreBranch")}')
f'origin/{self.local_config.get("remoteVars", {}).get("coreBranch")}')
new_date, new_time, _ = new_version.split(" ", 2)
new_time = new_time.replace(":", "")
new_version = f"{new_date}-{new_time}"
Expand Down Expand Up @@ -245,7 +253,8 @@ def handle_show_demo(self, message):
if self.check_for_signal('CORE_useHesitation', -1):
self.speak("Here you go", private=True)
# import os
os.chdir(self.configuration_available["dirVars"]["ngiDir"])
# TODO: Make a new demo? DM
os.chdir(self.local_config["dirVars"]["ngiDir"])
os.system('gnome-terminal -- shortcuts/demoNeon.sh')

def handle_exit_shutdown_intent(self, message):
Expand Down Expand Up @@ -393,7 +402,7 @@ def converse(self, message=None):
if not self.server:
self.speak("Starting the update.", private=True)
try:
os.chdir(self.configuration_available.get("dirVars", {}).get("ngiDir"))
os.chdir(self.local_config.get("dirVars", {}).get("ngiDir"))
subprocess.call(['gnome-terminal', '--', 'sudo', "./update.sh"])
except HTTPError as e:
LOG.info(e)
Expand All @@ -410,7 +419,8 @@ def converse(self, message=None):
if f"exitNow_{confrimed_num}" in actions_requested:
self.speak_dialog("Exiting", private=True, wait=True)
if not self.server:
subprocess.call([self.configuration_available["dirVars"]["coreDir"] + '/stop_neon.sh'])
self.bus.emit(Message("neon.shutdown"))
# subprocess.call([self.local_config["dirVars"]["coreDir"] + '/stop_neon.sh'])

if f"shutdownNow_{confrimed_num}" in actions_requested:
LOG.info('quiting')
Expand All @@ -421,10 +431,8 @@ def converse(self, message=None):
if f"eraseAllData_{confrimed_num}" in actions_requested:
LOG.info(">>> Clear All")
self.speak_dialog("ConfirmClearAll", private=True)
if not self.server:
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -a"])
else:
# TODO: Non-server clear yml?
if self.server:
user_dict['ignored_brands'] = {}
user_dict['favorite_brands'] = {}
user_dict['specially_requested'] = {}
Expand Down Expand Up @@ -454,14 +462,14 @@ def converse(self, message=None):
user_dict["secondary_tts_gender"] = ""
user_dict["secondary_neon_voice"] = ""
user_dict["speed_multiplier"] = 1.0
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -A " + user_dict["username"]])
# subprocess.call(['bash', '-c', ". " + self.local_config["dirVars"]["ngiDir"]
# + "/functions.sh; refreshNeon -A " + user_dict["username"]])
if request_from_mobile(message):
self.mobile_skill_intent("clear_data", {"kind": "all"}, message)
else:
self.socket_emit_to_server("clear cookies intent",
[message.context["klat_data"]["request_id"]])

refresh_neon("all", user)
if f"eraseSelectedTranscriptions_{confrimed_num}" in actions_requested:
LOG.info(">>> Clear Selected Transcripts")
if f"eraseLikes_{confrimed_num}" in actions_requested:
Expand All @@ -477,12 +485,13 @@ def converse(self, message=None):
self.user_config.update_yaml_file("brands", "specially_requested", {})
else:
self.speak("Taking care of your selected transcripts folder", private=True)
if self.server:
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -S " + user_dict["username"]])
else:
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -s"])
refresh_neon("selected", user)
# if self.server:
# subprocess.call(['bash', '-c', ". " + self.local_config["dirVars"]["ngiDir"]
# + "/functions.sh; refreshNeon -S " + user_dict["username"]])
# else:
# subprocess.call(['bash', '-c', ". " + self.local_config["dirVars"]["ngiDir"]
# + "/functions.sh; refreshNeon -s"])

if f"eraseIgnoredTranscriptions_{confrimed_num}" in actions_requested:
LOG.info(">>> Clear Ignored Transcripts")
Expand All @@ -495,26 +504,28 @@ def converse(self, message=None):
self.user_config.update_yaml_file("brands", "ignored_brands", {})
else:
self.speak("Taking care of your ignored brands transcriptions", private=True)
if self.server:
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -I " + user_dict["username"]])
else:
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -i"])
refresh_neon("ignored", user)
# if self.server:
# subprocess.call(['bash', '-c', ". " + self.local_config["dirVars"]["ngiDir"]
# + "/functions.sh; refreshNeon -I " + user_dict["username"]])
# else:
# subprocess.call(['bash', '-c', ". " + self.local_config["dirVars"]["ngiDir"]
# + "/functions.sh; refreshNeon -i"])

if f"eraseAllTranscriptions_{confrimed_num}" in actions_requested:
LOG.info(">>> Clear All Transcripts")
self.speak_dialog("ConfirmClearData", {"kind": "audio recordings and transcriptions"},
private=True)
# self.speak("Audio recordings and transcriptions cleared", private=True)
if self.server:
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -T " + user_dict["username"]])
if request_from_mobile(message):
self.mobile_skill_intent("clear_data", {"kind": "transcripts"}, message)
else:
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -t"])
refresh_neon("transcripts", user)
# if self.server:
# subprocess.call(['bash', '-c', ". " + self.local_config["dirVars"]["ngiDir"]
# + "/functions.sh; refreshNeon -T " + user_dict["username"]])
# if request_from_mobile(message):
# self.mobile_skill_intent("clear_data", {"kind": "transcripts"}, message)
# else:
# subprocess.call(['bash', '-c', ". " + self.local_config["dirVars"]["ngiDir"]
# + "/functions.sh; refreshNeon -t"])

if f"eraseProfile_{confrimed_num}" in actions_requested:
LOG.info(">>> Clear Profile")
Expand All @@ -531,53 +542,56 @@ def converse(self, message=None):
user_dict["about"] = ""
else:
# TODO: Update user profile DM
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -u"])
pass
# subprocess.call(['bash', '-c', ". " + self.local_config["dirVars"]["ngiDir"]
# + "/functions.sh; refreshNeon -u"])

if f"eraseCache_{confrimed_num}" in actions_requested:
self.speak_dialog("ConfirmClearData", {"kind": "cached responses"}, private=True)
if not self.server:
# self.speak("Clearing All cached responses.", private=True)
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -c"])
# if not self.server:
# # self.speak("Clearing All cached responses.", private=True)
# subprocess.call(['bash', '-c', ". " + self.local_config["dirVars"]["ngiDir"]
# + "/functions.sh; refreshNeon -c"])
# else:
LOG.debug("Clear Caches")
if request_from_mobile(message):
self.mobile_skill_intent("clear_data", {"kind": "cache"}, message)
else:
LOG.debug("Clear Caches")
if request_from_mobile(message):
self.mobile_skill_intent("clear_data", {"kind": "cache"}, message)
else:
self.socket_emit_to_server("clear cookies intent",
[message.context["klat_data"]["request_id"]])
self.socket_emit_to_server("clear cookies intent",
[message.context["klat_data"]["request_id"]])
refresh_neon("caches", user)

if f"erasePrefs_{confrimed_num}" in actions_requested:
LOG.info(">>> Clear Preferences")
self.speak_dialog("ConfirmClearData", {"kind": "unit preferences"}, private=True)
# TODO: Update for non-server? DM
if self.server:
user_dict["time"] = 12
user_dict["date"] = "MDY"
user_dict["measure"] = "imperial"
else:
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -r"])
# else:
# subprocess.call(['bash', '-c', ". " + self.local_config["dirVars"]["ngiDir"]
# + "/functions.sh; refreshNeon -r"])
# self.speak("Resetting all interface preferences.", private=True)

if f"eraseMedia_{confrimed_num}" in actions_requested:
# Neon.clear_data(['p'])
self.speak_dialog("ConfirmClearData",
{"kind": "pictures, videos, and audio recordings I have taken."},
private=True)
if self.server:
if request_from_mobile(message):
self.mobile_skill_intent("clear_data", {"kind": "media"}, message)
else:
pass
else:
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -p"])
# if self.server:
if request_from_mobile(message):
self.mobile_skill_intent("clear_data", {"kind": "media"}, message)
refresh_neon("media", user)
# else:
# subprocess.call(['bash', '-c', ". " + self.local_config["dirVars"]["ngiDir"]
# + "/functions.sh; refreshNeon -p"])

if f"eraseLanguages_{confrimed_num}" in actions_requested:
self.speak_dialog("ConfirmClearData", {"kind": "language preferences"}, private=True)
# self.speak("Resetting your language preferences.", private=True)
# Neon.clear_data(['l'])
# TODO: Update for non-server? DM
if self.server:
user_dict["stt_language"] = "en"
user_dict["stt_region"] = "US"
Expand All @@ -589,9 +603,9 @@ def converse(self, message=None):
user_dict["secondary_tts_gender"] = ""
user_dict["secondary_neon_voice"] = ""
user_dict["speed_multiplier"] = 1.0
else:
subprocess.call(['bash', '-c', ". " + self.configuration_available["dirVars"]["ngiDir"]
+ "/functions.sh; refreshNeon -l"])
# else:
# subprocess.call(['bash', '-c', ". " + self.local_config["dirVars"]["ngiDir"]
# + "/functions.sh; refreshNeon -l"])

LOG.debug("DM: Clear Data Confirmed")
if self.server:
Expand Down
Loading