Beispiel #1
0
    def validate_base(self, ignore_no_files=False):
        """
        Validates the configuration and the input files
        :param bool ignore_no_files: if the extending recipe does not work with files, set this to true to skip
        the validation check for no files (used in wcs_extract recipe).
        """
        if self.session.get_wcs_service(
        ) is None or self.session.get_wcs_service() == "":
            raise RecipeValidationException("No valid wcs endpoint provided")
        if self.session.get_crs_resolver(
        ) is None or self.session.get_crs_resolver() == "":
            raise RecipeValidationException("No valid crs resolver provided")
        if self.session.get_coverage_id(
        ) is None or self.session.get_coverage_id() == "":
            raise RecipeValidationException("No valid coverage id provided")
        if not FileUtil.check_dir_writable(ConfigManager.tmp_directory):
            raise RecipeValidationException(
                "Cannot write to tmp directory '{}'".format(
                    ConfigManager.tmp_directory))

        checked_files = []

        for file in self.session.get_files():
            if FileUtil.validate_file_path(file.get_filepath()):
                checked_files.append(file)

        if not ignore_no_files:
            # If no input file is available, exit wcst_import.
            FileUtil.validate_input_file_paths(checked_files)

        self.session.files = checked_files

        if 'wms_import' not in self.options:
            self.options['wms_import'] = False
        else:
            self.options['wms_import'] = bool(self.options['wms_import'])

        if 'tiling' not in self.options:
            self.options['tiling'] = None

        if 'scale_levels' not in self.options:
            self.options['scale_levels'] = None

        if "import_order" in self.options:
            if self.options['import_order'] != AbstractToCoverageConverter.IMPORT_ORDER_ASCENDING \
                    and self.options['import_order'] != AbstractToCoverageConverter.IMPORT_ORDER_DESCENDING:
                error_message = "'import_order' option must be '{}' or '{}', given '{}'.".\
                                  format(AbstractToCoverageConverter.IMPORT_ORDER_ASCENDING,
                                         AbstractToCoverageConverter.IMPORT_ORDER_DESCENDING,
                                         self.options['import_order'])
                raise RecipeValidationException(error_message)
        else:
            self.options['import_order'] = None
Beispiel #2
0
    def open_gdal_dataset_from_any_file(files):
        """
        This method is used to open 1 dataset to get the common metadata shared from all input files.
        :param list files: input files
        """
        gdal_dataset = None

        for file in files:
            try:
                gdal_dataset = GDALGmlUtil(file.get_filepath())
                return gdal_dataset
            except Exception as ex:
                # Cannot open file by gdal, try with next file
                if ConfigManager.skip:
                    continue
                else:
                    raise

        if gdal_dataset is None:
            # Cannot open any dataset from input files, just exit wcst_import process
            FileUtil.validate_input_file_paths([])
Beispiel #3
0
    def get_valid_files(self):
        """
            Valid file path could be opened by GDAL
            files is list of files need to valid
        """
        # Validate input files by GDAL. If GDAL could not decode file then will have an warning.
        # GDAL needs file name encode in 'utf8' or file name with spaces could not open.
        file_paths = []

        for file in self.files:
            fileName = str(file).encode('utf8')
            try:
                check = gdal.Open(fileName)
                file_paths = file_paths + [file]
            except Exception as e:
                log.warn(
                    "WARNING: File " + fileName +
                    " is not is not a valid GDAL decodable file. Reason: " +
                    str(e) + ". The import process will ignore this file.\n")

        FileUtil.validate_input_file_paths(file_paths)

        return file_paths
Beispiel #4
0
    def validate_base(self, ignore_no_files=False):
        """
        Validates the configuration and the input files
        :param bool ignore_no_files: if the extending recipe does not work with files, set this to true to skip
        the validation check for no files (used in wcs_extract recipe).
        """
        if self.session.get_wcs_service(
        ) is None or self.session.get_wcs_service() == "":
            raise RecipeValidationException("No valid wcs endpoint provided")
        if self.session.get_crs_resolver(
        ) is None or self.session.get_crs_resolver() == "":
            raise RecipeValidationException("No valid crs resolver provided")
        if self.session.get_coverage_id(
        ) is None or self.session.get_coverage_id() == "":
            raise RecipeValidationException("No valid coverage id provided")

        import recipes.virtual_coverage.recipe as super_coverage
        if self.session.get_recipe_name() == super_coverage.Recipe.RECIPE_NAME:
            # NOTE: virtual_coverage recipe does not require any input files
            return

        if not FileUtil.check_dir_writable(ConfigManager.tmp_directory):
            raise RecipeValidationException(
                "Cannot write to tmp directory '{}'".format(
                    ConfigManager.tmp_directory))

        checked_files = []

        for file in self.session.get_files():
            if FileUtil.validate_file_path(file.get_filepath()):
                checked_files.append(file)

        if not ignore_no_files:
            # If no input file is available, exit wcst_import.
            FileUtil.validate_input_file_paths(checked_files)

        self.session.files = checked_files

        if 'wms_import' not in self.options:
            self.options['wms_import'] = False
        else:
            self.options['wms_import'] = bool(self.options['wms_import'])

        if 'tiling' not in self.options:
            self.options['tiling'] = None

        if 'scale_levels' not in self.options:
            self.options['scale_levels'] = None

        if 'scale_factors' not in self.options:
            self.options['scale_factors'] = None

        if self.options['scale_levels'] is not None \
           and self.options['scale_factors'] is not None:
            raise RecipeValidationException(
                "Only one of 'scale_levels' or 'scale_factors' "
                "setting can exist in the ingredients file.")
        if self.options['scale_factors'] is not None:
            # as scale_factors and scale_levels are only valid when initializing a new coverage
            cov = CoverageUtil(self.session.get_coverage_id())
            if not cov.exists():
                for obj in self.options['scale_factors']:
                    if 'coverage_id' not in obj or 'factors' not in obj:
                        raise RecipeValidationException(
                            "All elements of 'scale_factors' list must contain "
                            "'coverage_id' and 'factors' properties")
                    coverage_id = obj['coverage_id']
                    cov = CoverageUtil(coverage_id)
                    if cov.exists():
                        raise RecipeValidationException(
                            "Downscaled level coverage '" + coverage_id +
                            "' already exists, "
                            "please use a different 'coverage_id' in 'scale_factors' list"
                        )

        self.validate_pyramid_members()
        self.validate_pyramid_bases()

        if "import_order" in self.options:
            if self.options['import_order'] != AbstractToCoverageConverter.IMPORT_ORDER_ASCENDING \
                    and self.options['import_order'] != AbstractToCoverageConverter.IMPORT_ORDER_DESCENDING:
                error_message = "'import_order' option must be '{}' or '{}', given '{}'.".\
                                  format(AbstractToCoverageConverter.IMPORT_ORDER_ASCENDING,
                                         AbstractToCoverageConverter.IMPORT_ORDER_DESCENDING,
                                         self.options['import_order'])
                raise RecipeValidationException(error_message)
        else:
            self.options['import_order'] = None