Fabric equivalent try it finally

In case Fabric fails or not, I need to perform a bunch of cleaning tasks (basically delete temporary files and folders ).

How can I achieve this with Fabric?

+5
source share
2 answers

Put something like this in your file:

from fabric.context_managers import settings

def task_name():
    # commands that are not expected to fail
    ...
    with settings(warn_only=True):
        # commands that might fail
        ...
    clean_up()

You might even want to give the whole treatment goal warn_only=Trueif you don't care:

@with_settings(warn_only=True)
def task_name():
    ...

( more details )

+5
source

You can always use the new execute () and wrap it in try / except or just look at the return codes from your run () s.

0
source

All Articles