Created
August 12, 2014 08:42
-
-
Save hhursev/75e4b383f0fb86afcc26 to your computer and use it in GitHub Desktop.
Example fabfile to use
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
import os | |
from fabric.api import env, local, run, prefix, cd | |
env.roledefs = { | |
'xx': ['host:port'], | |
} | |
env.forward_agent = True | |
def _local_manage(command): | |
local("python manage.py {}".format(command)) | |
def _manage(command): | |
with prefix('source {}bin/activate'.format(env.venv)): | |
run('python manage.py {command} {module}'.format( | |
command=command, | |
module='--settings={}'.format(env.settings_module) if env.settings_module else '')) | |
def r(): | |
"""Clean .pyc files and run a public development server""" | |
local('stty sane') | |
_local_manage('clean_pyc -p .') | |
_local_manage('runserver_plus 0.0.0.0:8000') | |
def s(): | |
"""Run ipython shell_plus from django_extensions""" | |
local('stty sane') | |
_local_manage('shell_plus --ipython') | |
def xx(): | |
env.roles = ['xx'] | |
env.home = '~/path_to_project/' | |
env.restart_command = 'touch wsgi.py' | |
env.branch = 'master' | |
env.venv = '~/.virtualenvs/path_to_project_venv/' | |
env.settings_module = 'DJANGO_SETTINGS_MODULE used' | |
def compilemessages(): | |
_manage('compilemessages') | |
def gitfetch(): | |
run('git checkout {}'.format(env.branch)) | |
run('git pull') | |
def migrate(): | |
_manage('syncdb') | |
_manage('migrate') | |
def collectstatic(): | |
_manage('collectstatic --noinput') | |
def restart(): | |
run('{}'.format(env.restart_command)) | |
def update_packages(upgrade=False): | |
with prefix('source {}bin/activate'.format(env.venv)): | |
run('pip install -r requirements/requirements.txt {}'.format('-U' if upgrade else '')) | |
def update(): | |
with cd(env.home): | |
gitfetch() | |
update_packages() | |
migrate() | |
compilemessages() | |
collectstatic() | |
restart() | |
def dump(): | |
current_dir = os.getcwd() | |
with prefix('source {}bin/activate'.format(env.venv)), cd('{}'.format(env.home)): | |
dumped_file = run('python dump_db.py {}'.format(env.settings_module)) | |
file_path = os.path.join(env.home, dumped_file) | |
copy_to = os.path.join(current_dir, dumped_file) | |
scp(file_path, copy_to) | |
def scp(file_path, copy_to, recursive=False): | |
local('scp {} {}:{} {}'.format('-r' if recursive else '', env.host, file_path, copy_to)) | |
def gitsync(): | |
with cd(env.home): | |
run('git checkout {}'.format(env.branch)) | |
run('git fetch') | |
run('git reset --hard origin/{}'.format(env.branch)) | |
def getwebroot(): | |
current_dir = os.getcwd() | |
webroot_dir = os.path.join(env.home, 'webroot') | |
scp(webroot_dir, current_dir, recursive=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment