Skip to content

Commit

Permalink
Don't require config via environment variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
carljm committed May 19, 2012
1 parent 7e4cfb0 commit 722374a
Show file tree
Hide file tree
Showing 143 changed files with 265 additions and 252 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
*.pyc *.pyc
htmlcov/ htmlcov/
datazilla/settings/local.py
7 changes: 4 additions & 3 deletions datazilla/controller/admin/populate_summary_cache.py
@@ -1,11 +1,12 @@
import os import os
import sys import sys
import time
import datetime
import json import json
import memcache import memcache
import zlib import zlib


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "datazilla.settings.base")
from django.conf import settings

from optparse import OptionParser from optparse import OptionParser
from datazilla.model.DatazillaModel import DatazillaModel from datazilla.model.DatazillaModel import DatazillaModel


Expand All @@ -24,7 +25,7 @@ def cacheTestSummaries(project):
gm = DatazillaModel(project, 'graphs.json') gm = DatazillaModel(project, 'graphs.json')
dataIter = gm.getAllSummaryCache() dataIter = gm.getAllSummaryCache()


mc = memcache.Client([os.environ["DATAZILLA_MEMCACHED"]], debug=0) mc = memcache.Client([settings.DATAZILLA_MEMCACHED], debug=0)


for d in dataIter: for d in dataIter:
for data in d: for data in d:
Expand Down
22 changes: 8 additions & 14 deletions datazilla/model/sql/model.py
Expand Up @@ -7,6 +7,8 @@
import os import os
import re import re


from django.conf import settings

from datasource.bases.BaseHub import BaseHub from datasource.bases.BaseHub import BaseHub
from datasource.hubs.MySQL import MySQL from datasource.hubs.MySQL import MySQL


Expand All @@ -24,16 +26,11 @@ def loadvars():
##### #####
if not Model.projectHub: if not Model.projectHub:


Model.DATAZILLA_DATABASE_NAME = \ Model.DATAZILLA_DATABASE_NAME = settings.DATAZILLA_DATABASE_NAME
os.environ["DATAZILLA_DATABASE_NAME"] Model.DATAZILLA_DATABASE_USER = settings.DATAZILLA_DATABASE_USER
Model.DATAZILLA_DATABASE_USER = \ Model.DATAZILLA_DATABASE_PASSWORD = settings.DATAZILLA_DATABASE_PASSWORD
os.environ["DATAZILLA_DATABASE_USER"] Model.DATAZILLA_DATABASE_HOST = settings.DATAZILLA_DATABASE_HOST
Model.DATAZILLA_DATABASE_PASSWORD = \ Model.DATAZILLA_DATABASE_PORT = settings.DATAZILLA_DATABASE_PORT
os.environ["DATAZILLA_DATABASE_PASSWORD"]
Model.DATAZILLA_DATABASE_HOST = \
os.environ["DATAZILLA_DATABASE_HOST"]
Model.DATAZILLA_DATABASE_PORT = \
os.environ["DATAZILLA_DATABASE_PORT"]


#### ####
#Configuration of datasource hub: #Configuration of datasource hub:
Expand Down Expand Up @@ -92,10 +89,7 @@ def __init__(self, project, sqlFileName):
self.project = project self.project = project
self.sqlFileName = sqlFileName self.sqlFileName = sqlFileName


try: self.DEBUG = settings.DEBUG
self.DEBUG = os.environ["DATAZILLA_DEBUG"] is not None
except KeyError:
self.DEBUG = False


##### #####
#Set the hub to the requested project #Set the hub to the requested project
Expand Down
Empty file added datazilla/settings/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions datazilla/settings/appengine.py
@@ -0,0 +1,5 @@
TEMPLATE_LOADERS = [
'django.template.loaders.filesystem.load_template_source',
]

MIDDLEWARE_CLASSES = []
175 changes: 175 additions & 0 deletions datazilla/settings/base.py
@@ -0,0 +1,175 @@
# Django settings for webapp project.
import os, posixpath

USE_APP_ENGINE = "APPENGINE_RUNTIME" in os.environ

# These settings can all be optionally set via env vars, or in local.py:

# Set Database connectivity via environment
DATAZILLA_DATABASE_NAME = os.environ.get("DATAZILLA_DATABASE_NAME", "")
DATAZILLA_DATABASE_USER = os.environ.get("DATAZILLA_DATABASE_USER", "")
DATAZILLA_DATABASE_PASSWORD = os.environ.get("DATAZILLA_DATABASE_PASSWORD", "")
DATAZILLA_DATABASE_HOST = os.environ.get("DATAZILLA_DATABASE_HOST", "")
DATAZILLA_DATABASE_PORT = os.environ.get("DATAZILLA_DATABASE_PORT", "")

DATAZILLA_MEMCACHED = os.environ.get("DATAZILLA_MEMCACHED", "")

# Set base URL via the environment
DATAZILLA_URL = os.environ.get("DATAZILLA_URL", "/")

DEBUG = os.environ.get("DATAZILLA_DEBUG") is not None

