OS_CHOICES should live in one place
authorJeff Hammel <jhammel@mozilla.com>
Thu, 20 May 2010 15:53:26 -0700
changeset 29 9a99dcd4ed7a1c415caee2d08d577ca4ed6f798e
parent 28 aaf0eec5f386314b07a3945d6493a6f3d30ecc03
child 30 b09d1edc0583a44fb24049a1bafa41a33dbddac7
push id5
push userjhammel@mozilla.com
push dateFri, 21 May 2010 00:42:10 +0000
OS_CHOICES should live in one place
topfails/mappings.py
topfails/viewer/models.py
topfails/viewer/views.py
--- a/topfails/mappings.py
+++ b/topfails/mappings.py
@@ -50,30 +50,31 @@ OSes = [ 'Linux',
          'Rev3 Fedora 12x64',
          'Rev3 MacOSX Leopard 10.5.8',
          'Rev3 MacOSX Snow Leopard 10.6.2',
          'Rev3 WINNT 5.1',
          'Rev3 WINNT 6.1',
          'WINNT 5.2' ]
 OS_to_index = dict([(OS, index) for index, OS in enumerate(OSes)])
 index_to_OS = dict([(index, OS) for index, OS in enumerate(OSes)])
+OS_CHOICES = tuple([(index, OS) for index, OS in enumerate(OSes)])
 OSdata = { 'Linux': {'name': 'Linux', 'bits': 32 },
            'Rev3 Fedora 12': { 'name': 'Fedora', 'bits': 32},
            'Rev3 Fedora 12x64': { 'name': 'Fedora', 'bits': 64},
 	   'Linux x86-64': { 'name': 'Linux', 'bits': 64},
 	   'OS X 10.5.2': { 'name': 'MAC OSX', 'bits': 32},
 	   'OS X 10.6.2': { 'name': 'MAC OSX', 'bits': 64},
 	   'Rev3 MacOSX Leopard 10.5.8': { 'name': 'MAC OSX', 'bits': 32},
 	   'Rev3 MacOSX Snow Leopard 10.6.2': { 'name': 'MAC OSX', 'bits': 64},
 	   'Rev3 WINNT 5.1': { 'name': 'Windows', 'bits': 32},
 	   'Rev3 WINNT 6.1': { 'name': 'Windows', 'bits': 64},
 	   'WINNT 5.2': { 'name': 'Windows', 'bits': 32},
     }
 
-# branch objects
+# Branch objects:
 # branches = [ 'mozilla-central',
 #              'mozilla-1.9.2',
 #              'comm-central',
 #              'comm-central-trunk'
 #     ]
 trees = { 'Firefox': 'mozilla-central',
           'Firefox3.6': 'mozilla-1.9.2',
           'Thunderbird': 'comm-central',
--- a/topfails/viewer/models.py
+++ b/topfails/viewer/models.py
@@ -1,27 +1,13 @@
 import re
 from django.db import models, connection
 from datetime import datetime
 from time import ctime, sleep, time
-from topfails.mappings import OSes
-
-# class OS():
-#   Windows = 0
-#   Mac = 1
-#   Linux = 2
-#   Unknown = 3
-
-# OS_CHOICES = (
-#     (OS.Windows, 'Windows'),
-#     (OS.Mac, 'Mac'),
-#     (OS.Linux, 'Linux'),
-#     (OS.Unknown, 'Unknown')
-# )
-OS_CHOICES = tuple([(index, OS) for index, OS in enumerate(OSes)])
+from topfails.mappings import OS_CHOICES
 
 class BuildStatus():
   Success = 0
   TestFailed = 1
   Burning = 2
   Exception = 3
   Unknown = 4
 
--- a/topfails/viewer/views.py
+++ b/topfails/viewer/views.py
@@ -1,17 +1,17 @@
 """
 views for topfails
 """
 
 import re
 from django.shortcuts import render_to_response, get_list_or_404
 from django.http import HttpResponse
-from topfails.viewer.models import Build, Tree, Test,TestFailure, OS_CHOICES
-### TODO: OS_CHOICES should be deprecated in place of topfails.mappings
+from topfails.mappings import OS_CHOICES
+from topfails.viewer.models import Build, Tree, Test,TestFailure
 
 try:
   import simplejson as json
 except ImportError:
   try:
     # New in python 2.6
     import json
   except ImportError:
@@ -53,32 +53,34 @@ def tests(request,tree='Firefox'):
     test_names = TestFailure.objects.filter(build__tree__name__exact=tree).values('test__name').distinct()
     if request.GET.has_key('json'):
       jtext = list(test_names)
       return HttpResponse(json.dumps(jtext))
     else:
       return render_to_response('viewer/tests.html', { 'tree' : tree, 'tests': [t['test__name'] for t in test_names]})
 
 def test(request,tree='Firefox'):
-  failures = get_list_or_404(TestFailure.objects.filter(build__tree__name__exact=tree).filter(test__name__exact=request.GET['name']).order_by('-build__starttime')[:10000])
+  failures = get_list_or_404(TestFailure.objects.filter(build__tree__name__exact=tree).filter(test__name__exact=request.GET['name']).order_by('-build__starttime')[:10000]) # TODO: remove hard-coded constants
   return render_to_response('viewer/test.html', {'test': request.GET['name'], 'failures': failures, 'tree' : tree})
 
 def topfails(request,tree='Firefox'):
   failures = TestFailure.get_most_failing_tests(tree)
   if request.GET.has_key('json'):
     jtext = list(failures)
     return HttpResponse(json.dumps(jtext))
   else:
     return render_to_response('viewer/topfails.html', {'failures': failures, 'tree' : tree})
   
 def Help(request,tree):
   return render_to_response('viewer/Help.html',{'tree':tree})  
   
 def timeline(request,tree='Firefox'):
-  name = request.GET['name']
+
+  name = request.GET['name'] # XXX will cause a 500 if not present!
+  
   builds = get_list_or_404(Build.objects.filter(tree__name__exact=tree), test__name__exact=name)
   buildlist = []
   desc_list = []
   for b in builds:
     descs = b.testfailure_set.filter(testfailure__name__exact=name).order_by('id')
     desc = '\n'.join(descs.values_list('description', flat=True))
     if desc not in desc_list:
       desc_list.append(desc)