From bd5be4eb111600c5d4f4624db92768f6573a965e Mon Sep 17 00:00:00 2001 From: Fabian Schindler <fabian.schindler.strauss@gmail.com> Date: Tue, 25 Aug 2020 17:31:50 +0200 Subject: [PATCH] Raising error when a file would be overridden --- preprocessor/preprocessor/steps/calc.py | 10 +++++----- preprocessor/preprocessor/steps/output.py | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/preprocessor/preprocessor/steps/calc.py b/preprocessor/preprocessor/steps/calc.py index ad27cdb6..a208a417 100644 --- a/preprocessor/preprocessor/steps/calc.py +++ b/preprocessor/preprocessor/steps/calc.py @@ -1,9 +1,5 @@ import os -from os.path import basename, dirname, join -from math import ceil, floor -import logging -import uuid -import os +from os.path import basename, dirname, join, isfile import subprocess from typing import List from glob import glob @@ -21,6 +17,10 @@ def calc_step(source_dir: os.PathLike, target_dir: os.PathLike, formulas: List[d target_dir, replace_ext(basename(filename), item.get('output_postfix', '_proc%d' % i) + '.tif', False) ) + # fail if a file would be overridden + # TODO: maybe just log an error + if isfile(target_filename): + raise Exception('Calc output filename %s already exists' % target_filename) calc_formula(source_dir, item['inputs'], target_filename, item['formula'], item.get('data_type', 'Float32')) diff --git a/preprocessor/preprocessor/steps/output.py b/preprocessor/preprocessor/steps/output.py index ac1bdd86..e7d99d27 100644 --- a/preprocessor/preprocessor/steps/output.py +++ b/preprocessor/preprocessor/steps/output.py @@ -19,7 +19,7 @@ def output_step(source_dir: os.PathLike, target_dir: os.PathLike, options: dict= # warp each individual file warped_files = [] - for filename in glob(join(source_dir, '*')): + for filename in glob(join(source_dir, '*.tif')): target_filename = join(target_dir, replace_ext(basename(filename), extension)) gdal.Warp(target_filename, filename, options=gdal.WarpOptions( **options -- GitLab