Example #1
0
    def is_duplicate_description(self):
        """Check if the integration has a non-duplicate description ."""
        is_description_in_yml = False
        is_description_in_package = False
        package_path = None
        md_file_path = None
        if not re.match(PACKS_INTEGRATION_YML_REGEX, self.file_path, re.IGNORECASE):
            package_path = os.path.dirname(self.file_path)
            try:
                path_without_extension = os.path.splitext(self.file_path)[0]
                md_file_path = glob.glob(path_without_extension + '_description.md')[0]
            except IndexError:
                error_message, error_code = Errors.no_description_file_warning()
                self.handle_error(error_message, error_code, file_path=self.file_path, warning=True)

            if md_file_path:
                is_description_in_package = True

        data_dictionary = get_yaml(self.file_path)

        if not data_dictionary:
            return is_description_in_package

        if data_dictionary.get('detaileddescription'):
            is_description_in_yml = True

        if is_description_in_package and is_description_in_yml:
            error_message, error_code = Errors.description_in_package_and_yml()
            if self.handle_error(error_message, error_code, file_path=package_path):
                self._is_valid = False
                return False

        return True
Example #2
0
    def is_duplicate_description(self):
        """Check if the integration has a non-duplicate description ."""
        is_description_in_yml = False
        is_description_in_package = False
        package_path = None
        md_file_path = None
        if not re.match(PACKS_INTEGRATION_YML_REGEX, self.file_path, re.IGNORECASE):
            package_path = os.path.dirname(self.file_path)
            try:
                md_file_path = glob.glob(os.path.join(os.path.dirname(self.file_path), '*_description.md'))[0]
            except IndexError:
                print_warning("No detailed description file was found in the package {}."
                              " Consider adding one.".format(package_path))
            if md_file_path:
                is_description_in_package = True

        data_dictionary = get_yaml(self.file_path)

        if not data_dictionary:
            return is_description_in_package

        if data_dictionary.get('detaileddescription'):
            is_description_in_yml = True

        if is_description_in_package and is_description_in_yml:
            error_message, error_code = Errors.description_in_package_and_yml()
            if self.handle_error(error_message, error_code, file_path=package_path):
                self._is_valid = False
                return False

        return True
Example #3
0
    def is_duplicate_description(self):
        """Check if the integration has a non-duplicate description ."""
        is_description_in_yml = False
        is_description_in_package = False
        package_path = None
        md_file_path = None

        if not re.match(PACKS_INTEGRATION_YML_REGEX, self.file_path, re.IGNORECASE):
            package_path = os.path.dirname(self.file_path)
            try:
                base_name_without_extension: str = os.path.basename(os.path.splitext(self.file_path)[0].replace(
                    '_description', ''))
                dir_name: str = os.path.dirname(self.file_path)
                expected_description_name: str = os.path.join(dir_name, f'{base_name_without_extension}_description.md')
                md_file_path = glob.glob(expected_description_name)[0]
            except IndexError:
                is_unified_integration = self.data_dictionary.get('script', {}).get('script', '') not in {'-', ''}
                if not (self.data_dictionary.get('deprecated') or is_unified_integration):
                    error_message, error_code = Errors.no_description_file_warning()
                    self.handle_error(error_message, error_code, file_path=self.file_path, warning=True)

            if md_file_path:
                is_description_in_package = True

        if not self.data_dictionary:
            return is_description_in_package

        if self.data_dictionary.get('detaileddescription'):
            is_description_in_yml = True

        if is_description_in_package and is_description_in_yml:
            error_message, error_code = Errors.description_in_package_and_yml()
            if self.handle_error(error_message, error_code, file_path=package_path):
                self._is_valid = False
                return False

        return True