From 6a8b8d76b9c1e47fc861f57d049c56a489678930 Mon Sep 17 00:00:00 2001 From: Lubomir Bucek <lubomir.bucek@eox.at> Date: Tue, 22 Sep 2020 20:33:57 +0200 Subject: [PATCH] allow regex in output glob case insensitive .tif --- preprocessor/preprocessor/steps/output.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/preprocessor/preprocessor/steps/output.py b/preprocessor/preprocessor/steps/output.py index 5d093c6f..34627278 100644 --- a/preprocessor/preprocessor/steps/output.py +++ b/preprocessor/preprocessor/steps/output.py @@ -1,9 +1,13 @@ import os from os.path import join, basename -from glob import glob from uuid import uuid4 +from fnmatch import translate +import re from ..util import replace_ext, gdal +import logging + +logger = logging.getLogger(__name__) def output_step(source_dir: os.PathLike, target_dir: os.PathLike, options: dict=None): @@ -15,8 +19,9 @@ def output_step(source_dir: os.PathLike, target_dir: os.PathLike, options: dict= raise ValueError('Unsupported driver %s' % frmt) extension = driver.GetMetadata().get('DMD_EXTENSIONS', 'tif').split(' ')[0] # warp each individual file + match = re.compile(translate('*.tif'), re.IGNORECASE).match warped_files = [] - for filename in glob(join(source_dir, '*.tif')): + for filename in [join(source_dir, fnm) for fnm in os.listdir(source_dir) if match(fnm)]: target_filename = join(target_dir, replace_ext(basename(filename), extension)) gdal.Warp(target_filename, filename, options=gdal.WarpOptions( **options -- GitLab