Exemple #1
0
    def _get_target_folder(resources, module_type):
        """
        Return the folder from the resources and given a module type
        :param resources: Resource object
        :type resources: Resources
        :param module_type: type of the module (TYPE_NEURON, TYPE_STT, TYPE_TTS, TYPE_TRIGGER, TYPE_SIGNAL)
        :return: path of the folder
        """
        module_type_converter = dict()
        # dict to get the path behind a type of resource
        try:
            module_type_converter = {
                TYPE_NEURON: resources.neuron_folder,
                TYPE_STT: resources.stt_folder,
                TYPE_TTS: resources.tts_folder,
                TYPE_TRIGGER: resources.trigger_folder,
                TYPE_SIGNAL: resources.signal_folder
            }
        except AttributeError:
            # will be raised if the resource folder is not set in settings
            pass
        # Let's find the right path depending of the type
        try:
            folder_path = module_type_converter[module_type]
        except KeyError:
            folder_path = None
        # No folder_path has been found
        message = "No %s folder set in settings." % module_type
        if folder_path is None:
            logger.debug(message)
            Utils.print_danger(message)

        return folder_path
Exemple #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.intelora_version,
                            supported_versions=self.dna.
                            intelora_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
                                if self.run_ansible_playbook_module(
                                        install_file_path=self.
                                        install_file_path):
                                    Utils.print_success(
                                        "Module: %s installed" % module_name)
                                else:
                                    Utils.print_danger(
                                        "Module: %s not installed" %
                                        module_name)
                else:
                    logger.debug(
                        "[ResourcesManager] installation cancelled, deleting temp repo %s"
                        % str(self.tmp_path))
                    shutil.rmtree(self.tmp_path)
Exemple #3
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
Exemple #4
0
    def is_settings_ok(resources, dna):
        """
        Test if required settings files in config of Intelora are ok.
        The resource object must not be empty
        Check id the use have set the an installation path in his settings for the target module type
        :param resources: the Resources model
        :param dna: DNA info about the module to install
        :return:
        """
        settings_ok = True
        if resources is None:
            message = "Resources folder not set in settings, cannot install."
            logger.debug(message)
            Utils.print_danger(message)
            settings_ok = False
        else:
            if dna.module_type == "neuron" and resources.neuron_folder is None:
                message = "Resources folder for neuron installation not set in settings, cannot install."
                logger.debug(message)
                Utils.print_danger(message)
                settings_ok = False
            if dna.module_type == "stt" and resources.stt_folder is None:
                message = "Resources folder for stt installation not set in settings, cannot install."
                logger.debug(message)
                Utils.print_danger(message)
                settings_ok = False
            if dna.module_type == "tts" and resources.tts_folder is None:
                message = "Resources folder for tts installation not set in settings, cannot install."
                logger.debug(message)
                Utils.print_danger(message)
                settings_ok = False
            if dna.module_type == "trigger" and resources.trigger_folder is None:
                message = "Resources folder for trigger installation not set in settings, cannot install."
                logger.debug(message)
                Utils.print_danger(message)
                settings_ok = False
            if dna.module_type == "signal" and resources.signal_folder is None:
                message = "Resources folder for signal installation not set in settings, cannot install."
                logger.debug(message)
                Utils.print_danger(message)
                settings_ok = False

        return settings_ok