Commit a8c30f9a authored by Colm Talbot's avatar Colm Talbot Committed by Moritz Huebner

Allow overwrite results

parent 205dadd4
......@@ -27,6 +27,8 @@ Changes currently on master, but not under a tag.
- PowerSpectralDensity structure modified
- Fixed bug in get_open_data
- .prior files are no longer created. The prior is stored in the result object.
- Users can now choose to overwrite existing result files, rather than creating
a .old file.
### Removed
- Removes the "--detectors" command line argument (not a general CLI requirement)
......
......@@ -167,15 +167,27 @@ class Result(dict):
item = [Result._standardise_a_string(i) for i in item]
return item
def save_to_file(self):
""" Writes the Result to a deepdish h5 file """
def save_to_file(self, overwrite=False):
"""
Writes the Result to a deepdish h5 file
Parameters
----------
overwrite: bool, optional
Whether or not to overwrite an existing result file.
default=False
"""
file_name = result_file_name(self.outdir, self.label)
utils.check_directory_exists_and_if_not_mkdir(self.outdir)
if os.path.isfile(file_name):
logger.debug(
'Renaming existing file {} to {}.old'.format(file_name,
file_name))
os.rename(file_name, file_name + '.old')
if overwrite:
logger.debug('Removing existing file {}'.format(file_name))
os.remove(file_name)
else:
logger.debug(
'Renaming existing file {} to {}.old'.format(file_name,
file_name))
os.rename(file_name, file_name + '.old')
logger.debug("Saving result to {}".format(file_name))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment