Commits

Bruce Kroeze committed 38860e7

created a solid base project with a buildout config

Comments (0)

Files changed (17)

 pychecker-log.txt
 \.\#*
 backups/*
+development.py
+production.py
+playinfo.db
 newest = true
 unzip = true
 eggs =
-    Django
     ipython
     simplejson
     mysql-python
     django-keyedcache
     django-debug-toolbar
     nose
+    south
 
 extra_paths =
-    playainfo
     ${django-nose:location}
-    .
 
 develop =
 
 
   | bin/buildout
 
+* Copy "development_example.py" to "development.py" in your playainfo/playinfo directory and edit to have the right information for your installation.  Most likely, you'll want to change the database information and enter your mail server info.
+
+* Create your database
+
+  | bin/django syncdb
+  | bin/django migrate
+
 * Start the python web server
 
   *This server is not Apache, but a dedicated test server for python applications. It runs on port 8000 and it is important that Apache (or other web service) not do not LISTEN to port 8000. The following is run in a shell. You may want to run it in the background ('&', 'jobs', fg... remember).*
+../parts/django/django/contrib/admin/media

playainfo/development_example.py

+# This is the development settings file for PlayaInfo
+# You should copy it to a file named "development.py"
+# or "production.py" and modify as you need for your
+# installation.
+
+from playainfo.settings import *
+import os
+
+DEBUG=True
+TEMPLATE_DEBUG=False
+
+DATABASE_ENGINE = 'sqlite3'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+DATABASE_NAME = os.path.join(DIRNAME, 'playinfo.db')  # Or path to database file if using sqlite3.
+DATABASE_USER = ''             # Not used with sqlite3.
+DATABASE_PASSWORD = ''         # Not used with sqlite3.
+DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
+DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
+
+# MEDIA_ROOT = os.path.join(DIRNAME, 'media')
+# MEDIA_URL = '/media/'
+# ADMIN_MEDIA_PREFIX = '/media/admin/'
+
+# DEFAULT_FROM_EMAIL = '(Dev) Playadmin <system@example.com>'
+EMAIL_HOST = ''
+EMAIL_HOST_USER = ''
+EMAIL_FROM = ''
+EMAIL_HOST_PASSWORD = ''
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+SECRET_KEY = '2aab8dad3e20117322bf69523a700e91'
+
+TIME_ZONE = 'America/PSTPDT'
+
+from utils import logs
+_loglevels = {'root' : logs.DEBUG, 'keyedcache' : logs.INFO}
+_logfname = os.path.normpath(os.path.join(DIRNAME, '..'))
+_logfname = os.path.join(_logfname, 'playinfo.log') + ':20000000:20'
+log = logs.getLogger('settings', level=_loglevels,
+      format="%(asctime)s [%(process)d] %(levelname)s %(name)s: %(message)s",
+      outfile=_logfname, streaming=True)
+log.debug('development target')

playainfo/directory/migrations/0001_initial.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        pass
+
+
+    def backwards(self, orm):
+        pass
+
+
+    models = {
+        
+    }
+
+    complete_apps = ['directory']

playainfo/directory/migrations/__init__.py

Empty file added.

playainfo/migrations/0001_initial.py

+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+        pass
+
+
+    def backwards(self, orm):
+        pass
+
+
+    models = {
+        
+    }
+
+    complete_apps = ['playainfo']

playainfo/migrations/__init__.py

Empty file added.

playainfo/models.py

Empty file added.

playainfo/production_example.py

+# This is the development settings file for PlayaInfo
+# You should copy it to a file named "development.py"
+# or "production.py" and modify as you need for your
+# installation.
+
+from playainfo.settings import *
+import os
+
+DEBUG=True
+TEMPLATE_DEBUG=False
+
+DATABASE_ENGINE = 'sqlite3'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+DATABASE_NAME = os.path.join(DIRNAME, 'playinfo.db')  # Or path to database file if using sqlite3.
+DATABASE_USER = ''             # Not used with sqlite3.
+DATABASE_PASSWORD = ''         # Not used with sqlite3.
+DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
+DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
+
+# MEDIA_ROOT = os.path.join(DIRNAME, 'media')
+# MEDIA_URL = '/media/'
+# ADMIN_MEDIA_PREFIX = '/media/admin/'
+
+# DEFAULT_FROM_EMAIL = '(Dev) Playadmin <system@example.com>'
+EMAIL_HOST = ''
+EMAIL_HOST_USER = ''
+EMAIL_FROM = ''
+EMAIL_HOST_PASSWORD = ''
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+SECRET_KEY = '2aab8dad3e20117322bf69523a700e91'
+
+TIME_ZONE = 'America/PSTPDT'
+
+from utils import logs
+_loglevels = {'root' : logs.DEBUG, 'keyedcache' : logs.INFO}
+_logfname = os.path.normpath(os.path.join(DIRNAME, '..'))
+_logfname = os.path.join(_logfname, 'playinfo.log') + ':20000000:20'
+log = logs.getLogger('settings', level=_loglevels,
+      format="%(asctime)s [%(process)d] %(levelname)s %(name)s: %(message)s",
+      outfile=_logfname, streaming=True)
+log.debug('development target')

playainfo/settings.py

 # Django settings for playainfo project.
+#
+# This file is imported by "development.py" or "production.py"
+# You should not modify this file to put in local settings.  Instead
+# you should put those local settings, such as file paths and database
+# details in the development/production files.
+#
 
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
 
+import os
+
+# Directory name of this file.  Very helpful for figuring out filepaths
+DIRNAME = os.path.abspath(os.path.dirname(__file__).decode('utf-8'))
+
 ADMINS = (
     # ('Your Name', 'your_email@domain.com'),
 )
 
 MANAGERS = ADMINS
 
+# set these in your development/production file, not here.
 DATABASE_ENGINE = ''           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
 DATABASE_NAME = ''             # Or path to database file if using sqlite3.
 DATABASE_USER = ''             # Not used with sqlite3.
 DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
 DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
 
+# Set these in your development/production file
+DEFAULT_FROM_EMAIL = 'system@example.com'
+EMAIL_HOST = ''
+EMAIL_HOST_USER = ''
+EMAIL_FROM = ''
+EMAIL_HOST_PASSWORD = ''
+
 # Local time zone for this installation. Choices can be found here:
 # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
 # although not all choices may be available on all operating systems.
 # If running in a Windows environment this must be set to the same as your
 # system time zone.
+# Set this in your development/production file, if it needs to be overridden
 TIME_ZONE = 'America/Chicago'
 
 # Language code for this installation. All choices can be found here:
 
 # Absolute path to the directory that holds media.
 # Example: "/Users/media/media.lawrence.com/"
-MEDIA_ROOT = ''
+# Set this in your development/production file, if it needs to be overridden
+MEDIA_ROOT = os.path.join(DIRNAME, '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 = ''
+MEDIA_URL = '/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/'
+ADMIN_MEDIA_PREFIX = '/media/admin/'
 
 # Make this unique, and don't share it with anybody.
-SECRET_KEY = '=_q01e6(rns-%ei$8ptn(rnd&xsh*noct9%ir113_-+n2r1i5h'
+# Set this in your development/production file, not here.
+SECRET_KEY = ''
 
 # List of callables that know how to import templates from various sources.
 TEMPLATE_LOADERS = (
     'django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
+    # optional, enable this if you are using the debug toolbar
+    'debug_toolbar.middleware.DebugToolbarMiddleware',
 )
 
 ROOT_URLCONF = 'playainfo.urls'
 
 TEMPLATE_DIRS = (
-	'/home/playainfo/src/playainfo/templates/',
+	os.path.join(DIRNAME, 'templates')
 )
 
 INSTALLED_APPS = (
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.sites',
+    'playainfo',
+    'playainfo.directory',
+    'keyedcache',
+    'south',
+
+    # optional, but excellent and recommended
+    'django_extensions',
+    # optional, a great help during development or debugging
+    'debug_toolbar',
 )
+
+# configure the cache
+CACHE_BACKEND = "memcached://127.0.0.1:11211/"
+CACHE_TIMEOUT = 60*5
+CACHE_PREFIX = "L"
+
+INTERNAL_IPS = ('127.0.0.1',)
+
+DEBUG_TOOLBAR_CONFIG = {
+    'INTERCEPT_REDIRECTS': False,
+    'HIDE_DJANGO_SQL': True,
+}
+
+PLAYAINFO_CONFIG = {
+    'refresh' : 600,  #refresh data from BMEarth every x seconds
+}
+
+

playainfo/urls.py

 # from django.contrib import admin
 # admin.autodiscover()
 
-urlpatterns = patterns('',
+urlpatterns = patterns('playainfo',
 	(r'^$', 'directory.views.index'),
 	(r'^browse/$', 'directory.views.browse'),
 	(r'^add/$', 'directory.views.add'),

playainfo/utils/__init__.py

Empty file added.

playainfo/utils/logs.py

+# -*- coding: utf-8 -*-
+"""Provides log utility methods, mostly useful for getting and instantiating a log easily.
+
+Example with a rotating log that will get up to 20megs before rolling::
+
+  _loglevels = {'root' : logs.DEBUG, 'keyedcache' : logs.INFO}
+  log = logs.getLogger('settings', level=_loglevels,
+      format="%(asctime)s [%(process)d] %(levelname)s %(name)s: %(message)s",
+      outfile='/var/log/example.log:20000000:20', streaming=True)
+  log.info("Started")
+
+:Authors:
+    - Bruce Kroeze
+"""
+"""
+New BSD License
+===============
+Copyright (c) 2010, Bruce Kroeze <bruce@ecomsmith.com>
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+    * Redistributions of source code must retain the above copyright notice,
+      this list of conditions and the following disclaimer.
+    * Redistributions in binary form must reproduce the above copyright notice,
+      this list of conditions and the following disclaimer in the documentation
+      and/or other materials provided with the distribution.
+    * Neither the name of SolidSiteSolutions LLC, Zefamily LLC nor the names of its
+      contributors may be used to endorse or promote products derived from this
+      software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+"""
+__docformat__="restructuredtext"
+
+
+import os, os.path, logging, logging.config, logging.handlers
+
+DEBUG=logging.DEBUG
+INFO=logging.INFO
+WARN=logging.WARN
+
+_ROOT = None
+_ONCE = {}
+
+def getLogger(target, ini = None, streaming = True, level = logging.DEBUG, outfile = None, format="%(asctime)s %(levelname)s %(name)s: %(message)s"):
+    """Returns the requested logger, loading the base config from the spec'd
+    ini file if not already loaded.
+
+    Note that there can be several nominees for an inifile by delimiting with
+    a semicolon.
+
+    If no root, and no configfile is found, then load from the kwargs:
+
+    streaming - true if errors should print to the console
+    level - default log level
+    format - output format
+    outfile - output filename (Format with a leading "/" for an absolute path, else relative to the current working dir, format like so for RotatingFileHandler fname:maxsize:maxcount)
+    """
+
+    global _ROOT
+
+    if _ROOT is None:
+        if ini:
+            for inifile in ini.split(";"):
+                inifile = resolve_path(inifile)
+                if os.path.exists(inifile):
+                    logging.config.fileConfig(inifile)
+                    _ROOT = logging.root
+                    _ROOT.debug("loaded from %s", inifile)
+
+    if _ROOT is None:
+
+        if isinstance(level, dict):
+            levels = level
+            level = levels.pop('root', logging.DEBUG)
+        else:
+            levels = {}
+
+        _ROOT = logging.root
+        _ROOT.setLevel(level)
+        formatter = logging.Formatter(format)
+
+        if streaming:
+            streamout = logging.StreamHandler()
+            streamout.setLevel(level)
+            streamout.setFormatter(formatter)
+            maybe_add_handler(_ROOT, streamout)
+
+        if outfile:
+            parts = outfile.split(":")
+            if len(parts) == 3:
+                fname, sz, ct = parts
+                fileout = logging.handlers.RotatingFileHandler(fname, maxBytes=sz, backupCount=ct)
+            else:
+                fileout = logging.FileHandler(outfile)
+
+            fileout.setLevel(level)
+            fileout.setFormatter(formatter)
+            maybe_add_handler(_ROOT, fileout)
+
+        for key in levels:
+            l = getLogger(key)
+            l.setLevel(levels[key])
+
+        _ROOT.debug("loaded config")
+
+    return logging.getLogger(target)
+
+def maybe_add_handler(logger, handler):
+    ok = True
+    hc = handler.__class__
+    for h in logger.handlers:
+        if h.__class__ == hc:
+            ok = False
+            break
+    if ok:
+        logger.addHandler(handler)
+
+def resolve_path(fname):
+    """Expands all environment variables and tildes, returning the absolute path."""
+    fname = os.path.expandvars(fname)
+    fname = os.path.expanduser(fname)
+    if fname.startswith("./"):
+        fname = "%s%s" % (os.getcwd(), fname[1:])
+    return os.path.abspath(fname)
+
+def warn_once(logger, key, *args):
+    global _ONCE
+    if not _ONCE.get(key, False):
+        _ONCE[key] = True
+        logger.warn(*args)

playainfo/views.py

Empty file added.
+2010-07-18 05:31:15,159 [20492] DEBUG root: loaded config
+2010-07-18 05:31:15,159 [20492] DEBUG settings: development target
+2010-07-18 05:31:30,690 [20493] DEBUG root: loaded config
+2010-07-18 05:31:30,691 [20493] DEBUG settings: development target
+2010-07-18 12:31:30,800 [20494] DEBUG root: loaded config
+2010-07-18 12:31:30,800 [20494] DEBUG settings: development target
+2010-07-18 05:35:42,977 [20582] DEBUG root: loaded config
+2010-07-18 05:35:42,977 [20582] DEBUG settings: development target
+2010-07-18 12:35:43,078 [20583] DEBUG root: loaded config
+2010-07-18 12:35:43,079 [20583] DEBUG settings: development target
+2010-07-18 12:36:07,579 [20595] DEBUG root: loaded config
+2010-07-18 12:36:07,579 [20595] DEBUG settings: development target
+2010-07-18 05:36:26,181 [20597] DEBUG root: loaded config
+2010-07-18 05:36:26,181 [20597] DEBUG settings: development target
+2010-07-18 05:36:30,368 [20598] DEBUG root: loaded config
+2010-07-18 05:36:30,368 [20598] DEBUG settings: development target
+2010-07-18 05:37:00,528 [20612] DEBUG root: loaded config
+2010-07-18 05:37:00,528 [20612] DEBUG settings: development target