def get_config_dir(): """ Get a default directory in which to find configuration files Returns: Path to configuration or else default """ site = sysconfig.get_paths()['platlib'] if exists(join(site, 'NGI')): return join(site, "NGI") for p in [path for path in sys.path if path != ""]: if exists(join(p, "NGI")): return join(p, "NGI") if re.match(".*/lib/python.*/site-packages", p): clean_path = "/".join(p.split("/")[0:-4]) if exists(join(clean_path, "NGI")): LOG.warning( f"Depreciated core structure found at {clean_path}") return join(clean_path, "NGI") elif exists(join(clean_path, "neon_core")): # Dev Environment return clean_path elif exists(join(clean_path, "mycroft")): LOG.info(f"Mycroft core structure found at {clean_path}") return clean_path elif exists(join(clean_path, ".venv")): # Localized Production Environment (Servers) return clean_path default_path = expanduser("~/.local/share/neon") # LOG.info(f"System packaged core found! Using default configuration at {default_path}") return default_path
def synchronize(self): """ Upload namespaces, pages and data to the last connected. """ namespace_pos = 0 enclosure = self.application.enclosure for namespace, pages in enclosure.loaded: LOG.info('Sync {}'.format(namespace)) # Insert namespace self.send({"type": "mycroft.session.list.insert", "namespace": "mycroft.system.active_skills", "position": namespace_pos, "data": [{"skill_id": namespace}] }) # Insert pages self.send({"type": "mycroft.gui.list.insert", "namespace": namespace, "position": 0, "data": [{"url": p} for p in pages] }) # Insert data data = enclosure.datastore.get(namespace, {}) for key in data: self.send({"type": "mycroft.session.set", "namespace": namespace, "data": {key: data[key]} }) namespace_pos += 1
def tcp_client(self): """Simple tcp socket client emitting just one message""" with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect(TEST_SOCKET_ADDRESS) s.sendall(TEST_DICT_B64) LOG.info('Client sent data') data = get_packet_data(socket=s, sequentially=True) self.assertEqual(data, TEST_DICT_B64)
def test_03_get_packet_data(self): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind(TEST_SOCKET_ADDRESS) s.listen() threading.Thread(target=self.tcp_client).start() conn, addr = s.accept() with conn: LOG.info(f'Connected by {addr}') data = get_packet_data(conn, sequentially=False) self.assertEqual(data, TEST_DICT_B64) conn.sendall(data)
def on_gui_client_connected(self, message): # GUI has announced presence LOG.info('GUI HAS ANNOUNCED!') port = self.global_config["gui_websocket"]["base_port"] LOG.debug("on_gui_client_connected") gui_id = message.data.get("gui_id") LOG.debug("Heard announcement from gui_id: {}".format(gui_id)) # Announce connection, the GUI should connect on it soon self.bus.emit(Message("mycroft.gui.port", {"port": port, "gui_id": gui_id}))
def create_gui_service(enclosure, config): import tornado.options LOG.info('Starting message bus for GUI...') # Disable all tornado logging so mycroft loglevel isn't overridden tornado.options.parse_command_line(['--logging=None']) routes = [(config['route'], GUIWebsocketHandler)] application = web.Application(routes, debug=True) application.enclosure = enclosure application.listen(config['base_port'], config['host']) create_daemon(ioloop.IOLoop.instance().start) LOG.info('GUI Message bus started!') return application
def get_neon_auth_config(path: Optional[str] = None) -> NGIConfig: """ Returns a dict authentication configuration and handles populating values from key files Args: path: optional path to yml configuration files Returns: NGIConfig object with authentication config """ auth_config = NGIConfig("ngi_auth_vars", path) if not auth_config.content: LOG.info("Populating empty auth configuration") auth_config._content = build_new_auth_config(path) LOG.info(f"Loaded auth config from {auth_config.file_path}") return auth_config
def create(config=None, results_event: Event = None): if config and not config.get( "module" ): # No module, try getting stt config from passed config config = config.get("stt") if not config: # No config, go get it config = get_neon_speech_config().get("stt", {}) LOG.info(f"Create STT with config: {config}") clazz = OVOSSTTFactory.get_class(config) if not clazz: LOG.warning("plugin not found, falling back to Chromium STT") config["module"] = "google" # TODO configurable fallback plugin clazz = OVOSSTTFactory.get_class(config) if not clazz: raise ValueError("fallback plugin not found") return WrappedSTT(clazz, config=config, results_event=results_event)
def get_neon_user_config(path: Optional[str] = None) -> NGIConfig: """ Returns a dict user configuration and handles any migration of configuration values to local config from user config Args: path: optional path to yml configuration files Returns: NGIConfig object with user config """ user_config = NGIConfig("ngi_user_info", path) default_user_config = NGIConfig("default_user_conf", os.path.join(os.path.dirname(__file__), "default_configurations")) if len(user_config.content) == 0: LOG.info("Created Empty User Config!") user_config.populate(default_user_config.content) local_config = NGIConfig("ngi_local_conf", path) _move_config_sections(user_config, local_config) user_config.make_equal_by_keys(default_user_config.content) LOG.info(f"Loaded user config from {user_config.file_path}") return user_config
def get_neon_local_config(path: Optional[str] = None) -> NGIConfig: """ Returns a dict local configuration and handles any migration of configuration values to local config from user config Args: path: optional path to yml configuration files Returns: NGIConfig object with local config """ local_config = NGIConfig("ngi_local_conf", path) default_local_config = NGIConfig("default_core_conf", os.path.join(os.path.dirname(__file__), "default_configurations")) if len(local_config.content) == 0: LOG.info(f"Created Empty Local Config at {local_config.path}") local_config.populate(default_local_config.content) # TODO: Update from Mycroft config DM user_config = NGIConfig("ngi_user_info", path) _move_config_sections(user_config, local_config) local_config.make_equal_by_keys(default_local_config.content) LOG.info(f"Loaded local config from {local_config.file_path}") return local_config
def on_message(self, message): LOG.info("Received: {}".format(message)) msg = json.loads(message) if (msg.get('type') == "mycroft.events.triggered" and (msg.get('event_name') == 'page_gained_focus' or msg.get('event_name') == 'system.gui.user.interaction')): # System event, a page was changed msg_type = 'gui.page_interaction' msg_data = {'namespace': msg['namespace'], 'page_number': msg['parameters'].get('number'), 'skill_id': msg['parameters'].get('skillId')} elif msg.get('type') == "mycroft.events.triggered": # A normal event was triggered msg_type = '{}.{}'.format(msg['namespace'], msg['event_name']) msg_data = msg['parameters'] elif msg.get('type') == 'mycroft.session.set': # A value was changed send it back to the skill msg_type = '{}.{}'.format(msg['namespace'], 'set') msg_data = msg['data'] message = Message(msg_type, msg_data) LOG.info('Forwarding to bus...') self.application.enclosure.bus.emit(message) LOG.info('Done!')
def __setitem__(self, key, value): LOG.info(f"Config changes pending write to disk!") self._pending_write = True self._content[key] = value
def on_close(self): LOG.info('Closing {}'.format(id(self))) GUIWebsocketHandler.clients.remove(self)
def open(self): GUIWebsocketHandler.clients.append(self) LOG.info('New Connection opened!') self.synchronize()