Created
March 27, 2015 04:27
-
-
Save mattvonrocketstein/6e6a13668c23f39c8379 to your computer and use it in GitHub Desktop.
self-hosting fabfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if __name__ == '__main__': | |
# a neat hack that makes this file a "self-hosting" fabfile, | |
# ie it is invoked directly but still gets all the fabric niceties | |
# like real option parsing, including --help and -l (for listing | |
# commands). note that as of fabric 1.10, the file for some reason | |
# needs to end in .py, despite what the documentation says. see: | |
# http://docs.fabfile.org/en/1.4.2/usage/fabfiles.html#fabfile-discovery | |
# | |
# the .index() manipulation below should make this work regardless of | |
# whether this is invoked from shell as "./foo.py" or "python foo.py" | |
from fabric.main import main as fmain | |
patched_argv = ['fab', '-f', __file__, ] + \ | |
sys.argv[sys.argv.index(__file__)+1:] | |
sys.argv = patched_argv | |
with warnings.catch_warnings(): | |
warnings.simplefilter("ignore") | |
fmain() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment