def test_store_settings(self): settings = dict(foo='bar') save_settings(self.skill_mock.root_dir, settings) settings_path = str(self.temp_dir.joinpath('settings.json')) with open(settings_path) as settings_file: file_contents = settings_file.read() self.assertEqual(file_contents, '{"foo": "bar"}')
def on_end(message): """Store settings and indicate that the skill handler has completed """ if self.settings != self._initial_settings: save_settings(self.settings_write_path, self.settings) self._initial_settings = deepcopy(self.settings) if handler_info: msg_type = handler_info + '.complete' message.context["skill_id"] = self.skill_id self.bus.emit(message.forward(msg_type, skill_data))
def _check_for_first_run(self): """The very first time a skill is run, speak the intro.""" first_run = self.instance.settings.get("__mycroft_skill_firstrun", True) if first_run: LOG.info("First run of " + self.skill_id) self.instance.settings["__mycroft_skill_firstrun"] = False save_settings(self.skill_directory, self.instance.settings) intro = self.instance.get_intro_message() if intro: self.instance.speak(intro)
def enable_email_polling(self, message): if self.update_credentials() is False: # No credentials return sender = normalize_email(message.data.get('sender')) setting = self.settings.get('look_for_email') if not setting: # The email notification service is not active yet if sender: self.settings['look_for_email'] = {"whitelist": [sender]} else: self.settings['look_for_email'] = {"whitelist": None} # Start the notification service self.schedule_repeating_event(self.poll_emails, datetime.now(), EMAIL_POLL_INTERVAL, name='poll.emails') self.speak_dialog("start.poll.email") else: if not setting['whitelist'] and sender: # The user request that we look for a specific email, but we are already notifying all incoming mails # Ask if the user wants to limit the notifications to that email replace = self.ask_yesno( prompt="cancel.looking.for.all.look.specific", data={"email": sender}) if replace == "yes": setting['whitelist'] = [sender] else: # We did not change anything, so the event data does not need to be updated return elif not setting['whitelist'] and not sender: # We were requested to look for all emails, but we are already doing that self.speak_dialog("already.looking.for.all") return elif sender in setting['whitelist']: # We were requested to look for emails by a specific person, but we are already doing that self.speak_dialog("already.looking.for.specific", data={"email": sender}) return elif setting['whitelist'] and not sender: replace = self.ask_yesno( prompt="cancel.looking.for.specific.look.all", data={"email": setting['whitelist']}) if replace == "yes": setting['whitelist'] = None else: # We did not change anything, so the event data does not need to be updated return else: setting['whitelist'].append(sender) self.speak_dialog("update.notify.data") save_settings(self.root_dir, self.settings)
def stop_debug_remote(self): self.log.info( 'Stoppig PTVSD - Python Tools for Visual Studio debug server.....') self.settings['remote_debug'] = False save_settings(self.root_dir, self.settings) self.set_single_thread(False) self.log.info('Restarting skillservice') proc = subprocess.Popen(self.root_dir + '/EndDebug.sh', preexec_fn=os.setsid, shell=True) proc.wait()
def update_skill_settings(self, new_preferences: dict, message: Message = None, skill_global=False): """ Updates skill settings with the passed new_preferences :param new_preferences: dict of updated preference values. {key: val} :param message: Message associated with request :param skill_global: Boolean to indicate these are global/non-user-specific variables """ LOG.debug(f"Update skill settings with new: {new_preferences}") if self.server and not skill_global: new_preferences["skill_id"] = self.skill_id self.update_profile({"skills": {self.skill_id: new_preferences}}, message) else: for key, val in new_preferences.items(): self.settings[key] = val self._ngi_settings[key] = val save_settings(self.settings_write_path, self.settings) self._ngi_settings.write_changes()
def initialize(self): if not self.settings.get('remote_debug'): self.settings['remote_debug'] = False save_settings(self.root_dir, self.settings) ptvsd_pid = self.is_process_running('python3 -m ptvsd') skills_pid = self.is_process_running(' -m mycroft.skills') if ptvsd_pid == skills_pid: self.set_single_thread(True) else: if ptvsd_pid: for p in ptvsd_pid: proc = subprocess.Popen('kill -9 ' + str(p), preexec_fn=os.setsid, shell=True) proc.wait() if self.settings.get('remote_debug') is True: self.debug_remote() else: self.set_single_thread(False)
def disable_email_polling(self, message): if not self.settings.get('look_for_email'): self.speak_dialog("poll.emails.not.started") return sender = normalize_email(message.data.get('sender')) if not sender: self.settings['look_for_email'] = None self.remove_event('poll.emails') self.speak_dialog("stop.poll.emails") else: # We are looking for all new emails, turn it off completely if not self.settings['look_for_email']['whitelist']: self.settings['look_for_email'] = None self.remove_event('poll.emails') self.speak_dialog("stop.poll.emails") save_settings(self.root_dir, self.settings) return # Do we even look for that sender? if not sender in self.settings['look_for_email']['whitelist']: self.speak_dialog("not.looking.for", data={"email": sender}) return if len(self.settings['look_for_email']['whitelist']) > 1: # Remove the sender from the whitelist self.settings['look_for_email']['whitelist'].remove(sender) self.speak_dialog("stop.looking.for", data={"email": sender}) else: # We don't have any email addresses to look for, so turn it off completely self.settings['look_for_email'] = None self.remove_event('poll.emails') self.speak_dialog("stop.poll.emails.last.email.removed") save_settings(self.root_dir, self.settings)