Ejemplo n.º 1
0
 def wait_before_stop(self):
     logger.debug("[Ambient_sounds] Wait %s minutes before checking if the thread is alive" % self.auto_stop_minutes)
     Utils.print_info("[Ambient_sounds] Wait %s minutes before stopping the ambient sound" % self.auto_stop_minutes)
     sleep(self.auto_stop_minutes*60)  # *60 to convert received minutes into seconds
     logger.debug("[Ambient_sounds] Time is over, Stop player")
     Utils.print_info("[Ambient_sounds] Time is over, stopping the ambient sound")
     self.stop_last_process()
Ejemplo n.º 2
0
    def run_ansible_playbook_module(self, install_file_path):
        """
        Run the install.yml file through an Ansible playbook using the dedicated neuron !

        :param sudo_password: local machine sudo password required to install libraries
        :param install_file_path: the path of the Ansible playbook to run.
        :return:
        """
        logger.debug("[ResourcesManager] Run ansible playbook")
        Utils.print_info("Starting neuron installation")
        # ask the sudo password
        if self.sudo_password is not None:
            pswd = self.sudo_password
        else:
            pswd = getpass.getpass('Sudo password:')
        if not pswd or pswd == "":
            Utils.print_warning("You must enter a sudo password")
            return False
        else:
            ansible_neuron_parameters = {
                "task_file": install_file_path,
                "sudo": True,
                "sudo_user": "******",
                "sudo_password": pswd
            }
            neuron = Neuron(name="ansible_playbook",
                            parameters=ansible_neuron_parameters)
            NeuronLauncher.start_neuron(neuron)
            return True
Ejemplo n.º 3
0
    def _check_supported_version(current_version, supported_versions):
        """
        The dna file contains supported Kalliope version for the module to install.
        Check if supported versions are match the current installed version. If not, ask the user to confirm the
        installation anyway
        :param current_version: current version installed of Kalliope. E.g 0.4.0
        :param supported_versions: list of supported version
        :return: True if the version is supported or user has confirmed the installation
        """
        logger.debug("[ResourcesManager] Current installed version of Kalliope: %s" % str(current_version))
        logger.debug("[ResourcesManager] Module supported version: %s" % str(supported_versions))

        supported_version_found = False
        for supported_version in supported_versions:
            if version.parse(current_version) == version.parse(supported_version):
                # we found the exact version
                supported_version_found = True
                break

        if not supported_version_found:
            # we ask the user if we want to install the module even if the version doesn't match
            Utils.print_info("Current installed version of Kalliope: %s" % current_version)
            Utils.print_info("Module supported versions: %s" % str(supported_versions))
            Utils.print_warning("The neuron seems to be not supported by your current version of Kalliope")
            supported_version_found = Utils.query_yes_no("install it anyway?")
            logger.debug("[ResourcesManager] install it anyway user answer: %s" % supported_version_found)

        logger.debug("[ResourcesManager] check_supported_version: %s" % str(supported_version_found))
        return supported_version_found
Ejemplo n.º 4
0
def signal_handler(signal, frame):
    """
    Used to catch a keyboard signal like Ctrl+C in order to kill the kalliope program
    :param signal: signal handler
    :param frame: execution frame
    """
    print "\n"
    Utils.print_info("Ctrl+C pressed. Killing Kalliope")
    sys.exit(0)
Ejemplo n.º 5
0
 def _clone_repo(path, git_url):
     """
     Use git to clone locally the neuron in a temp folder
     :return:
     """
     # clone the repo
     logger.debug("[ResourcesManager] GIT clone into folder: %s" % path)
     Utils.print_info("Cloning repository...")
     # if the folder already exist we remove it
     if os.path.exists(path):
         shutil.rmtree(path)
     else:
         os.makedirs(path)
     Repo.clone_from(git_url, path)
Ejemplo n.º 6
0
 def set_mute_status(mute=False):
     """
     Define is the mute status
     :param mute: Boolean. If false, Kalliope is voice is stopped
     """
     logger.debug("[SettingEditor] mute. Switch trigger process to mute : %s" % mute)
     settings = SettingLoader().settings
     if mute:
         Utils.print_info("Kalliope now muted, voice has been stopped.")
         HookManager.on_mute()
     else:
         Utils.print_info("Kalliope now speaking.")
         HookManager.on_unmute()
     settings.options.mute = mute
