Skip to content

Instantly share code, notes, and snippets.

@fadur
Created January 16, 2010 21:31
Show Gist options
  • Select an option

  • Save fadur/279023 to your computer and use it in GitHub Desktop.

Select an option

Save fadur/279023 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from fabric.api import *
from fabric.contrib.files import append
#I've made the assumption that you have git installed
env.projectname = 'name_project' #name of your project
def local():
"""your local setup"""
env.hosts = ['localhost']
env.user = 'username'
env.password = 'password'
env.workspace = '/Users/%(user)s/Sites' % env #name of workspace dir
env.path = '%(workspace)s/%(projectname)s' % env
env.activate_path = '%(workspace)s/%(projectname)s/bin/activate' % env
env.apache_path = '%(path)s/apache' % env
env.httpd = '/private/etc/apache2/httpd.conf' #path to where your apache's httpd.conf is located
env.ip = '127.0.0.1'
def setup():
"""docstring for setup"""
require('hosts', provided_by=[local])
require('path')
with cd(env.workspace):
run('virtualenv --no-site-packages %(projectname)s' % env)
sudo('easy_install pip', pty=True)
run('source %(activate_path)s; pip install django' % env)
with cd(env.path):
run('source %(activate_path)s; django-admin.py startproject %(projectname)s' % env)
run ('mkdir %(path)s/apache' % env )
run('mkdir %(apache_path)s/logs; touch %(apache_path)s/%(projectname)s.conf; touch %(apache_path)s/%(projectname)s.wsgi' % env)
write_wsgi()
write_conf()
get_monitor()
enable_site()
def write_wsgi():
"""docstring for write_wsgi"""
file = open("%(apache_path)s/%(projectname)s.wsgi" % env, "w")
file.write("import os, sys\nsys.path = ['%(path)s'] + sys.path\n\n\nos.environ['DJANGO_SETTINGS_MODULE'] = '%(projectname)s.settings'\n \n\nimport django.core.handlers.wsgi\napplication = django.core.handlers.wsgi.WSGIHandler()" % env)
file.close()
def write_conf():
"""docstring for write_conf"""
file = open("%(apache_path)s/%(projectname)s.conf" % env, "w")
file.write("WSGIPythonHome '%(path)s'\nWSGIRestrictStdout Off\nWSGIDaemonProcess %(projectname)s\nWSGIProcessGroup %(projectname)s\n\n<VirtualHost *:80>\n ServerName %(projectname)s.local\n Alias /site_media/ '%(path)s/%(projectname)s/site-media'\n<Directory '%(path)s/%(projectname)s/site-media'> Order allow,deny\n Options Indexes\n Allow from all\n\n</Directory>\n\n\n\nAlias /media/ '%(path)s/lib/python2.6/site-packages/django/contrib/admin/media/'\n<Directory '%(path)s/python2.6/site-packages/django/contrib/admin/media/'>\n Order allow,deny \n Options Indexes \n Allow from all \n</Directory>\n\nWSGIScriptAlias / '%(apache_path)s/%(projectname)s.wsgi\n\n<Directory '%(apache_path)s'>\n Allow from all\n</Directory>\nErrorLog %(apache_path)s/logs/%(projectname)s-error_log\nTransferLog %(apache_path)s/logs/%(projectname)s-access_log\n</VirtualHost>" % env)
file.close()
def enable_site():
"""this enable your site using httpd.conf"""
append('#enabling %(projectname)s\nInclude %(apache_path)s/%(projectname)s.conf\n' % env,'%(httpd)s' % env, use_sudo=True)
append('%(ip)s %(projectname)s.local' % env, '/etc/hosts', use_sudo=True)
def get_monitor():
"""download and enable auto restart of wsgi"""
run('cd %(path)s;git clone git://gist.github.com/258020.git gist-258020' % env)
run('cd %(path)s/gist-258020; mv monitor.py %(path)s/%(projectname)s/; rm -rf %(path)s/gist-258020' % env)
append("\nimport %(projectname)s.monitor\n%(projectname)s.monitor.start(interval=1.0)" % env,"%(apache_path)s/%(projectname)s.wsgi" % env)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment