def load_remote(self, settings=None): log.debug('Loading remote config...') try: self.__store_cache(settings or DeviceApi(self.rt).get_settings()) self.load_local() except ConnectionError: log.exception('Loading Remote Config')
def load_plugin(plugin_cls: Type[BasePlugin], args, kwargs): if not plugin_cls: return None try: plugin = plugin_cls(*args, **kwargs) except Exception: log.exception('Loading', plugin_cls.__name__) return None return plugin
def _get_transcription(self, recording): utterance = '' try: utterance = self.stt.transcribe(recording) except ValueError: log.info('Found no words in audio') except RequestException: log.exception('Speech Client') else: log.info('Utterance: ' + utterance) return utterance
def run(self): while not self.rt.main_thread.quit_event.is_set(): try: with suppress(NewQuerySignal): with suppress(SkipActivationSignal): self.recognizer.wait_for_wake_word() self.send_query(self.record_phrase()) except (SystemExit, KeyboardInterrupt): raise except Exception: log.exception('In speech interface')
def assign(self, data): """Set identity from data""" if not isinstance(data, dict): log.error('Invalid Identity Data:', data) return try: self.uuid = data['uuid'] self.access_token = data['access'] self.refresh_token = data['refresh'] self.expiration = data['expires_at'] except KeyError: log.exception('Loading Identity')
def _try_run_packages(self, packages: List[Package]) -> Union[Package, None]: """Iterates through packages, executing handlers until one succeeds""" while len(packages) > 0: package = max(packages, key=lambda x: x.confidence) intent_id = package.match.intent_id del packages[packages.index(package)] log.info('Selected intent', intent_id, package.confidence) try: handler = self.intent_data[intent_id].get( 'handler', self.default_handler) return self._run_handler(handler, package) except Exception: log.exception(intent_id, 'callback') return None
def load_skill_class(self, folder_name): cls_name = to_camel(folder_name) try: mod = import_module(folder_name + '.skill') mod = reload(mod) cls = getattr(mod, cls_name, '') except Exception: log.exception('Loading', folder_name) return None if not isclass(cls): log.error('Could not find', cls_name, 'in', folder_name) return None update_dyn_attrs(cls, '_skill', self._plugin_path) return cls
def load_class(package: str, suffix: str, module: str, plugin_path: str, attr_name: str = None): package = package + '.' + module + suffix log.debug('Loading {}{}...'.format(module, suffix)) try: mod = import_module(package) cls_name = to_camel(module + suffix) cls = getattr(mod, cls_name, '') if not isclass(cls): log.error('Could not find', cls_name, 'in', package) elif not issubclass(cls, BasePlugin): log.error( '{} must inherit BasePlugin to be loaded dynamically'.format( cls.__name__)) else: update_dyn_attrs(cls, suffix, plugin_path, attr_name) return cls except Exception: log.exception('Loading Module', package) return None
def _log_exception(label, e, warn, stack_offset): if warn: log.warning(label, '--', e.__class__.__name__ + ':', e, stack_offset=stack_offset + 1) else: log.exception(label, stack_offset=stack_offset + 1)