Merge lp:~elachuni/ubuntu-webcatalog/deploy into lp:ubuntu-webcatalog

Proposed by Anthony Lenton
Status: Merged
Approved by: Łukasz Czyżykowski
Approved revision: no longer in the source branch.
Merged at revision: 22
Proposed branch: lp:~elachuni/ubuntu-webcatalog/deploy
Merge into: lp:ubuntu-webcatalog
Diff against target: 749 lines (+437/-167)
13 files modified
.bzrignore (+3/-0)
debian/control (+8/-1)
django_project/config/main.cfg (+98/-0)
django_project/settings.py (+24/-156)
django_project/urls.py (+8/-0)
fabtasks/bootstrap.py (+32/-0)
fabtasks/upgrade_from_package.py (+4/-3)
requirements.txt (+8/-3)
setup.py (+20/-4)
src/webcatalog/context_processors.py (+26/-0)
src/webcatalog/middleware/exception.py (+127/-0)
src/webcatalog/schema.py (+61/-0)
src/webcatalog/wsgi.py (+18/-0)
To merge this branch: bzr merge lp:~elachuni/ubuntu-webcatalog/deploy
Reviewer Review Type Date Requested Status
Canonical ISD hackers Pending
Review via email: mp+65276@code.launchpad.net

Commit message

Added several infrastructure modules and classes.

Description of the change

Overview
========
This branch adds standard ISD modules and classes, prepping for a deployment.

Details
=======
Integration for the following was added in this branch:
 - (django-)configglue
 - django-preflight
 - django-adminaudit
 - django-pgtools
 - Google analytics
 - django_openid_auth (for admin authentication)
 - wsgi-oops

To post a comment you must log in.
Revision history for this message
Łukasz Czyżykowski (lukasz-czyzykowski) wrote :

There are still some RnR/SCA leftovers in the code, lines:
- 54 (mentions devportal),
- 676 (comment mentions sca-deploy)

Also, if you add user=postgres in [default_database], will enable to run against PostgreSQL without the need for one bit of config (and this setting is ignored by SQLite).

Revision history for this message
ISD Branch Mangler (isd-branches-mangler) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

22. By Anthony Lenton