# Make this unique, and don't share it with anybody.
SECRET_KEY = os.environ.get("DATAZILLA_DJANGO_SECRET_KEY", "")


ROOT = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
path = lambda *a: os.path.join(ROOT, *a)

ADMINS = [
("jeads", "jeads@mozilla.com"),
("Carl Meyer", "cmeyer@mozilla.com"),
]

MANAGERS = ADMINS

# 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.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = "America/Los_Angeles"

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = "en-us"

SITE_ID = 1

# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = False

# 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 static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
#STATIC_ROOT = path("datazilla/webapp/collected-assets")

# Additional locations of static files
STATICFILES_DIRS = [
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
path("datazilla/webapp/static"),
]

# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
# "django.contrib.staticfiles.finders.DefaultStorageFinder",
]

# 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",
]

MIDDLEWARE_CLASSES = [
"django.middleware.common.CommonMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
]

ROOT_URLCONF = "datazilla.webapp.urls"

TEMPLATE_DIRS = [
path("datazilla/webapp/templates")
]

INSTALLED_APPS = [
#"django.contrib.auth",
#"django.contrib.contenttypes",
#"django.contrib.sessions",
#"django.contrib.sites",
#"django.contrib.messages",
#"django.contrib.staticfiles",
# Uncomment the next line to enable the admin:
# "django.contrib.admin",
# Uncomment the next line to enable admin documentation:
# "django.contrib.admindocs",

"datazilla.webapp.apps.datazilla",
]

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"mail_admins": {
"level": "ERROR",
"class": "django.utils.log.AdminEmailHandler"
}
},
"loggers": {
"django.request": {
"handlers": ["mail_admins"],
"level": "ERROR",
"propagate": True,
},
}
}

# Import app-engine specific settings, if appropriate
if USE_APP_ENGINE:
from .appengine import *

# Import local settings to add to/override the above
try:
from .local import *
except ImportError:
pass

# Derived settings, whose values should vary with local settings:

TEMPLATE_DEBUG = DEBUG

# The URL static assets will be served at.
STATIC_URL = posixpath.join(DATAZILLA_URL, "static")

CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.memcached.MemcachedCache",
"LOCATION": DATAZILLA_MEMCACHED,
}
}

if not USE_APP_ENGINE:
DATABASES = {
"default": {
"ENGINE" : "django.db.backends.mysql", # Add "postgresql_psycopg2", "postgresql", "mysql", "sqlite3" or "oracle".
"NAME" : DATAZILLA_DATABASE_NAME, # Or path to database file if using sqlite3.
"USER" : DATAZILLA_DATABASE_USER, # Not used with sqlite3.
"PASSWORD" : DATAZILLA_DATABASE_PASSWORD, # Not used with sqlite3.
"HOST" : DATAZILLA_DATABASE_HOST, # Set to empty string for localhost. Not used with sqlite3.
"PORT" : DATAZILLA_DATABASE_PORT, # Set to empty string for default. Not used with sqlite3.
}
}

26 changes: 26 additions & 0 deletions datazilla/settings/local.sample.py
@@ -0,0 +1,26 @@
"""
Sample Datazilla local-settings.
Copy this file to ``local.py`, then uncomment and modify the below settings as
needed for your configuration.
"""
import os

# Database connection parameters
DATAZILLA_DATABASE_NAME = os.environ.get("DATAZILLA_DATABASE_NAME", "")
DATAZILLA_DATABASE_USER = os.environ.get("DATAZILLA_DATABASE_USER", "")
DATAZILLA_DATABASE_PASSWORD = os.environ.get("DATAZILLA_DATABASE_PASSWORD", "")
DATAZILLA_DATABASE_HOST = os.environ.get("DATAZILLA_DATABASE_HOST", "")
DATAZILLA_DATABASE_PORT = os.environ.get("DATAZILLA_DATABASE_PORT", "")

DATAZILLA_MEMCACHED = os.environ.get("DATAZILLA_MEMCACHED", "")

# base URL
DATAZILLA_URL = os.environ.get("DATAZILLA_URL", "/")

# This should always be False in production
DEBUG = os.environ.get("DATAZILLA_DEBUG") is not None

# Make this unique, and don't share it with anybody.
SECRET_KEY = os.environ["DATAZILLA_DJANGO_SECRET_KEY"]
4 changes: 2 additions & 2 deletions datazilla/webapp/conf/etc/nginx/conf.d/datazilla.conf
Expand Up @@ -4,10 +4,10 @@ server {
access_log /var/log/nginx/datazilla.access.log; access_log /var/log/nginx/datazilla.access.log;
error_log /var/log/nginx/datazilla.error.log; error_log /var/log/nginx/datazilla.error.log;


location ^~ /media/ { location ^~ /static/ {
index index.html index index.html
client_max_body_size 1G; client_max_body_size 1G;
alias /usr/local/datazilla/datazilla/webapp/media/; alias /usr/local/datazilla/datazilla/webapp/static/;
} }


location ^~ /htmlcov { location ^~ /htmlcov {
Expand Down

0 comments on commit 722374a

Please sign in to comment.