1
# Copyright 2005-2011 Canonical Ltd. All rights reserved.
3
# This program is free software: you can redistribute it and/or modify
4
# it under the terms of the GNU Affero General Public License as published by
5
# the Free Software Foundation, either version 3 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU Affero General Public License for more details.
13
# You should have received a copy of the GNU Affero General Public License
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
from datetime import datetime, timedelta
20
from django.conf import settings
21
from django.http import Http404, HttpResponseRedirect
22
from django.shortcuts import render_to_response
24
from oopstools.oops import dbsummaries
25
from oopstools.oops.helpers import parsedate
26
from oopstools.oops.models import Oops, Report
27
from oopstools.oops.prefixloader import PrefixLoader
28
from oopstools.oops.oopsstore import OopsStore, OopsNotFound
32
# Check both the given ID and a fixed-up version of it.
33
oopsids = [request.GET.get('oopsid', '')]
34
oopsid_fixed = oopsids[0].upper()
35
if not oopsid_fixed.startswith('OOPS-'):
36
oopsid_fixed = 'OOPS-' + oopsid_fixed
37
if oopsid_fixed not in oopsids:
38
oopsids.append(oopsid_fixed)
40
# Check each ID in both the database and filesystem
41
# (should maybe have an API option for this, instead of doing it manually?)
43
for oopsid in oopsids:
45
oops = Oops.objects.get(oopsid__exact=oopsid)
47
except Oops.DoesNotExist:
48
# Try to find the OOPS report in the filesystem.
49
store = OopsStore(settings.OOPSDIR)
51
oops = store.find_oops(oopsid)
56
if oops and oops.exists():
62
tmpl = settings.INDEX_TEMPLATE
63
reports = Report.objects.filter(active=True)
65
'userdata': request.GET,
68
return render_to_response(tmpl, dictionary=data)
72
bug_number = request.POST.get('bug_number', '')
73
oopsid = request.POST.get('oopsid')
74
oops = Oops.objects.get(oopsid__exact=oopsid)
75
oops.oopsinfestation.bug = bug_number
76
oops.oopsinfestation.save()
77
return HttpResponseRedirect('/oops.py/?oopsid=%s' % oopsid)
80
def prefixloader(request):
82
if request.method == "POST":
83
prefixloader = PrefixLoader(settings.LAZR_CONFIG)
84
prefixes = prefixloader.load_prefixes_into_database()
86
return render_to_response("prefixloader.html", dictionary={
87
"LAZR_CONFIG": settings.LAZR_CONFIG,
88
"prefixes": prefixes})
91
def report(request, report_name):
93
r = Report.objects.get(name=report_name, active=True)
94
except Report.DoesNotExist:
97
# Since reports are created by an external script, let's build URLs
98
# for the past ten days.
99
now = datetime.utcnow()
101
for day in range(1, 11):
102
dates.append(now - timedelta(day))
106
'SUMMARY_URI': settings.SUMMARY_URI,
108
return render_to_response("report.html", dictionary=data)
111
def report_day_view(request, report_name, year, month, day):
112
filename = '-'.join([report_name, year, month, day]) + '.html'
113
# Try to find out if the report exists already.
114
if os.path.exists(os.path.join(settings.SUMMARY_DIR, filename)):
115
url = settings.SUMMARY_URI + '/' + filename
116
return HttpResponseRedirect(url)
118
# Build it dynamically. This might take some time...
120
report = Report.objects.get(name=report_name, active=True)
121
except Report.DoesNotExist:
124
summary_class = getattr(dbsummaries, report.get_summary_display())
125
prefixes = [prefix.value for prefix in report.prefixes.all()]
126
start = end = parsedate("-".join([year, month, day]))
127
# XXX Unpack the data needed from the summary object to avoid
128
# doing processing in the template.
129
# There's probably a better way of doing this.
130
summary = summary_class(start, end, prefixes)
131
durations_section = summary.get_section_by_id('durations')
132
stmt_counts_section = summary.get_section_by_id(
134
timeout_counts = summary.get_section_by_id(
135
'time-out-counts-by-page-id')
137
'ROOT_URL': settings.ROOT_URL,
139
'durations': durations_section,
140
'stmt_counts': stmt_counts_section,
141
'timeout_counts': timeout_counts
143
return render_to_response("summary.html", dictionary=data)