Skip to content

Commit e032a76

Browse files
mhidasmphemming
andauthored
Fix issue with moving temporary files (#178)
Fixing the temp file permission bug Fixes #167 (originally proposed in #176) Co-authored-by: mphemming <mphemming@live.co.uk>
1 parent 2b1f81e commit e032a76

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

aodntools/timeseries_products/aggregated_timeseries.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,9 @@ def main_aggregator(files_to_agg, var_to_agg, site_code, input_dir='', output_di
210210
rejected_files = []
211211

212212
# default name for temporary file. It will be renamed at the end
213-
_, temp_outfile = tempfile.mkstemp(suffix='.nc', dir=output_dir)
214-
213+
fd, temp_outfile = tempfile.mkstemp(suffix='.nc', dir=output_dir)
214+
os.close(fd)
215+
215216
## check files and get total number of flattened obs
216217
n_obs_total = 0
217218
for file in files_to_agg:

aodntools/timeseries_products/velocity_aggregated_timeseries.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def velocity_aggregated(files_to_agg, site_code, input_dir='', output_dir='./',
7171
bad_files = {}
7272

7373
# default name for temporary file. It will be renamed at the end
74-
_, temp_outfile = tempfile.mkstemp(suffix='.nc', dir=output_dir)
75-
74+
fd, temp_outfile = tempfile.mkstemp(suffix='.nc', dir=output_dir)
75+
os.close(fd)
7676
## check files and get total number of flattened obs
7777
n_obs_total = 0
7878
for file in files_to_agg:
@@ -237,6 +237,7 @@ def velocity_aggregated(files_to_agg, site_code, input_dir='', output_dir='./',
237237
("velocity-"+product_type),
238238
('END-'+ time_end_filename), 'C-' + current_utc_timestamp(DATESTAMP_FORMAT)]) + '.nc'
239239
ncout_path = os.path.join(output_dir, output_name)
240+
240241
shutil.move(temp_outfile, ncout_path)
241242

242243

aodntools/timeseries_products/velocity_hourly_timeseries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def velocity_hourly_aggregated(files_to_agg, site_code, input_dir='', output_dir
105105
chunk_size = 90 ## size in days
106106

107107
## default name for temporary file. It will be renamed at the end
108-
_, temp_outfile = tempfile.mkstemp(suffix='.nc', dir=output_dir)
109-
108+
fd, temp_outfile = tempfile.mkstemp(suffix='.nc', dir=output_dir)
109+
os.close(fd)
110110
## check files and get total number of flattened obs
111111
print("CHECKING FILES...")
112112
for index, file in enumerate(files_to_agg):

0 commit comments

Comments
 (0)