[r=lukasz-czyzykowski] Added several infrastructure modules and classes.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2011-06-07 17:27:12 +0000
+++ .bzrignore 2011-06-21 11:33:32 +0000
@@ -1,8 +1,11 @@
1webcatalog.db1webcatalog.db
2src/ubuntu_webcatalog.egg-info/2src/ubuntu_webcatalog.egg-info/
3virtualenv/3virtualenv/
4django_project/adminaudit
5django_project/django_openid_auth
4django_project/local_settings.py6django_project/local_settings.py
5django_project/static/7django_project/static/
6django_project/media_root_dev/*8django_project/media_root_dev/*
7.backup9.backup
8tags10tags
11branches/
912
=== modified file 'debian/control'
--- debian/control 2011-06-17 15:33:40 +0000
+++ debian/control 2011-06-21 11:33:32 +0000
@@ -18,6 +18,13 @@
18 python-django (>> 1.2.4),18 python-django (>> 1.2.4),
19 python-imaging,19 python-imaging,
20 python-configglue (>> 0.9.1),20 python-configglue (>> 0.9.1),
21 python-django-configglue (>> 0.3)21 python-django-configglue (>> 0.3),
22 python-django-preflight,
23 python-django-adminaudit,
24 python-django-pgtools,
25 python-django-south,
26 python-django-openid-auth,
27 python-wsgi-oops,
28 python-apt
22Description: Ubuntu Web Catalog29Description: Ubuntu Web Catalog
23 Providing web access to the Ubuntu Software Center.30 Providing web access to the Ubuntu Software Center.
2431
=== added directory 'django_project/config'
=== added file 'django_project/config/main.cfg'
--- django_project/config/main.cfg 1970-01-01 00:00:00 +0000
+++ django_project/config/main.cfg 2011-06-21 11:33:32 +0000
@@ -0,0 +1,98 @@
1[__noschema__]
2hostname = webcatalog.staging.ubuntu.com
3
4[django]
5authentication_backends = django_openid_auth.auth.OpenIDBackend
6 django.contrib.auth.backends.ModelBackend
7
8databases = django_databases
9logging = django_logging
10
11debug = true
12media_root = django_project/media_root_dev/
13
14installed_apps = django.contrib.auth
15 django.contrib.contenttypes
16 django.contrib.sessions
17 django.contrib.sites
18 django.contrib.messages
19 django.contrib.staticfiles
20 django.contrib.markup
21 adminaudit
22 django.contrib.admin
23 django_openid_auth
24 django_configglue
25 webcatalog
26 south
27 preflight
28 pgtools
29login_url = /openid/login/
30managers = %(admins)s
31middleware_classes = django.middleware.common.CommonMiddleware
32 django.contrib.sessions.middleware.SessionMiddleware
33 django.middleware.csrf.CsrfViewMiddleware
34 django.contrib.auth.middleware.AuthenticationMiddleware
35 django.contrib.messages.middleware.MessageMiddleware
36 webcatalog.middleware.exception.LogExceptionMiddleware
37fixture_dirs =
38
39secret_key = eepu9Av5ixage9ahhodovahfaiFoorodahf6keip3eichaeW9f
40template_debug = %(debug)s
41time_zone = Europe/London
42media_url = /site_media/
43use_etags = true
44
45template_context_processors = django.contrib.auth.context_processors.auth
46 django.core.context_processors.debug
47 django.core.context_processors.i18n
48 django.core.context_processors.media
49 django.core.context_processors.static
50 django.contrib.messages.context_processors.messages
51 webcatalog.context_processors.google_analytics_id
52
53template_dirs = django_project/templates/
54static_root = ./django_project/static/
55static_url = /assets/
56
57# Django-1.1 backwards compatibility
58database_engine = sqlite3
59database_name = webcatalog.db
60
61
62[django_databases]
63default = default_database
64
65[default_database]
66engine = sqlite3
67name = webcatalog.db
68
69[django_logging]
70loggers = django_loggers
71version = 1
72disable_existing_loggers = False
73
74[django_loggers]
75
76[openid]
77openid_sso_server_url = https://login.staging.ubuntu.com
78openid_create_users = true
79openid_update_details_from_sreg = true
80openid_launchpad_teams_mapping = openid_team_mapping
81
82
83[openid_team_mapping]
84# Structure here is: LP Team = Django Group
85canonical-isd-hackers = admin
86canonical-losas = admin
87
88[oops]
89oops_dir = /srv/%(hostname)s/staging-logs/www-oops
90
91[webcatalog]
92serve_site_media = True
93sca_api_url = https://sc.staging.ubuntu.com/api/2.0/
94disk_apt_cache_location = /tmp/webcat_cache
95
96[google]
97google_analytics_id = UA-1018242-24
98
099
=== modified file 'django_project/settings.py'
--- django_project/settings.py 2011-06-17 17:48:07 +0000
+++ django_project/settings.py 2011-06-21 11:33:32 +0000
@@ -1,156 +1,24 @@
1# Django settings for django_project project.1from __future__ import absolute_import
22
3DEBUG = True3import os.path
4TEMPLATE_DEBUG = DEBUG4
55from configglue.pyschema import SchemaConfigParser
6ADMINS = (6from django_configglue.utils import update_settings
7 # ('Your Name', 'your_email@example.com'),7
8)8from webcatalog.schema import WebCatalogSchema
99
10MANAGERS = ADMINS10
1111# get absolute path for config files
12DATABASES = {12current_dir = os.path.dirname(os.path.abspath(__file__))
13 'default': {13config_files = map(lambda x: os.path.join(current_dir, x),
14 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.14 ['config/main.cfg', '../../local_config/local.cfg',
15 'NAME': 'webcatalog.db', # Or path to database file if using sqlite3.15 'local.cfg'])
16 'USER': '', # Not used with sqlite3.16
17 'PASSWORD': '', # Not used with sqlite3.17# parse config files
18 'HOST': '', # Set to empty string for localhost. Not used with sqlite3.18parser = SchemaConfigParser(WebCatalogSchema())
19 'PORT': '', # Set to empty string for default. Not used with sqlite3.19parser.read(config_files)
20 }20update_settings(parser, locals())
21}21
2222# keep parser reference
23# Local time zone for this installation. Choices can be found here:23__CONFIGGLUE_PARSER__ = parser
24# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name24
25# although not all choices may be available on all operating systems.
26# On Unix systems, a value of None will cause Django to use the same
27# timezone as the operating system.
28# If running in a Windows environment this must be set to the same as your
29# system time zone.
30TIME_ZONE = 'America/Chicago'
31
32# Language code for this installation. All choices can be found here:
33# http://www.i18nguy.com/unicode/language-identifiers.html
34LANGUAGE_CODE = 'en-us'
35
36SITE_ID = 1
37
38# If you set this to False, Django will make some optimizations so as not
39# to load the internationalization machinery.
40USE_I18N = True
41
42# If you set this to False, Django will not format dates, numbers and
43# calendars according to the current locale
44USE_L10N = True
45
46# Absolute filesystem path to the directory that will hold user-uploaded files.
47# Example: "/home/media/media.lawrence.com/media/"
48MEDIA_ROOT = './django_project/media_root_dev/'
49
50# URL that handles the media served from MEDIA_ROOT. Make sure to use a
51# trailing slash.
52# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
53MEDIA_URL = '/site_media/'
54
55# Absolute path to the directory static files should be collected to.
56# Don't put anything in this directory yourself; store your static files
57# in apps' "static/" subdirectories and in STATICFILES_DIRS.
58# Example: "/home/media/media.lawrence.com/static/"
59STATIC_ROOT = './django_project/static/'
60
61# URL prefix for static files.
62# Example: "http://media.lawrence.com/static/"
63STATIC_URL = '/assets/'
64
65# URL prefix for admin static files -- CSS, JavaScript and images.
66# Make sure to use a trailing slash.
67# Examples: "http://foo.com/static/admin/", "/static/admin/".
68ADMIN_MEDIA_PREFIX = '/assets/admin/'
69
70# Additional locations of static files
71STATICFILES_DIRS = (
72 # Put strings here, like "/home/html/static" or "C:/www/django/static".
73 # Always use forward slashes, even on Windows.
74 # Don't forget to use absolute paths, not relative paths.
75)
76
77# List of finder classes that know how to find static files in
78# various locations.
79STATICFILES_FINDERS = (
80 'django.contrib.staticfiles.finders.FileSystemFinder',
81 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
82# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
83)
84
85# Make this unique, and don't share it with anybody.
86SECRET_KEY = '5t7w7uzf&_^goikwn)!g3lmn07gw7x&193uvs#irw4h=1#*%%-'
87
88# List of callables that know how to import templates from various sources.
89TEMPLATE_LOADERS = (
90 'django.template.loaders.filesystem.Loader',
91 'django.template.loaders.app_directories.Loader',
92# 'django.template.loaders.eggs.Loader',
93)
94
95MIDDLEWARE_CLASSES = (
96 'django.middleware.common.CommonMiddleware',
97 'django.contrib.sessions.middleware.SessionMiddleware',
98 'django.middleware.csrf.CsrfViewMiddleware',
99 'django.contrib.auth.middleware.AuthenticationMiddleware',
100 'django.contrib.messages.middleware.MessageMiddleware',
101)
102
103ROOT_URLCONF = 'django_project.urls'
104
105TEMPLATE_DIRS = (
106 './django_project/templates',
107)
108
109INSTALLED_APPS = (
110 'django.contrib.auth',
111 'django.contrib.contenttypes',
112 'django.contrib.sessions',
113 'django.contrib.sites',
114 'django.contrib.messages',
115 'django.contrib.staticfiles',
116 'django.contrib.admin',
117 'south',
118 'webcatalog',
119)
120
121# A sample logging configuration. The only tangible logging
122# performed by this configuration is to send an email to
123# the site admins on every HTTP 500 error.
124# See http://docs.djangoproject.com/en/dev/topics/logging for
125# more details on how to customize your logging configuration.
126LOGGING = {
127 'version': 1,
128 'disable_existing_loggers': False,
129 'handlers': {
130 'mail_admins': {
131 'level': 'ERROR',
132 'class': 'django.utils.log.AdminEmailHandler'
133 }
134 },
135 'loggers': {
136 'django.request': {
137 'handlers': ['mail_admins'],
138 'level': 'ERROR',
139 'propagate': True,
140 },
141 }
142}
143
144########################
145# Ubuntu Web Catalog specific settings:
146########################
147
148# Strictly for use in our dev environment:
149SERVE_SITE_MEDIA = True
150SCA_API_URL = 'https://sc.staging.ubuntu.com/api/2.0/'
151DISK_APT_CACHE_LOCATION = '/tmp/webcat_cache'
152
153try:
154 from local_settings import *
155except ImportError:
156 pass
15725
=== removed directory 'django_project/templates'
=== modified file 'django_project/urls.py'
--- django_project/urls.py 2011-05-06 15:03:41 +0000
+++ django_project/urls.py 2011-06-21 11:33:32 +0000
@@ -15,15 +15,23 @@
15# You should have received a copy of the GNU Affero General Public License15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.16# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
18import preflight
19import adminaudit
18from django.conf.urls.defaults import patterns, include, url20from django.conf.urls.defaults import patterns, include, url
19from django.conf import settings21from django.conf import settings
20from django.contrib import admin22from django.contrib import admin
23from django.views.generic.simple import redirect_to
2124
22admin.autodiscover()25admin.autodiscover()
26preflight.autodiscover()
27adminaudit.audit_install()
2328
24urlpatterns = patterns('',29urlpatterns = patterns('',
25 url(r'^cat/', include('webcatalog.urls')),30 url(r'^cat/', include('webcatalog.urls')),
26 url(r'^admin/', include(admin.site.urls)),31 url(r'^admin/', include(admin.site.urls)),
32 (r'^preflight/$', include('preflight.urls')),
33 url(r'^$', redirect_to, {'url': '/cat/'}),
34
27)35)
2836
29if settings.SERVE_SITE_MEDIA:37if settings.SERVE_SITE_MEDIA:
3038
=== modified file 'fabtasks/bootstrap.py'
--- fabtasks/bootstrap.py 2011-05-06 21:00:11 +0000
+++ fabtasks/bootstrap.py 2011-06-21 11:33:32 +0000
@@ -52,13 +52,45 @@
52 if not os.path.exists(link_name):52 if not os.path.exists(link_name):
53 os.symlink(os.path.abspath(source), link_name)53 os.symlink(os.path.abspath(source), link_name)
5454
55def _get_or_pull_bzr_branch(repo, name, revision=None):
56 if revision is None:
57 revision = ""
58 else:
59 revision = "--revision={0}".format(revision)
60 if not os.path.exists("branches"):
61 os.mkdir('branches')
62 branch_path = os.path.join("branches", name)
63 if os.path.exists(branch_path):
64 local("rm -r {0}".format(branch_path))
65 local("bzr branch {0} {1} {2}".format(
66 revision, repo, branch_path), capture=False)
67
68def pull_required_branches():
69 _get_or_pull_bzr_branch(
70 "lp:django-adminaudit",
71 "django-adminaudit")
72 _symlink(
73 "branches/django-adminaudit/adminaudit",
74 "django_project/adminaudit")
75 _get_or_pull_bzr_branch(
76 "lp:~django-openid-auth/django-openid-auth/trunk",
77 "django-openid-auth",
78 revision=79)
79 _symlink(
80 "branches/django-openid-auth/django_openid_auth",
81 "django_project/django_openid_auth")
5582
56def bootstrap():83def bootstrap():
57 virtualenv_create()84 virtualenv_create()
58 install_requirements()85 install_requirements()
86 pull_required_branches()
5987
6088
61def clean():89def clean():
90 local("rm -rf branches/")
62 local("rm -rf virtualenv/")91 local("rm -rf virtualenv/")
63 local("rm -rf src/ubuntu_webcatalog.egg-info")92 local("rm -rf src/ubuntu_webcatalog.egg-info")
64 local("rm -f webcatalog.db")93 local("rm -f webcatalog.db")
94 links = ("adminaudit", "django_openid_auth")
95 for link in links:
96 local("rm -f django_project/{0}".format(link))
6597
=== modified file 'fabtasks/upgrade_from_package.py'
--- fabtasks/upgrade_from_package.py 2011-04-05 02:19:30 +0000
+++ fabtasks/upgrade_from_package.py 2011-06-21 11:33:32 +0000
@@ -69,7 +69,7 @@
69 recipe = dedent("""\69 recipe = dedent("""\
70 # bzr-builder format 0.2 deb-version {debupstream}-0~{revno}+{time}70 # bzr-builder format 0.2 deb-version {debupstream}-0~{revno}+{time}
71 .""")71 .""")
72 recipe_path = os.path.join(build_dir, 'rnr.recipe')72 recipe_path = os.path.join(build_dir, 'uwc.recipe')
73 with open(recipe_path, 'w+') as recipe_file:73 with open(recipe_path, 'w+') as recipe_file:
74 recipe_file.write(recipe)74 recipe_file.write(recipe)
7575
@@ -92,7 +92,7 @@
9292
93def migrate_database(config_dir=None):93def migrate_database(config_dir=None):
94 if config_dir is None:94 if config_dir is None:
95 # By default, the rnr config directory is assumed to be95 # By default, the uwc config directory is assumed to be
96 # /home/username/django_project.96 # /home/username/django_project.
97 config_dir = 'django_project'97 config_dir = 'django_project'
98 run(config_dir + '/manage.py syncdb --migrate')98 run(config_dir + '/manage.py syncdb --migrate')
@@ -133,7 +133,8 @@
133 run("cp %s/local.cfg %s" % (backup_dir, config_dir))133 run("cp %s/local.cfg %s" % (backup_dir, config_dir))
134 else:134 else:
135 # Create a local.cfg on the server from our template.135 # Create a local.cfg on the server from our template.
136 local_file, local_path = tempfile.mkstemp()136 local_fd, local_path = tempfile.mkstemp()
137 local_file = os.fdopen(local_fd, 'w')
137 local_file.write(LOCAL_CONFIG)138 local_file.write(LOCAL_CONFIG)
138 local_file.close()139 local_file.close()
139 put(local_path, "%s/local.cfg" % config_dir)140 put(local_path, "%s/local.cfg" % config_dir)
140141
=== modified file 'requirements.txt'
--- requirements.txt 2011-06-17 14:44:34 +0000
+++ requirements.txt 2011-06-21 11:33:32 +0000
@@ -1,7 +1,12 @@
1configglue==0.10
2coverage
1django3django
4django-configglue==0.4
5-e bzr+http://bazaar.launchpad.net/~canonical-isd-hackers/django-pgtools/trunk
6django-preflight
2mock7mock
8PIL
9python-debian
10python-openid
3setuptools11setuptools
4south12south
5python-debian
6PIL
7coverage
813
=== modified file 'setup.py'
--- setup.py 2011-04-05 02:19:30 +0000
+++ setup.py 2011-06-21 11:33:32 +0000
@@ -1,5 +1,24 @@
1import os
1from setuptools import setup, find_packages2from setuptools import setup, find_packages
23
4def find_packages_data(start_dir):
5 packages = {}
6 for package_name in os.listdir(start_dir):
7 package_dir = os.path.join(start_dir, package_name)
8 if os.path.exists(os.path.join(package_dir, '__init__.py')):
9 files = []
10 packages[package_name] = files
11 for dirpath, dirnames, filenames in os.walk(package_dir):
12 dirpath = dirpath[len(package_dir) + 1:]
13 for filename in filenames:
14 ext = os.path.splitext(filename)[1]
15 if ext not in ('.py', '.pyc', '.pyo'):
16 file_path = os.path.join(dirpath, filename)
17 full_file_path = os.path.join(package_dir, file_path)
18 if os.path.isfile(full_file_path):
19 files.append(file_path)
20 return packages
21
3setup(22setup(
4 name = "ubuntu-webcatalog",23 name = "ubuntu-webcatalog",
5 version = "0.1",24 version = "0.1",
@@ -18,9 +37,6 @@
18 'django',37 'django',
19 'south',38 'south',
20 ],39 ],
21 package_data = {40 package_data = find_packages_data('src'),
22 'webcatalog': [
23 ],
24 },
25)41)
2642
2743
=== added file 'src/webcatalog/context_processors.py'
--- src/webcatalog/context_processors.py 1970-01-01 00:00:00 +0000
+++ src/webcatalog/context_processors.py 2011-06-21 11:33:32 +0000
@@ -0,0 +1,26 @@
1# -*- coding: utf-8 -*-
2# This file is part of the Ubuntu Web Catalog
3# Copyright (C) 2011 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Affero General Public License as
7# published by the Free Software Foundation, either version 3 of the
8# License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Context processors web catalog app."""
19
20from django.conf import settings
21
22def google_analytics_id(request):
23 """Adds the google analytics id to the context if it's present."""
24 return {
25 'google_analytics_id': getattr(settings, 'GOOGLE_ANALYTICS_ID', None),
26 }
027
=== added directory 'src/webcatalog/middleware'
=== added file 'src/webcatalog/middleware/__init__.py'
=== added file 'src/webcatalog/middleware/exception.py'
--- src/webcatalog/middleware/exception.py 1970-01-01 00:00:00 +0000
+++ src/webcatalog/middleware/exception.py 2011-06-21 11:33:32 +0000
@@ -0,0 +1,127 @@
1# -*- coding: utf-8 -*-
2# This file is part of the Ubuntu Web Catalog
3# Copyright (C) 2011 Canonical Ltd.
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Affero General Public License as
7# published by the Free Software Foundation, either version 3 of the
8# License, or (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU Affero General Public License for more details.
14#
15# You should have received a copy of the GNU Affero General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18"""Exception logging middleware for the web catalog app."""
19
20import logging
21import re
22import sys
23import traceback
24
25from django.conf import settings
26from django.db import connection
27from django.views import debug
28from django.views.debug import ExceptionReporter
29
30default_hidden_settings = \
31 'SECRET|PASSWORD|PROFANITIES_LIST|PRIVATE|secret|password|private'
32hidden_settings = getattr(settings, 'HIDDEN_SETTINGS', default_hidden_settings)
33debug.HIDDEN_SETTINGS = re.compile(hidden_settings)
34
35
36class SanitizedExceptionReporter(ExceptionReporter):
37 def __init__(self, request, exc_type, exc_value, tb, is_email=None):
38 request = self.sanitize_request(request)
39 ExceptionReporter.__init__(self, request,
40 exc_type, exc_value, tb)
41
42 def get_traceback_frames(self):
43 # This method is taken from Django's views.debug.ExceptionReporter.
44 # Please see the license file in the third-party/django directory.
45 frames = []
46 tb = self.tb
47 while tb is not None:
48 # support for __traceback_hide__ which is used by a few libraries
49 # to hide internal frames.
50 if tb.tb_frame.f_locals.get('__traceback_hide__'):
51 tb = tb.tb_next
52 continue
53 filename = tb.tb_frame.f_code.co_filename
54 function = tb.tb_frame.f_code.co_name
55 lineno = tb.tb_lineno - 1
56 loader = tb.tb_frame.f_globals.get('__loader__')
57 module_name = tb.tb_frame.f_globals.get('__name__')
58 pre_context_lineno, pre_context, context_line, post_context = \
59 self._get_lines_from_file(filename, lineno, 7, loader,
60 module_name)
61 if pre_context_lineno is not None:
62 frames.append({
63 'tb': tb,
64 'filename': filename,
65 'function': function,
66 'lineno': lineno + 1,
67 # The only diff in this method: call self.sanitize_vars()
68 'vars': self.sanitize_vars(tb.tb_frame.f_locals.items()),
69 'id': id(tb),
70 'pre_context': pre_context,
71 'context_line': context_line,
72 'post_context': post_context,
73 'pre_context_lineno': pre_context_lineno + 1,
74 })
75 tb = tb.tb_next
76
77 if not frames:
78 frames = [{
79 'filename': '&lt;unknown&gt;',
80 'function': '?',
81 'lineno': '?',
82 'context_line': '???',
83 }]
84
85 return frames
86
87 # These two methods are new -- Sanitize the request's POST and GET dicts,
88 # and local variables in frames, not only Django's settings.
89 def sanitize_vars(self, items):
90 sanitized = []
91 for item in items:
92 if debug.HIDDEN_SETTINGS.search(item[0]):
93 sanitized.append((item[0], '********'))
94 else:
95 sanitized.append(item)
96 return sanitized
97
98 def sanitize_request(self, request):
99 """Remove sensitive from the request before it is displayed"""
100 dup_post = request.POST.copy()
101 for key in request.POST.iterkeys():
102 if debug.HIDDEN_SETTINGS.search(key):
103 dup_post[key] = '********'
104 request.POST = dup_post
105 dup_get = request.GET.copy()
106 for key in request.GET.iterkeys():
107 if debug.HIDDEN_SETTINGS.search(key):
108 dup_get[key] = '********'
109 request.GET = dup_get
110 return request
111
112
113debug.ExceptionReporter = SanitizedExceptionReporter
114
115
116class LogExceptionMiddleware(object):
117 def process_exception(self, request, exception):
118 """Log the traceback, so that it can be kept in the oops file"""
119 reporter = SanitizedExceptionReporter(request, *sys.exc_info())
120 template_debug = settings.TEMPLATE_DEBUG
121 settings.TEMPLATE_DEBUG = True
122 try:
123 logging.warn(traceback.format_exc())
124 for query in connection.queries:
125 logging.warn("time: %(time)s sql: %(sql)s" % query)
126 finally:
127 settings.TEMPLATE_DEBUG = template_debug
0128
=== added file 'src/webcatalog/schema.py'
--- src/webcatalog/schema.py 1970-01-01 00:00:00 +0000
+++ src/webcatalog/schema.py 2011-06-21 11:33:32 +0000
@@ -0,0 +1,61 @@
1import django
2
3from configglue.pyschema import ConfigSection
4from configglue.pyschema.options import (BoolConfigOption, StringConfigOption,
5 LinesConfigOption, IntConfigOption, DictConfigOption, TupleConfigOption)
6from django_configglue.schema import (
7 Django112Schema,
8 schemas,
9 )
10
11# Currently we've updated to latest configglue/django-configglue
12# but they remove a registered schema for django 1.1.1, which is
13# the currently installed django version on our servers, resulting in:
14# http://razorgirl.info/job/software-center-agent-deploy/23/console
15# So we register the 112 schema to match until we upgrade. Once we
16# upgraded this should still work without updating (as the version
17# will be 1.3).
18schemas.register(Django112Schema, '1.1.1')
19DjangoSchema = schemas.get(django.get_version())
20
21
22class WebCatalogSchema(DjangoSchema):
23 """Config options specific to the web catalog."""
24 # default section
25 extra_pythonpath = LinesConfigOption(item=StringConfigOption())
26 pgconnect_timeout = IntConfigOption(default=10)
27 should_serve_https = BoolConfigOption()
28
29 oops = ConfigSection()
30 oops.oops_dir = StringConfigOption(help='Absolute path to the directory'
31 ' oops reports will be stored in')
32
33 openid = ConfigSection()
34 openid.openid_sso_server_url = StringConfigOption()
35 openid.openid_create_users = BoolConfigOption()
36 openid.openid_update_details_from_sreg = BoolConfigOption()
37 openid.openid_launchpad_teams_mapping = DictConfigOption()
38 openid.openid_sreg_extra_fields = LinesConfigOption(
39 item=StringConfigOption())
40
41 webcatalog = ConfigSection()
42 webcatalog.serve_site_media = BoolConfigOption(default=True)
43 webcatalog.sca_api_url = StringConfigOption()
44 webcatalog.disk_apt_cache_location = StringConfigOption()
45
46 google = ConfigSection()
47 google.google_analytics_id = StringConfigOption()
48
49 logging = ConfigSection()
50 logging.webapp_logging_config = StringConfigOption()
51
52 # preflight
53 preflight = ConfigSection()
54 preflight.preflight_base_template = StringConfigOption(
55 default="webcatalog/base.html")
56
57 #adminaudit
58 adminaudit_emails_recipients = LinesConfigOption(
59 item=StringConfigOption())
60 adminaudit_summary_subject = StringConfigOption(
61 default='Admin Audit Summary')
062
=== renamed directory 'django_project/templates/light' => 'src/webcatalog/templates/light'
=== added file 'src/webcatalog/wsgi.py'
--- src/webcatalog/wsgi.py 1970-01-01 00:00:00 +0000
+++ src/webcatalog/wsgi.py 2011-06-21 11:33:32 +0000
@@ -0,0 +1,18 @@
1import logging.config
2import platform
3
4from canonical.oops.serializer import OOPSRFC822Serializer
5from canonical.oops.wsgi import OopsWare
6from django.core.handlers.wsgi import WSGIHandler
7from django.conf import settings
8
9def make_app():
10 """Encapsulate our webcatalog handler in an OOPS app for error reporting."""
11 default_id = ''.join(x for x in platform.node() if x.isalpha())
12 appserver_id = getattr(settings, 'APPSERVER_ID', default_id)
13 logging.config.fileConfig(settings.WEBAPP_LOGGING_CONFIG)
14 oops_dir = getattr(settings, 'OOPS_DIR', '/tmp')
15 oops_app = OopsWare(WSGIHandler(), oops_dir=oops_dir,
16 key=appserver_id, hide_meta=True)
17 oops_app.serial = OOPSRFC822Serializer(appserver_id, oops_dir, None)
18 return oops_app

Subscribers

People subscribed via source and target branches