Ejemplo n.º 7
0
 def set_mute_status(mute=False):
     """
     Define is the mute status
     :param mute: Boolean. If false, Kalliope is voice is stopped
     """
     logger.debug(
         "[SettingEditor] mute. Switch trigger process to mute : %s" % mute)
     settings = SettingLoader().settings
     if mute:
         Utils.print_info("Kalliope now muted, voice has been stopped.")
         HookManager.on_mute()
     else:
         Utils.print_info("Kalliope now speaking.")
         HookManager.on_unmute()
     settings.options.mute = mute
Ejemplo n.º 8
0
    def is_repo_ok(dna_file_path, install_file_path):
        """
        Check if the git cloned repo is fine to be installed
        :return: True if repo is ok to be installed, False otherwise
        """
        Utils.print_info("Checking repository...")
        repo_ok = True
        # check that a install.yml file is present
        if not os.path.exists(install_file_path):
            Utils.print_danger("Missing %s file" % INSTALL_FILE_NAME)
            repo_ok = False

        if not os.path.exists(dna_file_path):
            Utils.print_danger("Missing %s file" % DNA_FILE_NAME)
            repo_ok = False

        return repo_ok
Ejemplo n.º 9
0
 def set_deaf_status(trigger_instance, deaf=False):
     """
     Define is the trigger is listening or not.
     :param trigger_instance: the trigger instance coming from the order. It will be paused or unpaused.
     :param deaf: Boolean. If true, kalliope is trigger is paused
     """
     logger.debug("[MainController] deaf . Switch trigger process to deaf : %s" % deaf)
     settings = SettingLoader().settings
     if deaf:
         trigger_instance.pause()
         Utils.print_info("Kalliope now deaf, trigger has been paused")
         HookManager.on_deaf()
     else:
         trigger_instance.unpause()
         Utils.print_info("Kalliope now listening for trigger detection")
         HookManager.on_undeaf()
     settings.options.deaf = deaf
Ejemplo n.º 10
0
 def set_deaf_status(trigger_instance, deaf=False):
     """
     Define is the trigger is listening or not.
     :param trigger_instance: the trigger instance coming from the order. It will be paused or unpaused.
     :param deaf: Boolean. If true, kalliope is trigger is paused
     """
     logger.debug(
         "[MainController] deaf . Switch trigger process to deaf : %s" %
         deaf)
     settings = SettingLoader().settings
     if deaf:
         trigger_instance.pause()
         Utils.print_info("Kalliope now deaf, trigger has been paused")
         HookManager.on_deaf()
     else:
         trigger_instance.unpause()
         Utils.print_info("Kalliope now listening for trigger detection")
         HookManager.on_undeaf()
     settings.options.deaf = deaf
Ejemplo n.º 11
0
    def run_ansible_playbook_module(install_file_path):
        """
        Run the install.yml file through an Ansible playbook using the dedicated neuron !

        :param install_file_path: the path of the Ansible playbook to run.
        :return:
        """
        logger.debug("[ResourcesManager] Run ansible playbook")
        Utils.print_info("Starting neuron installation")
        # ask the sudo password
        pswd = getpass.getpass('Sudo password:')
        ansible_neuron_parameters = {
            "task_file": install_file_path,
            "sudo": True,
            "sudo_user": "******",
            "sudo_password": pswd
        }
        neuron = Neuron(name="ansible_playbook", parameters=ansible_neuron_parameters)
        NeuronLauncher.start_neuron(neuron)
Ejemplo n.º 12
0
    def start(self):
        """
        This method matches the incoming messages to the signals/order sentences provided in the Brain
        """

        # create a dict of synapses that have been launched
        launched_synapses = self._get_matching_synapse_list(
            self.brain.synapses, self.order)

        if not launched_synapses:
            Utils.print_info("No synapse match the captured order: %s" %
                             self.order)
        else:
            for synapse in launched_synapses:
                params = self._get_synapse_params(synapse, self.order)
                for neuron in synapse.neurons:
                    self._start_neuron(neuron, params)

        # return the list of launched synapse
        return launched_synapses