def virtualenv():
"""Activates virtualenv context for other commands to run inside it.
"""
with fab.cd(HERE):
with fab.prefix('source %(virtualenv_dir)s/bin/activate' % env):
yield
python类prefix()的实例源码
def source(path):
return prefix('source %s' % path)
def deploy_template(env):
if env.get('template'):
run("git remote add template %s || true" % env.template)
run("git fetch template")
run("git reset HEAD %s && rm -rf %s" % (env.template_dir,
env.template_dir))
run("git read-tree --prefix=%s -u template/master"
% env.template_dir)
def deploy():
with prefix(". /usr/local/bin/virtualenvwrapper.sh; workon perdiem"):
previous_commit_hash = run("git log -1 --format=\"%H\" --no-color", pty=False)
run("git pull")
cmd_changes_deployed = "git log {previous_hash}.. --reverse --format=\"%h : %an : %s\" --no-color".format(
previous_hash=previous_commit_hash
)
changes_deployed = run(cmd_changes_deployed, pty=False)
run("pip install -r ../requirements.txt")
run("python manage.py migrate")
run("python manage.py collectstatic --no-input")
sudo("sv restart perdiem")
send_notification(changes_deployed)
def install_dist_package():
"""Install the dist package on the remote host(s)."""
with cd(remote_app_dir):
with prefix(env.activate):
sudo('pip install {}'.format(dist_package_file))
# remove dist package
run('rm {}'.format(dist_package_file))
# END DEPLOYMENT HELPERS
# Supervisor