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))
예제 #2
0
    def install(self):
        """
        Module installation method.
        """
        # first, we clone the repo
        self._clone_repo(path=self.tmp_path, git_url=self.git_url)

        # check the content of the cloned repo
        if self.is_repo_ok(dna_file_path=self.dna_file_path,
                           install_file_path=self.install_file_path):

            # Load the dna.yml file
            self.dna = DnaLoader(self.dna_file_path).get_dna()
            if self.dna is not None:
                logger.debug("[ResourcesManager] DNA file content: " +
                             str(self.dna))
                if self.is_settings_ok(resources=self.settings.resources,
                                       dna=self.dna):
                    # the dna file is ok, check the supported version
                    if self._check_supported_version(
                            current_version=self.settings.kalliope_version,
                            supported_versions=self.dna.
                            kalliope_supported_version):

                        # Let's find the target folder depending the type
                        module_type = self.dna.module_type.lower()
                        target_folder = self._get_target_folder(
                            resources=self.settings.resources,
                            module_type=module_type)
                        if target_folder is not None:
                            # let's move the tmp folder in the right folder and get a new path for the module
                            module_name = self.dna.name.lower()
                            target_path = self._rename_temp_folder(
                                name=self.dna.name.lower(),
                                target_folder=target_folder,
                                tmp_path=self.tmp_path)

                            # if the target_path exists, then run the install file within the new repository
                            if target_path is not None:
                                self.install_file_path = target_path + os.sep + INSTALL_FILE_NAME
                                self.run_ansible_playbook_module(
                                    install_file_path=self.install_file_path)
                                Utils.print_success("Module: %s installed" %
                                                    module_name)
                else:
                    logger.debug(
                        "[ResourcesManager] installation cancelled, deleting temp repo %s"
                        % str(self.tmp_path))
                    shutil.rmtree(self.tmp_path)
예제 #3
0
    def _get_matching_synapse_list(cls, all_synapses_list, order_to_match):
        """
        Class method to return all the matching synapses with the order from the complete of synapses.

        :param all_synapses_list: the complete list of all synapses
        :param order_to_match: the order to match
        :type order_to_match: str
        :return: the list of matching synapses
        """
        matching_synapses_list = list()
        for synapse in all_synapses_list:
            for signal in synapse.signals:
                if type(signal) == Order:
                    if cls._spelt_order_match_brain_order_via_table(
                            signal.sentence, order_to_match):
                        matching_synapses_list.append(synapse)
                        logger.debug("Order found! Run neurons: %s" %
                                     synapse.neurons)
                        Utils.print_success(
                            "Order matched in the brain. Running synapse \"%s\""
                            % synapse.name)
        return matching_synapses_list
예제 #4
0
    def install(self, force=False):
        """
        Module installation method.
        :arg force: True to skip the version compatibility
        :return Dna object if resource installed
        """
        # first, we clone the repo
        self._clone_repo(path=self.tmp_path, git_url=self.git_url)

        # check the content of the cloned repo
        if not self.is_repo_ok(dna_file_path=self.dna_file_path,
                               install_file_path=self.install_file_path):
            logger.debug("[ResourcesManager] Invalid resource repository")
            self.cleanup_after_failed_installation()
            raise ResourcesManagerException("Invalid resource repository")

        # Load the dna.yml file
        self.dna = DnaLoader(self.dna_file_path).get_dna()
        if self.dna is None:
            logger.debug(
                "[ResourcesManager] No DNA file found in the resource to install"
            )
            self.cleanup_after_failed_installation()
            raise ResourcesManagerException(
                "No DNA file found in the resource to install")

        logger.debug("[ResourcesManager] DNA file content: " + str(self.dna))
        if not self.is_settings_ok(resources=self.settings.resources,
                                   dna=self.dna):
            logger.debug("[ResourcesManager] Invalid settings")
            self.cleanup_after_failed_installation()
            raise ResourcesManagerException("Invalid settings")

        # the dna file is ok, check the supported version
        if not force:
            if not self._check_supported_version(
                    current_version=self.settings.kalliope_version,
                    supported_versions=self.dna.kalliope_supported_version):
                logger.debug("[ResourcesManager] Non supported version")
                self.cleanup_after_failed_installation()
                raise ResourcesManagerException("Non supported version")

        # Let's find the target folder depending the type
        module_type = self.dna.module_type.lower()
        target_folder = self._get_target_folder(
            resources=self.settings.resources, module_type=module_type)
        if target_folder is None:
            self.cleanup_after_failed_installation()
            raise ResourcesManagerException(
                "No resource folder set in settings")

        # let's move the tmp folder in the right folder and get a new path for the module
        module_name = self.dna.name.lower()
        target_path = self._rename_temp_folder(name=self.dna.name.lower(),
                                               target_folder=target_folder,
                                               tmp_path=self.tmp_path)

        # if the target_path exists, then run the install file within the new repository
        if target_path is None:
            raise ResourcesManagerException("Resource already present")
        else:
            self.install_file_path = target_path + os.sep + INSTALL_FILE_NAME
            if self.run_ansible_playbook_module(
                    install_file_path=self.install_file_path):
                Utils.print_success("Module: %s installed" % module_name)
                return self.dna
            else:
                Utils.print_danger("Module: %s not installed" % module_name)
                return None