Skip to content
Browse files

Initial import. Blank project.

  • Loading branch information...
0 parents commit 82de261f6f20116c94e7143de24162a86e0f4ec0 @onyxfish onyxfish committed Sep 16, 2011
0 __init__.py
No changes.
53 application.wsgi
@@ -0,0 +1,53 @@
+import os
+import sys
+import site
+
+# Reordering the path code from http://code.google.com/p/modwsgi/wiki/VirtualEnvironments
+
+# Remember original sys.path.
+prev_sys_path = list(sys.path)
+
+# Look for Virtual Env
+env_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../virtualenvs/panda"))
+
+# Add our Virtual Env
+site.addsitedir(os.path.join(
+ env_path,
+ "lib/python%s/site-packages" % sys.version[:3]
+))
+
+# Add our project
+sys.path.append(os.path.dirname(__file__))
+# and the parent directory
+sys.path.append(os.path.dirname(os.path.dirname(__file__)))
+
+# Reorder sys.path so new directories at the front.
+new_sys_path = []
+for item in list(sys.path):
+ if item not in prev_sys_path:
+ new_sys_path.append(item)
+ sys.path.remove(item)
+sys.path[:0] = new_sys_path
+
+#redirecting stdout to stderr cuz geopy uses print statements
+sys.stdout = sys.stderr
+
+# Fire up the WSGI
+import django.core.handlers.wsgi
+_application = django.core.handlers.wsgi.WSGIHandler()
+
+# We have to setup our own wsgi handler so we can grab environment
+# variables from apache.
+def application(environ, start_response):
+
+ # Discover our settings file
+ try:
+ os.environ["DJANGO_SETTINGS_MODULE"] = environ["DJANGO_SETTINGS_MODULE"]
+ except KeyError:
+ try:
+ os.environ["DJANGO_SETTINGS_MODULE"] = "config.%(DEPLOYMENT_TARGET)s.settings" % (environ)
+ except KeyError:
+ os.environ["DJANGO_SETTINGS_MODULE"] = "config.settings"
+
+ return _application(environ, start_response)
+
0 config/__init__.py
No changes.
21 config/logger.conf
@@ -0,0 +1,21 @@
+[loggers]
+keys=root
+
+[handlers]
+keys=syslogHandler
+
+[formatters]
+keys=simpleFormatter
+
+[formatter_simpleFormatter]
+format=%(levelname)s:%(name)s:%(message)s
+
+[logger_root]
+level=WARN
+handlers=syslogHandler
+
+[handler_syslogHandler]
+class=handlers.SysLogHandler
+level=WARN
+formatter=simpleFormatter
+args=("/dev/log", handlers.SysLogHandler.LOG_LOCAL2)
0 config/production/__init__.py
No changes.
28 config/production/apache
@@ -0,0 +1,28 @@
+<VirtualHost *:80>
+ ServerName panda.panda.tribapps.com
+ ServerAlias www.panda.panda.tribapps.com
+
+ SetEnv DEPLOYMENT_TARGET production
+ WSGIScriptAlias / /home/newsapps/sites/panda/application.wsgi
+ <Directory /home/newsapps/sites/panda/repository>
+ Order deny,allow
+ Allow from all
+ </Directory>
+
+ Redirect permanent /favicon.ico http://media.panda.tribapps.com/panda/na_media/favicon.ico
+
+ Alias /robots.txt /home/newsapps/sites/panda/repository/media/robots.txt
+
+ ErrorLog /home/newsapps/logs/panda.error.log
+ LogLevel warn
+
+ ServerSignature Off
+
+ RewriteEngine on
+ # canonical hostname
+ RewriteCond %{HTTP_HOST} !^panda.panda.tribapps.com [NC]
+ RewriteRule ^/(.*) http://panda.panda.tribapps.com/$1 [L,R]
+
+ RewriteCond %{REQUEST_URI} /maintenance.html$
+ RewriteRule $ / [R=302,L]
+</VirtualHost>
23 config/production/apache_maintenance
@@ -0,0 +1,23 @@
+<VirtualHost *:80>
+ ServerName panda.panda.tribapps.com
+ ServerAlias www.panda.panda.tribapps.com
+
+ Redirect permanent /favicon.ico http://media.panda.tribapps.com/panda/na_media/favicon.ico
+
+ Alias /robots.txt /home/newsapps/sites/panda/media/robots.txt
+
+ ErrorLog /home/newsapps/logs/panda.error.log
+ LogLevel warn
+
+ ServerSignature Off
+
+ RewriteEngine on
+ # canonical hostname
+ RewriteCond %{HTTP_HOST} !^panda.panda.tribapps.com [NC]
+ RewriteRule ^/(.*) http://panda.panda.tribapps.com/$1 [L,R]
+
+ DocumentRoot /home/newsapps/sites/panda/media/
+
+ RewriteCond %{REQUEST_URI} !/maintenance.html$
+ RewriteRule $ /maintenance.html [R=302,L]
+</VirtualHost>
42 config/production/settings.py
@@ -0,0 +1,42 @@
+from config.settings import *
+
+DEBUG = False
+TEMPLATE_DEBUG = DEBUG
+
+# Database
+DATABASES['default']['HOST'] = 'db'
+DATABASES['default']['PORT'] = '5433'
+DATABASES['default']['USER'] = 'panda'
+DATABASES['default']['PASSWORD'] = 'NE3HY2dc16'
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = 'http://media.panda.tribapps.com/panda/site_media/'
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = 'http://media.panda.tribapps.com/panda/admin_media/'
+
+# Predefined domain
+MY_SITE_DOMAIN = 'panda.panda.tribapps.com'
+
+# Email
+EMAIL_HOST = 'mail'
+EMAIL_PORT = 25
+
+# Caching
+CACHE_BACKEND = 'memcached://cache:11211/'
+
+# S3
+AWS_S3_URL = 's3://media.panda.tribapps.com/panda/'
+
+# Internal IPs for security
+INTERNAL_IPS = ()
+
+# logging
+import logging.config
+LOG_FILENAME = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'logger.conf')
+logging.config.fileConfig(LOG_FILENAME)
+
132 config/settings.py
@@ -0,0 +1,132 @@
+import logging
+import os
+
+import django
+
+# Base paths
+DJANGO_ROOT = os.path.dirname(os.path.realpath(django.__file__))
+SITE_ROOT = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
+
+# Debugging
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+ # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.contrib.gis.db.backends.postgis', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': 'panda', # Or path to database file if using sqlite3.
+ 'USER': 'panda', # Not used with sqlite3.
+ 'PASSWORD': 'NE3HY2dc16', # Not used with sqlite3.
+ 'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
+ 'PORT': '5432', # Set to empty string for default. Not used with sqlite3.
+ }
+}
+
+# Local time
+TIME_ZONE = 'America/Chicago'
+
+# Local language
+LANGUAGE_CODE = 'en-us'
+
+# Site framework
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# If you set this to False, Django will not format dates, numbers and
+# calendars according to the current locale
+USE_L10N = True
+
+# Absolute path to the directory that holds media.
+MEDIA_ROOT = os.path.join(SITE_ROOT, 'media')
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = '/site_media/'
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = '-lyd+@8@=9oni01+gjvb(txz3%hh_7a9m5*n0q^ce5+&c1fkm('
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+ 'django.template.loaders.eggs.Loader',
+)
+
+TEMPLATE_CONTEXT_PROCESSORS = (
+ 'django.core.context_processors.media',
+)
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.cache.UpdateCacheMiddleware',
+ 'django.middleware.common.CommonMiddleware',
+ # 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ # 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ # 'django.contrib.messages.middleware.MessageMiddleware',
+ 'debug_toolbar.middleware.DebugToolbarMiddleware',
+ 'django.middleware.cache.FetchFromCacheMiddleware',
+)
+
+ROOT_URLCONF = 'config.urls'
+
+TEMPLATE_DIRS = (
+ os.path.join(SITE_ROOT, 'templates')
+)
+
+INSTALLED_APPS = (
+ # 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.sites',
+ # 'django.contrib.messages',
+ # Uncomment the next line to enable the admin:
+ # 'django.contrib.admin',
+ # Uncomment the next line to enable admin documentation:
+ # 'django.contrib.admindocs',
+
+ 'django.contrib.humanize',
+ 'django.contrib.gis',
+ 'django.contrib.sitemaps',
+)
+
+# Predefined domain
+MY_SITE_DOMAIN = 'localhost:8000'
+
+# Email
+# run "python -m smtpd -n -c DebuggingServer localhost:1025" to see outgoing
+# messages dumped to the terminal
+EMAIL_HOST = 'localhost'
+EMAIL_PORT = 1025
+DEFAULT_FROM_EMAIL = 'do.not.reply@panda.tribapps.com'
+
+# Caching
+CACHE_MIDDLEWARE_KEY_PREFIX='panda'
+CACHE_MIDDLEWARE_SECONDS=90 * 60 # 90 minutes
+CACHE_BACKEND="dummy:///"
+
+# Logging
+logging.basicConfig(
+ level=logging.DEBUG,
+)
+
+# Allow for local (per-user) override
+try:
+ from local_settings import *
+except ImportError:
+ pass
0 config/staging/__init__.py
No changes.
28 config/staging/apache
@@ -0,0 +1,28 @@
+<VirtualHost *:80>
+ ServerName panda.panda.beta.tribapps.com
+ ServerAlias www.panda.panda.beta.tribapps.com
+
+ SetEnv DEPLOYMENT_TARGET staging
+ WSGIScriptAlias / /home/newsapps/sites/panda/application.wsgi
+ <Directory /home/newsapps/sites/panda/repository>
+ Order deny,allow
+ Allow from all
+ </Directory>
+
+ Redirect permanent /favicon.ico http://media.panda.beta.tribapps.com/panda/media/favicon.ico
+
+ Alias /robots.txt /home/newsapps/sites/panda/repository/media/robots.txt
+
+ ErrorLog /home/newsapps/logs/panda.error.log
+ LogLevel warn
+
+ ServerSignature Off
+
+ RewriteEngine on
+ # canonical hostname
+ RewriteCond %{HTTP_HOST} !^panda.panda.beta.tribapps.com [NC]
+ RewriteRule ^/(.*) http://panda.panda.beta.tribapps.com/$1 [L,R]
+
+ RewriteCond %{REQUEST_URI} /maintenance.html$
+ RewriteRule $ / [R=302,L]
+</VirtualHost>
23 config/staging/apache_maintenance
@@ -0,0 +1,23 @@
+<VirtualHost *:80>
+ ServerName panda.panda.beta.tribapps.com
+ ServerAlias www.panda.panda.beta.tribapps.com
+
+ Redirect permanent /favicon.ico http://media.panda.beta.tribapps.com/media/favicon.ico
+
+ Alias /robots.txt /home/newsapps/sites/panda/media/robots.txt
+
+ ErrorLog /home/newsapps/logs/panda.error.log
+ LogLevel warn
+
+ ServerSignature Off
+
+ RewriteEngine on
+ # canonical hostname
+ RewriteCond %{HTTP_HOST} !^panda.panda.tribapps.com [NC]
+ RewriteRule ^/(.*) http://panda.panda.tribapps.com/$1 [L,R]
+
+ DocumentRoot /home/newsapps/sites/panda/media/
+
+ RewriteCond %{REQUEST_URI} !/maintenance.html$
+ RewriteRule $ /maintenance.html [R=302,L]
+</VirtualHost>
41 config/staging/settings.py
@@ -0,0 +1,41 @@
+from config.settings import *
+
+DEBUG = False
+TEMPLATE_DEBUG = DEBUG
+
+# Database
+DATABASES['default']['HOST'] = 'db'
+DATABASES['default']['PORT'] = '5433'
+DATABASES['default']['USER'] = 'panda'
+DATABASES['default']['PASSWORD'] = 'NE3HY2dc16'
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = 'http://media.panda.beta.tribapps.com/panda/site_media/'
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = 'http://media.panda.beta.tribapps.com/panda/admin_media/'
+
+# Predefined domain
+MY_SITE_DOMAIN = 'panda.panda.beta.tribapps.com'
+
+# Email
+EMAIL_HOST = 'mail'
+EMAIL_PORT = 25
+
+# Caching
+CACHE_BACKEND = 'memcached://cache:11211/'
+
+# S3
+AWS_S3_URL = 's3://media.panda.beta.tribapps.com/panda/'
+
+# Internal IPs for security
+INTERNAL_IPS = ()
+
+# logging
+import logging.config
+LOG_FILENAME = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'logger.conf')
+logging.config.fileConfig(LOG_FILENAME)
16 config/urls.py
@@ -0,0 +1,16 @@
+from django.conf.urls.defaults import *
+
+# Uncomment the next two lines to enable the admin:
+# from django.contrib import admin
+# admin.autodiscover()
+
+urlpatterns = patterns('',
+ # Example:
+ # (r'^simple_project/', include('simple_project.foo.urls')),
+
+ # Uncomment the admin/doc line below to enable admin documentation:
+ # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+ # Uncomment the next line to enable the admin:
+ # (r'^admin/', include(admin.site.urls)),
+)
0 data/psql/dump.sql
No changes.
7 data/psql/finish_init.sql
@@ -0,0 +1,7 @@
+create or replace function exec(text) returns void as $$
+begin
+execute $1;
+end;
+$$ language plpgsql;
+
+select exec('alter table '||table_name||' owner to panda') from information_schema.tables where table_schema='public';
346 fabfile.py
@@ -0,0 +1,346 @@
+# Chicago Tribune News Applications fabfile
+# No copying allowed
+
+from fabric.api import *
+
+"""
+Base configuration
+"""
+#name of the deployed site if different from the name of the project
+env.site_name = 'panda'
+
+env.project_name = 'panda'
+env.database_password = 'NE3HY2dc16'
+env.site_media_prefix = "site_media"
+env.admin_media_prefix = "admin_media"
+env.path = '/home/newsapps/sites/%(project_name)s' % env
+env.log_path = '/home/newsapps/logs/%(project_name)s' % env
+env.env_path = '/home/newsapps/sites/virtualenvs/%(project_name)s' % env
+env.repo_path = '%(path)s' % env
+env.apache_config_path = '/home/newsapps/sites/apache/%(project_name)s' % env
+env.python = 'python2.6'
+env.repository_url = "git@github.com:pandaproject/panda.git"
+env.memcached_server_address = "cache"
+env.cache_server = "lb"
+env.multi_server = False
+
+"""
+Environments
+"""
+def production():
+ """
+ Work on production environment
+ """
+ env.settings = 'production'
+ env.hosts = ['db.panda.tribapps.com']
+ env.user = 'newsapps'
+ env.s3_bucket = 'media.panda.tribapps.com'
+ env.site_domain = 'panda.panda.tribapps.com'
+
+def staging():
+ """
+ Work on staging environment
+ """
+ env.settings = 'staging'
+ env.hosts = ['db.panda.beta.tribapps.com']
+ env.user = 'newsapps'
+ env.s3_bucket = 'media.panda.beta.tribapps.com'
+ env.site_domain = 'panda.panda.beta.tribapps.com'
+
+"""
+Branches
+"""
+def stable():
+ """
+ Work on stable branch.
+ """
+ env.branch = 'stable'
+
+def master():
+ """
+ Work on development branch.
+ """
+ env.branch = 'master'
+
+def branch(branch_name):
+ """
+ Work on any specified branch.
+ """
+ env.branch = branch_name
+
+"""
+Commands - setup
+"""
+def setup():
+ """
+ Setup a fresh virtualenv, install everything we need, and fire up the database.
+
+ Does NOT perform the functions of deploy().
+ """
+ require('settings', provided_by=[production, staging])
+ require('branch', provided_by=[stable, master, branch])
+
+ setup_directories()
+ setup_virtualenv()
+ clone_repo()
+ checkout_latest()
+ install_requirements()
+ destroy_database()
+ create_database()
+ load_data()
+ install_apache_conf()
+ deploy_requirements_to_s3()
+
+def setup_directories():
+ """
+ Create directories necessary for deployment.
+ """
+ run('mkdir -p %(path)s' % env)
+
+def setup_virtualenv():
+ """
+ Setup a fresh virtualenv.
+ """
+ run('virtualenv -p %(python)s --no-site-packages %(env_path)s;' % env)
+ run('source %(env_path)s/bin/activate; %(env_path)s/bin/easy_install -U setuptools; %(env_path)s/bin/easy_install -U pip;' % env)
+
+def clone_repo():
+ """
+ Do initial clone of the git repository.
+ """
+ run('git clone %(repository_url)s %(repo_path)s' % env)
+
+def checkout_latest():
+ """
+ Pull the latest code on the specified branch.
+ """
+ run('cd %(repo_path)s; git checkout %(branch)s; git pull origin %(branch)s' % env)
+
+def install_requirements():
+ """
+ Install the required packages using pip.
+ """
+ run('source %(env_path)s/bin/activate; yes w | pip install -q -r %(repo_path)s/requirements.txt' % env)
+
+def install_apache_conf():
+ """
+ Install the apache site config file.
+ """
+ sudo('cp %(repo_path)s/config/%(settings)s/apache %(apache_config_path)s' % env)
+
+def deploy_requirements_to_s3():
+ """
+ Deploy the admin media to s3.
+ """
+ with settings(warn_only=True):
+ run('s3cmd del --recursive s3://%(s3_bucket)s/%(project_name)s/%(admin_media_prefix)s/' % env)
+ run('s3cmd -P --guess-mime-type --rexclude-from=%(repo_path)s/s3exclude sync %(env_path)s/src/django/django/contrib/admin/media/ s3://%(s3_bucket)s/%(project_name)s/%(admin_media_prefix)s/' % env)
+
+
+"""
+Commands - deployment
+"""
+def deploy():
+ """
+ Deploy the latest version of the site to the server and restart Apache2.
+
+ Does not perform the functions of load_new_data().
+ """
+ require('settings', provided_by=[production, staging])
+ require('branch', provided_by=[stable, master, branch])
+
+ with settings(warn_only=True):
+ maintenance_up()
+
+ checkout_latest()
+ gzip_assets()
+ deploy_to_s3()
+ maintenance_down()
+
+def maintenance_up():
+ """
+ Install the Apache maintenance configuration.
+ """
+ sudo('cp %(repo_path)s/config/%(settings)s/apache_maintenance %(apache_config_path)s' % env)
+ reboot()
+
+def gzip_assets():
+ """
+ GZips every file in the media directory and places the new file
+ in the gzip directory with the same filename.
+ """
+ run('cd %(repo_path)s; python gzip_assets.py' % env)
+
+def deploy_to_s3():
+ """
+ Deploy the latest project site media to S3.
+ """
+ env.media_path = '%(repo_path)s/media/' % env
+ run(('s3cmd -P --guess-mime-type --rexclude-from=%(repo_path)s/s3exclude sync %(media_path)s s3://%(s3_bucket)s/%(project_name)s/%(site_media_prefix)s/') % env)
+
+ env.gzip_path = '%(repo_path)s/gzip_media/' % env
+ run(('s3cmd -P --add-header=Content-encoding:gzip --guess-mime-type --rexclude-from=%(repo_path)s/s3exclude sync %(gzip_path)s s3://%(s3_bucket)s/%(project_name)s/%(site_media_prefix)s/') % env)
+
+def reboot():
+ """
+ Restart the Apache2 server.
+ """
+ if env.multi_server:
+ run('bounce-apaches-for-cluster')
+ else:
+ sudo('service apache2 restart')
+
+def maintenance_down():
+ """
+ Reinstall the normal site configuration.
+ """
+ install_apache_conf()
+ reboot()
+
+"""
+Commands - rollback
+"""
+def rollback(commit_id):
+ """
+ Rolls back to specified git commit hash or tag.
+
+ There is NO guarantee we have committed a valid dataset for an arbitrary
+ commit hash.
+ """
+ require('settings', provided_by=[production, staging])
+ require('branch', provided_by=[stable, master, branch])
+
+ maintenance_up()
+ checkout_latest()
+ git_reset(commit_id)
+ gzip_assets()
+ deploy_to_s3()
+ maintenance_down()
+
+def git_reset(commit_id):
+ """
+ Reset the git repository to an arbitrary commit hash or tag.
+ """
+ env.commit_id = commit_id
+ run("cd %(repo_path)s; git reset --hard %(commit_id)s" % env)
+
+"""
+Commands - data
+"""
+def load_new_data():
+ """
+ Erase the current database and load new data from the SQL dump file.
+ """
+ require('settings', provided_by=[production, staging])
+
+ maintenance_up()
+ pgpool_down()
+ destroy_database()
+ create_database()
+ load_data()
+ pgpool_up()
+ maintenance_down()
+
+def create_database(func=run):
+ """
+ Creates the user and database for this project.
+ """
+ func('echo "CREATE USER %(project_name)s WITH PASSWORD \'%(database_password)s\';" | psql postgres' % env)
+ func('createdb -O %(project_name)s %(project_name)s -T template_postgis' % env)
+
+def destroy_database(func=run):
+ """
+ Destroys the user and database for this project.
+
+ Will not cause the fab to fail if they do not exist.
+ """
+ with settings(warn_only=True):
+ func('dropdb %(project_name)s' % env)
+ func('dropuser %(project_name)s' % env)
+
+def load_data():
+ """
+ Loads data from the repository into PostgreSQL.
+ """
+ run('psql -q %(project_name)s < %(repo_path)s/data/psql/dump.sql' % env)
+
+def pgpool_down():
+ """
+ Stop pgpool so that it won't prevent the database from being rebuilt.
+ """
+ sudo('/etc/init.d/pgpool stop')
+
+def pgpool_up():
+ """
+ Start pgpool.
+ """
+ sudo('/etc/init.d/pgpool start')
+
+"""
+Commands - miscellaneous
+"""
+
+def clear_cache():
+ """
+ Restart memcache, wiping the current cache.
+ """
+ if env.multi_server:
+ run('bounce-memcaches-for-cluster')
+ else:
+ sudo('service memcached restart')
+
+ run('curl -X PURGE -H "Host: %(site_domain)s" http://%(cache_server)s/' % env)
+
+def echo_host():
+ """
+ Echo the current host to the command line.
+ """
+ run('echo %(settings)s; echo %(hosts)s' % env)
+
+"""
+Deaths, destroyers of worlds
+"""
+def shiva_the_destroyer():
+ """
+ Remove all directories, databases, etc. associated with the application.
+ """
+ with settings(warn_only=True):
+ run('rm -Rf %(path)s' % env)
+ run('rm -Rf %(log_path)s' % env)
+ run('rm -Rf %(env_path)s' % env)
+ pgpool_down()
+ run('dropdb %(project_name)s' % env)
+ run('dropuser %(project_name)s' % env)
+ pgpool_up()
+ sudo('rm %(apache_config_path)s' % env)
+ reboot()
+ run('s3cmd del --recursive s3://%(s3_bucket)s/%(project_name)s' % env)
+
+def local_shiva():
+ destroy_database(local)
+
+def local_bootstrap():
+ create_database(local)
+
+ # Normal bootstrap
+ local('python manage.py syncdb --noinput')
+
+ # Bootstrap with south
+ # local('python manage.py syncdb --all --noinput')
+ # local('python manage.py migrate --fake')
+
+"""
+Utility functions (not to be called directly)
+"""
+def _execute_psql(query):
+ """
+ Executes a PostgreSQL command using the command line interface.
+ """
+ env.query = query
+ run(('cd %(repo_path)s; psql -q %(project_name)s -c "%(query)s"') % env)
+
+def _confirm_branch():
+ if (env.settings == 'production' and env.branch != 'stable'):
+ answer = prompt("You are trying to deploy the '%(branch)s' branch to production.\nYou should really only deploy a stable branch.\nDo you know what you're doing?" % env, default="Not at all")
+ if answer not in ('y','Y','yes','Yes','buzz off','screw you'):
+ exit()
32 gzip_assets.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+import os
+import gzip
+import shutil
+
+class FakeTime:
+ def time(self):
+ return 1261130520.0
+
+# Hack to override gzip's time implementation
+# See: http://stackoverflow.com/questions/264224/setting-the-gzip-timestamp-from-python
+gzip.time = FakeTime()
+
+shutil.rmtree('gzip_media', ignore_errors=True)
+
+for path, dirs, files in os.walk('media'):
+ for filename in files:
+ if filename[-3:] not in ['js', 'css', 'txt', 'html']:
+ continue
+
+ src_path = os.path.join(path, filename)
+ dest_path = 'gzip_'+src_path
+ if not os.path.exists(os.path.dirname(dest_path)):
+ os.makedirs(os.path.dirname(dest_path))
+
+ f_in = open(src_path, 'rb')
+ contents = f_in.read()
+ f_in.close()
+ f_out = gzip.open(dest_path, 'wb')
+ f_out.write(contents)
+ f_out.close();
21 manage.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+import os
+from django.core.management import execute_manager
+
+if not os.environ.has_key("DJANGO_SETTINGS_MODULE"):
+ if not os.environ.has_key("DEPLOYMENT_TARGET"):
+ os.environ["DJANGO_SETTINGS_MODULE"] = "config.settings"
+ else:
+ os.environ["DJANGO_SETTINGS_MODULE"] = "config.%s.settings" % os.environ["DEPLOYMENT_TARGET"]
+
+settings_module = os.environ["DJANGO_SETTINGS_MODULE"]
+
+try:
+ settings = __import__(settings_module, globals(), locals(), ['settings'], -1)
+except ImportError:
+ import sys
+ sys.stderr.write("Error: Can't find the file '%s.py'.\n" % settings_module)
+ sys.exit(1)
+
+if __name__ == "__main__":
+ execute_manager(settings)
57 media/maintenance.html
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Maintenance</title>
+ <style type="text/css">
+ body {
+ margin:0;
+ padding:0;
+ width:100%;
+ height:100%;
+ font: 14px/1.5em Helvetica Neue, Helvetica, Arial, sans-serif;
+ background-color:#555;
+ color:#222;
+ overflow:hidden;
+ }
+ #outer {
+ position:absolute;
+ top:50%;
+ left:50%;
+ }
+
+ #message {
+ position:relative;
+ top:-100px;
+ left:-50%;
+ width:400px;
+ height:160px;
+ margin:0 auto;
+ padding:20px 40px;
+ border-radius: 8px;
+ -o-border-radius: 8px;
+ -ms-border-radius: 8px;
+ -moz-border-radius: 8px;
+ -webkit-border-radius: 8px;
+ box-shadow:0 1px 4px rgba(0, 0, 0, 0.9), 0 0 40px rgba(0, 0, 0, 0.1) inset;
+ -webkit-box-shadow:0 1px 4px rgba(0, 0, 0, 0.9), 0 0 40px rgba(0, 0, 0, 0.1) inset;
+ -moz-box-shadow:0 1px 4px rgba(0, 0, 0, 0.9), 0 0 40px rgba(0, 0, 0, 0.1) inset;
+ -ms-box-shadow:0 1px 4px rgba(0, 0, 0, 0.9), 0 0 40px rgba(0, 0, 0, 0.1) inset;
+ -o-box-shadow:0 1px 4px rgba(0, 0, 0, 0.9), 0 0 40px rgba(0, 0, 0, 0.1) inset;
+
+ background-color:#dfdfdf;
+ text-shadow:0 1px 0 white;
+ }
+
+
+ </style>
+</head>
+<body>
+ <div id="outer">
+ <div id="message">
+ <h1>Down for maintenance</h1>
+ <p>We are sorry for the inconvenience, but we are either in the middle of upgrading this web site, or frantically trying to fix something we inadvertently broke. Bear with us, and check back in a couple minutes.</p>
+ </div>
+ </div>
+</body>
+</html>
69 media/reset.css
@@ -0,0 +1,69 @@
+/*
+Copyright (c) 2008, Yahoo! Inc. All rights reserved.
+Code licensed under the BSD License:
+http://developer.yahoo.net/yui/license.txt
+version: 2.5.1
+*/
+html {
+ color: #000;
+ background: #FFF;
+}
+body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td {
+ margin: 0;
+ padding: 0;
+}
+table {
+ border-collapse: collapse;
+ border-spacing: 0;
+}
+fieldset,img {
+ border: 0;
+}
+address,caption,cite,code,dfn,em,strong,th,var {
+ font-style: normal;
+ font-weight: normal;
+}
+li {
+ list-style: none;
+}
+caption,th {
+ text-align: left;
+}
+h1,h2,h3,h4,h5,h6 {
+ font-size: 100%;
+ font-weight: normal;
+}
+q:before,q:after {
+ content: '';
+}
+abbr,acronym {
+ border: 0;
+ font-variant: normal;
+}
+sup {
+ vertical-align: text-top;
+}
+sub {
+ vertical-align: text-bottom;
+}
+input,textarea,select {
+ font-family: inherit;
+ font-size: inherit;
+ font-weight: inherit;
+}
+input,textarea,select {*font-size:100%;
+}
+legend {
+ color: #000;
+}
+body {
+ font: 13px/1.231 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;
+}
+table {
+ font-size: inherit;
+ font: 100%;
+}
+pre,code,kbd,samp,tt {
+ font-family: monospace;*font-size:108%;
+ line-height: 100%;
+}
0 media/test/foo.txt
No changes.
6 requirements.txt
@@ -0,0 +1,6 @@
+-e git+https://github.com/django/django.git@1.3#egg=django
+fabric==0.9.4
+geopy
+django-debug-toolbar
+psycopg2
+python-memcached
1 s3exclude
@@ -0,0 +1 @@
+.svn
5 templates/404.html
@@ -0,0 +1,5 @@
+{% extends "base.html" %}
+
+{% block title %}Not Found{% endblock %}
+
+{% block content %}{% endblock %}
5 templates/500.html
@@ -0,0 +1,5 @@
+{% extends "base.html" %}
+
+{% block title %}Server Error{% endblock %}
+
+{% block content %}{% endblock %}
11 templates/base.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>{% block title %}{% endblock %}</title>
+ <link rel="stylesheet" href="/assets/css/reset.css" type="text/css" charset="utf-8"/>
+</head>
+<body>
+{% block content %}{% endblock %}
+</body>
+</html>

0 comments on commit 82de261

Please sign in to comment.
Something went wrong with that request. Please try again.