Skip to content

Commit

Permalink
Add actions done_if and skip_if #1132
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo Peng committed Jan 15, 2019
1 parent 278c4ff commit 6eeb1ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ def run(self):
fail_if = sos.actions:fail_if
warn_if = sos.actions:warn_if
stop_if = sos.actions:stop_if
done_if = sos.actions:done_if
skip_if = sos.actions:skip_if
download = sos.actions:download
run = sos.actions:run
Expand Down
16 changes: 16 additions & 0 deletions src/sos/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,22 @@ def stop_if(expr, msg='', no_output=False):
raise StopInputGroup(msg=msg, keep_output=not no_output)
return 0

@SoS_Action(acceptable_args=['expr', 'msg'])
def done_if(expr, msg=''):
'''Assuming that output has already been generated and stop
executing the rest of the substep'''
if expr:
raise StopInputGroup(msg=msg, keep_output=True)
return 0

@SoS_Action(acceptable_args=['expr', 'msg', 'no_output'])
def skip_if(expr, msg=''):
'''Skip the current substep and set _output to empty. Output
will be removed if already generated.'''
if expr:
raise StopInputGroup(msg=msg, keep_output=False)
return 0

#
# download file with progress bar
#
Expand Down

0 comments on commit 6eeb1ff

Please sign in to comment.