Skip to content

Instantly share code, notes, and snippets.

View fadur's full-sized avatar

Feisal Adur fadur

View GitHub Profile
#copy of the example script found on mod_wsgi wiki
#http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Monitoring_For_Code_Changes
#am not sure about the licencing but I've created this gist for personal use, making it easy to automate the setup when this is used
import os
import sys
import time
import signal
import threading
import atexit
#!/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
WSGIPythonHome /Users/username/Sites/sitename.tld
WSGIRestrictStdout Off
WSGIDaemonProcess sitename.tld
WSGIProcessGroup sitename.tld
<VirtualHost *:80>
ServerName sitename.local
Alias /site_media/ "/Users/username/Sites/sitename.tld/site-media/"
<Directory "/Users/username/Sites/sitename.tld/site-media/">
Order allow,deny
@fadur
fadur / gist:804794
Created January 31, 2011 20:57
wsgi example
import os, sys
sys.path = ['/Users/username/Sites/sitename.tld'] + sys.path
os.environ['DJANGO_SETTINGS_MODULE'] = 'sitename.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
@fadur
fadur / gist:804799
Created January 31, 2011 21:00
local fabfile
def local():
"""your local setup"""
env.hosts = ['localhost']
env.user = 'username'
env.password = 'secret'
env.projectname = 'test_project'
env.workspace = '/Users/%(username)s/Sites' #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
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)
@fadur
fadur / gist:804810
Created January 31, 2011 21:04
two methods that write out conf files
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/ '%(apache_path)s/public/site_media'\n<Directory '%(apache_path)s/public/site_media'>\n 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 Orde
@fadur
fadur / gist:804822
Created January 31, 2011 21:10
writes in conf files
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)
@fadur
fadur / gist:804825
Created January 31, 2011 21:11
get monitor gist
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)
@fadur
fadur / strip_html.py
Created February 28, 2011 19:37
Strips html tags from a given webpage
import re
import urllib
"""
strip html tags from a webpage
need's regex to remove js too
"""
url = ''