diff options
Diffstat (limited to 'fabfile/helpers.py')
-rw-r--r-- | fabfile/helpers.py | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/fabfile/helpers.py b/fabfile/helpers.py new file mode 100644 index 0000000..c31461b --- /dev/null +++ b/fabfile/helpers.py @@ -0,0 +1,97 @@ +"""Deployment helpers. +""" +from os.path import join as join_path + +from fabric.api import * +from fabric.contrib import files + + +def ve_run(cmd): + """Runs a command inside the activated virtualenv. + """ + require('root', provided_by=['setups.stage', 'setups.production']) + with prefix('source %(root)s/bin/activate' % env): + run(cmd) + + +def manage(cmd): + """Runs a command with manage.py. + """ + require('manage_py', provided_by=['setups.stage', 'setups.production']) + ve_run('%s %s' % (env.manage_py, cmd)) + + +def update_project(): + """Updates the project source. + """ + require('src_root', provided_by=['setups.stage', 'setups.production']) + require('git_branch', provided_by=['setups.stage', 'setups.production']) + with cd(env.src_root): + run('git pull origin %(git_branch)s' % env) + + +def link_settings(): + """Links the appropriate settings. + """ + require('stage', provided_by=['setups.stage', 'setups.production']) + require('config', provided_by=['setups.stage', 'setups.production']) + require('proj_root', provided_by=['setups.stage', 'setups.production']) + if env.stage: + host_settings = join_path(env.config, '%(host)s_stage.py' % env) + else: + host_settings = join_path(env.config, '%(host)s.py' % env) + settings = join_path(env.proj_root, 'local_settings.py') + if files.exists(settings): + run('rm %s' % settings) + if files.exists(host_settings): + run('ln -s %s %s' % (host_settings, settings)) + else: + print 'No host specific settings file found. Create one at %s' % host_settings + + +def collect_static(): + """Collects all static files. + """ + manage('collectstatic') + + +@task +def syncdb(): + """Runs the syncdb management command. + """ + manage('syncdb') + + +@task +def migrate(app_name=None): + """Runs the migrations for one or all apps. + """ + manage('migrate %s' % app_name) + + +@task(alias='id') +def indetify(): + """Identifes the deployed project. + + Displays the deployed project version, all Python packages installed inside + the virtualenv and the state of the migrations. + """ + require('proj_root', provided_by=['setups.stage', 'setups.production']) + with cd(env.proj_root): + run('git log -1') + ve_run('pip freeze') + manage('migrate -list') + + +@task(alias='install') +def install_requirements(): + """Installs the requirements. + """ + require('pip_file', provided_by=['setups.stage', 'setups.production']) + ve_run('pip install -r %(pip_file)s' % env) + + +@task(alias='load') +def load_fixture(fixture_path): + """Loads one or more fixtures.""" + manage('loaddata %s' % fixture_path) |