From 46431f36ff69f166e02413c1d6a5bd48f771817d Mon Sep 17 00:00:00 2001 From: Frank Steggink Date: Mon, 19 Feb 2024 16:05:30 +0100 Subject: [PATCH] Generate GFS name earlier and remove old file if it exists --- stetlcomponents/gfspreparationfilter.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/stetlcomponents/gfspreparationfilter.py b/stetlcomponents/gfspreparationfilter.py index 86ca9bdf..bfe10892 100644 --- a/stetlcomponents/gfspreparationfilter.py +++ b/stetlcomponents/gfspreparationfilter.py @@ -116,6 +116,16 @@ def invoke(self, packet): # TODO: consider using a Stetl chain for these steps + # Generate name of GFS file and remove an eventual old version + if self.output_gfs is not None: + gfs_path = self.output_gfs + else: + file_ext = os.path.splitext(input_gml) + gfs_path = file_ext[0] + '.gfs' + + if os.path.exists(gfs_path): + os.remove(gfs_path) + # Steps: # 1. Call ogrinfo and capture its output. log.info('calling ogrinfo') @@ -137,12 +147,6 @@ def invoke(self, packet): # 5. Save the output_gfs. log.info('writing output GFS') - if self.output_gfs is not None: - gfs_path = self.output_gfs - else: - file_ext = os.path.splitext(input_gml) - gfs_path = file_ext[0] + '.gfs' - with open(gfs_path, 'w') as f: f.write(result)