Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fabric demo
"""Fabric demo.
Setup Instructions:
pip install Fabric3
How to use:
fab --list
fab hello
fab provision
fab venv
fab wc:filename=fabfile.py
"""
from fabric.api import task, run, sudo, cd, env, get, put
import os
env.hosts = ["pipal.in"]
@task
def hello():
"""Prints hello world message.
"""
run("w > /tmp/w.txt")
getf
@task
def wc(filename):
put(filename, "/tmp")
run("wc /tmp/{} > /tmp/wc.txt".format(os.path.basename(filename)))
get("/tmp/wc.txt", "wc.txt")
print(open("wc.txt").read())
@task
def venv():
sudo("mkdir -p /usr/local/vikrant")
sudo("virtualenv /usr/local/vikrant/venv")
with cd("/usr/local/vikrant/venv"):
sudo("./bin/pip install Django")
APT_PACKAGES = [
"python-virtualenv"
]
@task
def provision():
sudo("apt-get update")
sudo("apt-get install -y " + " ".join(APT_PACKAGES))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.