Ejemplo n.º 1
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.º 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
    def uninstall(self, neuron_name=None, tts_name=None, stt_name=None, trigger_name=None):
        """
        Uninstall a community resource
        """
        target_path_to_delete = None
        module_name = ""
        if neuron_name is not None:
            target_path_to_delete = self._get_target_folder(resources=self.settings.resources,
                                                            module_type="neuron")
            module_name = neuron_name
        if tts_name is not None:
            target_path_to_delete = self._get_target_folder(resources=self.settings.resources,
                                                            module_type="neuron")
            module_name = tts_name
        if stt_name is not None:
            target_path_to_delete = self._get_target_folder(resources=self.settings.resources,
                                                            module_type="neuron")
            module_name = stt_name
        if trigger_name is not None:
            target_path_to_delete = self._get_target_folder(resources=self.settings.resources,
                                                            module_type="neuron")
            module_name = trigger_name

        if target_path_to_delete is not None:
            try:
                shutil.rmtree(target_path_to_delete + os.sep + module_name.lower())
                Utils.print_success("Module %s deleted" % module_name.lower())
            except shutil.Error:
                Utils.print_warning("The module %s doest not exist in the path %s" % (module_name.lower(), target_path_to_delete))
            except OSError:
                Utils.print_warning(
                    "The module %s doest not exist in the path %s" % (module_name.lower(), target_path_to_delete))
Ejemplo n.º 4
0
 def _rename_temp_folder(name, target_folder, tmp_path):
     """
     Rename the temp folder of the cloned repo
     Return the name of the path to install
     :return: path to install, None if already exists
     """
     logger.debug("[ResourcesManager] Rename temp folder")
     new_absolute_neuron_path = target_folder + os.sep + name
     try:
         os.rename(tmp_path, new_absolute_neuron_path)
         return new_absolute_neuron_path
     except OSError:
         # the folder already exist
         Utils.print_warning("The module %s already exist in the path %s" % (name, target_folder))
         # remove the cloned repo
         logger.debug("[ResourcesManager] Deleting temp folder %s" % str(tmp_path))
         shutil.rmtree(tmp_path)