From 8881f50ffb705a41f47fabda11f8463fbfe45232 Mon Sep 17 00:00:00 2001 From: Stephen McQuay Date: Thu, 24 Jan 2013 18:47:02 -0800 Subject: [PATCH] added example of context manager use --- context_managers.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 context_managers.py diff --git a/context_managers.py b/context_managers.py new file mode 100644 index 0000000..e64b0f8 --- /dev/null +++ b/context_managers.py @@ -0,0 +1,17 @@ +from fabric.api import env, run, cd, settings, local + +env.roledefs = { + 'web': ['web1', 'web2', 'web3'], + 'db': ['db1', 'db2'] +} + +def cd_example(): + with cd('/tmp'): + run('pwd') + + +def push_anyway(): + with settings(warn_only=True): + # simulate failure + local('false') + run('echo doing it anyway')