Skip to content

Commit

Permalink
Addition of cancellation for multiple directories and globs. (#338)
Browse files Browse the repository at this point in the history
* Initial implementation of cancel glob.

* Tweaks to prompt user for cancel.
  • Loading branch information
Francesco Di Natale authored Feb 23, 2021
1 parent e68cfac commit 4d1035b
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions maestrowf/maestro.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,39 @@ def cancel_study(args):
# Force logging to Warning and above
LOG_UTIL.configure(LFORMAT, log_lvl=3)

if not os.path.isdir(args.directory):
print("Attempted to cancel a path that was not a directory.")
return 1
directory_list = args.directory

Conductor.mark_cancelled(args.directory)
ret_code = 0
to_cancel = []
if directory_list:
for directory in directory_list:
abs_path = os.path.abspath(directory)
if not os.path.isdir(abs_path):
print(
f"Attempted to cancel '{abs_path}' "
"-- study directory not found.")
ret_code = 1
else:
print(f"Study in '{abs_path}' to be cancelled.")
to_cancel.append(abs_path)

if to_cancel:
ok_cancel = input("Are you sure? [y|[n]]: ")
try:
if ok_cancel in ACCEPTED_INPUT:
for directory in to_cancel:
Conductor.mark_cancelled(directory)
except Exception as excpt:
print(f"Error:\n{excpt}")
print("Error in cancellation. Aborting.")
return -1
else:
print("Cancellation aborted.")
else:
print("Path(s) or glob(s) did not resolve to a directory(ies).")
ret_code = 1

return 0
return ret_code


def load_parameter_generator(path, env, kwargs):
Expand Down Expand Up @@ -341,7 +367,7 @@ def setup_argparser():
'cancel',
help="Cancel all running jobs.")
cancel.add_argument(
"directory", type=str,
"directory", type=str, nargs="+",
help="Directory containing a launched study.")
cancel.set_defaults(func=cancel_study)

Expand Down

0 comments on commit 4d1035b

Please sign in to comment.