Skip to content

Commit

Permalink
Github issue #331 part 2 of issue: remove the creation of a tmp subdi…
Browse files Browse the repository at this point in the history
…rectory that is the current process ID and remove existing tmp file before appending to it.

 This will prevent appending identical information (and headers) to the tmp file for a given storm, when re-running extract tiles with existing tc pairs output.  This will result in an error as it is assumed that the tmp file will only have one header.
  • Loading branch information
bikegeek committed Dec 5, 2019
1 parent 4649b63 commit 7bdfac9
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ush/extract_tiles_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ def run_at_time(self, input_dict):

# get the process id to be used to identify the output
# amongst different users and runs.
cur_pid = str(os.getpid())
tmp_dir = os.path.join(self.config.getdir('TMP_DIR'), cur_pid)
# cur_pid = str(os.getpid())
#tmp_dir = os.path.join(self.config.getdir('TMP_DIR'), cur_pid)
tmp_dir = self.config.getdir('TMP_DIR')
self.logger.info("Begin extract tiles")

cur_init = init_time[0:8]+"_"+init_time[8:10]
Expand Down Expand Up @@ -140,6 +141,13 @@ def run_at_time(self, input_dict):
full_tmp_filename = os.path.join(tmp_dir, tmp_filename)

storm_match_list = util.grep(cur_storm, filter_name)

# If this tmp file already exists in the tmp directory, remove
# it first otherwise we end up repeatedly appending the
# same information to this tmp file, which can have dire consequences.
if os.path.exists(full_tmp_filename):
os.remove(full_tmp_filename)

with open(full_tmp_filename, "a+") as tmp_file:
# copy over header information
tmp_file.write(header)
Expand All @@ -156,9 +164,10 @@ def run_at_time(self, input_dict):
# end of for cur_storm

# Remove any empty files and directories in the extract_tiles output
# directory
# directory and clean up any tmp files
util.prune_empty(self.filtered_out_dir, self.logger)


# Clean up the tmp directory if it exists
if os.path.isdir(tmp_dir):
util.rmtree(tmp_dir)
Expand Down

0 comments on commit 7bdfac9

Please sign in to comment.