Created
February 14, 2010 21:52
-
-
Save idan/304285 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
projname/ | |
django_wsgi.py | |
fabfile.py | |
static/ | |
venv/ # virtualenv dir | |
docs/ | |
index.rst | |
foo.rst | |
... more docs ... | |
Makefile | |
projname/ | |
__init__.py | |
manage.py | |
urls.py | |
someapp/ | |
anotherapp/ | |
appsftw/ | |
... more apps ... | |
conf/ | |
__init__.py # empty! | |
base.py # contains a working set of defaults | |
ProductionServerHostname.py # imports * from base.py | |
MyMacbook.local.py # imports * from base.py |
This file contains hidden or 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
from os.path import join, basename, abspath | |
from fabric.api import * | |
from fabric.contrib import files | |
from fabric.context_managers import cd | |
env.hosts = ['pixane.com'] | |
env.root = '/var/web/myretailgenie' | |
env.proj_root = join(env.root, basename(abspath(env.root))) | |
env.venv = join(env.root, 'venv') | |
env.pip_file = join(env.root, 'requirements.txt') | |
def version(): | |
"""Show last commit to repo on server""" | |
run('cd %s; git log -1' % env.proj_root) | |
def restart(): | |
"""Restart Apache process""" | |
run('touch %s' % join(env.root, 'django_wsgi.py')) | |
def update_reqs(): | |
"""Update pip requirements""" | |
ve_run('pip install -E %s -r %s' % (env.venv, env.pip_file)) | |
def push(): | |
"""Push to git.""" | |
local('git push origin master') | |
def pull(): | |
"""Updates project source""" | |
run('cd %s; git pull origin master' % env.proj_root) | |
def syncdb(): | |
"""Run syncdb""" | |
output = ve_run('%s syncdb' % join(env.proj_root, 'manage.py')) | |
def link_settings(): | |
"""Link project settings.py to the appropriate settings.""" | |
host_settings = join(env.proj_root, 'conf', '%s.py' % env.get('host')) | |
base_settings = join(env.proj_root, 'conf', 'base.py') | |
settings = join(env.proj_root, '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. Linking to conf/base.py...' | |
run('ln -s %s %s' % (base_settings, settings)) | |
def ve_run(cmd): | |
""" | |
Helper function. | |
Runs a command using the virtualenv environment | |
""" | |
require('root') | |
return run('source %s/bin/activate; %s' % (env.root, cmd)) | |
def clean_docs(): | |
""" | |
Deletes all built sphinx docs. | |
""" | |
with cd(join(env.proj_root, 'docs')): | |
ve_run('make clean') | |
def build_docs(): | |
""" | |
Use sphinx to build the latest version of the docs. | |
""" | |
with cd(join(env.proj_root, 'docs')): | |
ve_run('make html') | |
def migrate(): | |
"""Run south migrations""" | |
output = ve_run('%s migrate' % join(env.proj_root, 'manage.py')) | |
def update(): | |
"""Update source, update pip requirements, syncdb, restart server""" | |
update_proj() | |
update_reqs() | |
link_settings() | |
syncdb() | |
restart() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment