def setup(snipsfile_path=None): pp.pcommand("Setting up Snips Manager as a Systemd service") snipsfile_path = snipsfile_path or DEFAULT_SNIPSFILE_PATH working_directory = os.path.dirname(snipsfile_path) if not is_raspi_os(): raise SystemdSnipsManagerException( "Snips Systemd configuration is only available on Raspberry Pi. Skipping Systemd setup" ) snipsmanager_path = which('snipsmanager') if snipsmanager_path is None: raise SystemdSnipsManagerException( "Error: cannot find command 'snipsmanager' on the system. Make sure the Snips Manager CLI is correctly installed. Skipping Systemd setup" ) contents = Systemd.get_template( SystemdSnipsManager.SNIPSMANAGER_SERVICE_NAME) contents = contents.replace("{{SNIPSMANAGER_COMMAND}}", snipsmanager_path) contents = contents.replace("{{WORKING_DIRECTORY}}", working_directory) Systemd.write_systemd_file( SystemdSnipsManager.SNIPSMANAGER_SERVICE_NAME, None, contents) Systemd.enable_service(None, SystemdSnipsManager.SNIPSMANAGER_SERVICE_NAME) pp.psuccess("Successfully set up Snips Manager as a Systemd service")
def print_done(num_installed, silent=False): if not silent: if num_installed == 1: pp.psuccess("Successfully installed 1 skill") else: pp.psuccess( "Successfully installed {} skills".format(num_installed))
def load(file_path=None, generate_classes=True): pp.pcommand("Loading assistant") if file_path is None: file_path = AssistantFetcher.SNIPS_TEMP_ASSISTANT_PATH message = pp.ConsoleMessage("Loading assistant from file {}".format(file_path)) message.start() if file_path is not None and not file_exists(file_path): message.error() raise AssistantLoaderException("Error loading assistant: file {} not found".format(file_path)) if is_raspi_os(): if not Snips.is_installed(): message.error() raise AssistantLoaderException("Error: loading an assistant requires the Snips platform to be installed. Please run 'curl https://install.snips.ai -sSf | sh' to install the Snips Platform") Snips.load_assistant(file_path) message.done() if generate_classes: AssistantLoader.generate_intent_classes(file_path) pp.psuccess("Assistant has been successfully loaded")
def setup_from_params(mqtt_hostname="localhost", mqtt_port=1883): pp.pcommand("Setting up Bluetooth as a Systemd service") if not is_raspi_os(): raise SystemdBluetoothException( "Bluetooth Systemd configuration is only available on Raspberry Pi. Skipping Systemd setup" ) if not is_node_available(): raise SystemdBluetoothException( "Error: Bluetooth module must be installed. Run 'snipsmanager install bluetooth' to setup Bluetooth" ) contents = Systemd.get_template(SystemdBluetooth.SNIPSBLE_SERVICE_NAME) if contents is None: return node_bin_path = which('node') command = SystemdBluetooth.SNIPSBLE_SCRIPT.format( node_bin_path=node_bin_path, node_module_path=NODE_MODULES_DIR, module_name=SystemdBluetooth.SNIPSBLE_MODULE_NAME, serviceUUID=SystemdBluetooth.SNIPSBLE_SERVICE_UUID, characteristicUUID=SystemdBluetooth.SNIPSBLE_CHARACTERISTIC_UUID, mqtt_hostname=mqtt_hostname, mqtt_port=mqtt_port) contents = contents.replace("{{SNIPSBLE_COMMAND}}", command) Systemd.write_systemd_file(SystemdBluetooth.SNIPSBLE_SERVICE_NAME, None, contents) Systemd.enable_service(None, SystemdBluetooth.SNIPSBLE_SERVICE_NAME) pp.psuccess("Successfully set up Bluetooth as a Systemd service")
def install(force_download=False): pp.pcommand("Setting up Bluetooth") if not is_raspi_os(): raise BluetoothInstallerException("Error: Bluetooth is only available on Raspberry Pi") if not is_node_available(): BluetoothInstaller.install_node() if force_download or not BluetoothInstaller.is_snips_mqtt_relay_installed(): message = pp.ConsoleMessage("Installing Node module $GREEN{}$RESET".format(BluetoothInstaller.SNIPS_MQTT_RELAY_MODULE_NAME)) message.start() try: execute_command("sudo npm install --no-cache --prefix={} {}".format(NODE_MODULES_PARENT_DIR, BluetoothInstaller.SNIPS_MQTT_RELAY_MODULE_NAME), True) message.done() except: message.error() raise BluetoothInstallerException("Error: Error installing Bluetooth module {}. Please install it manually".format(BluetoothInstaller.SNIPS_MQTT_RELAY_MODULE_NAME)) pp.psuccess("Bluetooth is successfully installed")
def install_node(): pp.psubmessage("Node is not available. Installing node.", indent=True) message = pp.ConsoleMessage("Removing previous version of Node") message.start() try: execute_command("sudo apt-get -y remove nodejs nodejs-legacy npm") message.done() except: message.error() pass deb_file = "node_latest_armhf.deb" deb_url = "http://node-arm.herokuapp.com/node_latest_armhf.deb" message = pp.ConsoleMessage("Downloading Raspbian-compatible version of Node") message.start() try: download_file(deb_url, deb_file) message.done() except: message.error() raise BluetoothInstallerException("Error: failed to download compatible version of Node") message = pp.ConsoleMessage("Installing Node") message.start() try: execute_command("sudo dpkg -i {}".format(deb_file)) message.done() except: message.error() raise BluetoothInstallerException("Error: installing Node. Please install Node manually") try: remove_file(filename) except: pass pp.psuccess("Successfully installed Node")
def install_spotify_addon(params=None, interactive=True): pp.pcommand("Installing Spotify add-on") if params is None or len(params) == 0: if interactive: pp.psubmessage("You need to provide a Spotify token", indent=True) pp.psubmessage( "Please open \033[1m\033[4m{}\033[0m in a web browser and follow the instructions to obtain it" .format(AddonInstaller.SPOTIFY_LOGIN_URL), indent=True) token = ask_for_input("Spotify token:") else: pp.pwarning( "Spotify add-on not installed. Please provide the Spotify token as a parameter, or omit the `--non-interative` flag" ) return else: token = params[0] Addons.install("spotify", [token]) pp.psuccess("Spotify add-on installed")
def login(email=None, password=None, greeting=None, silent=False): has_credentials = email is not None and password is not None silent = silent or has_credentials if has_credentials: Logout.logout() token = Cache.get_login_token() if not token: if not has_credentials: pp.pcommand(greeting or "Please enter your Snips Console credentials") email = ask_for_input("Email address:") password = ask_for_password("Password:"******"You are now signed in") else: raise InvalidTokenException( "Could not validate authentication token") else: if not silent: pp.psuccess("You are already signed in") return token
def print_done(silent=False): if not silent: pp.psuccess("Microphone setup successfully complete")
def print_done(silent=False): if not silent: pp.psuccess("Speaker setup successfully complete")
def run(self): if Cache.get_login_token() is not None: Logout.logout() pp.psuccess("You are now signed out") else: pp.psuccess("You are already signed out")