Commit 1cf9afcf authored by laochailan's avatar laochailan
Browse files

loadl merge: properly handle attempted overwrites

parent d72d756d
...@@ -68,13 +68,7 @@ def run(): ...@@ -68,13 +68,7 @@ def run():
print('Error: {}'.format(e)) print('Error: {}'.format(e))
sys.exit(1) sys.exit(1)
except jobfile.JobFileOverwriteError as e: except jobfile.JobFileOverwriteError as e:
diff_summary = '' print('Error: You changed the job parameters of an existing simulation.\nSummary of changes:\n{}\nThis can be no problem or data-breaking depending on the situation. Use \'--force\' to force overwriting the parameters or \'--restart\' to start a blank run.'.format(e.diff_summary()))
for taskname, taskdiff in e.difference.items():
diff_summary += '{}:\n'.format(taskname)
for param, diff in taskdiff.items():
diff_summary += ' {}: {} -> {}\n'.format(param, diff[1], diff[0])
print('Error: You changed the job parameters of an existing simulation.\nSummary of changes:\n{}\nThis can be no problem or data-breaking depending on the situation. Use \'--force\' to force overwriting the parameters or \'--restart\' to start a blank run.'.format(diff_summary))
sys.exit(1) sys.exit(1)
if args_run.single: if args_run.single:
cmd = '{} single "{}"'.format(job.jobconfig['mc_binary'], job_input_filename) cmd = '{} single "{}"'.format(job.jobconfig['mc_binary'], job_input_filename)
...@@ -96,7 +90,11 @@ def delete(): ...@@ -96,7 +90,11 @@ def delete():
os.unlink(results_file) os.unlink(results_file)
def merge(): def merge():
job_input_filename = job.write_job_input_file(force_overwrite=args_run.force) try:
job_input_filename = job.write_job_input_file(force_overwrite=False)
except (jobfile.JobFileGenError, jobfile.JobFileOverwriteError) as e:
print('Error: {}'.format(e))
sys.exit(1)
cmd = '{} merge "{}"'.format(job.jobconfig['mc_binary'], job_input_filename) cmd = '{} merge "{}"'.format(job.jobconfig['mc_binary'], job_input_filename)
print('$ '+cmd) print('$ '+cmd)
subprocess.run(cmd, shell=True) subprocess.run(cmd, shell=True)
......
...@@ -13,6 +13,15 @@ class JobFileGenError(Exception): ...@@ -13,6 +13,15 @@ class JobFileGenError(Exception):
class JobFileOverwriteError(Exception): class JobFileOverwriteError(Exception):
def __init__(self, difference): def __init__(self, difference):
self.difference = difference self.difference = difference
def diff_summary(self):
summary = []
for taskname, taskdiff in self.difference.items():
summary.append('{}:'.format(taskname))
for param, diff in taskdiff.items():
summary.append(' {}: {} -> {}'.format(param, diff[1], diff[0]))
return '\n'.join(summary)
def __str__(self):
return 'Tried to overwrite existing job data with different parameters.\n{}'.format(self.diff_summary())
class JobFile: class JobFile:
def __init__(self, filename): def __init__(self, filename):
......
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