Changeset 70016 in webkit


Ignore:
Timestamp:
Oct 18, 2010 7:13:19 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-10-18 Eric Seidel <eric@webkit.org>

Reviewed by Adam Barth.

Deploy Queue class in more places throughout QueueStatusServer
https://bugs.webkit.org/show_bug.cgi?id=47855

I also caught two typos from the previous change. Unfortunately
I don't yet know how to unittest request handlers yet.

  • QueueStatusServer/handlers/dashboard.py:
  • QueueStatusServer/handlers/statusbubble.py:
  • QueueStatusServer/handlers/updateworkitems.py:
  • QueueStatusServer/model/activeworkitems.py:
  • QueueStatusServer/model/attachment.py:
  • QueueStatusServer/model/queuepropertymixin.py: Added.
  • QueueStatusServer/model/queuepropertymixin_unittest.py: Added.
  • QueueStatusServer/model/queuestatus.py:
  • QueueStatusServer/model/workitems.py:
Location:
trunk/WebKitTools
Files:
8 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r70014 r70016  
     12010-10-18  Eric Seidel  <eric@webkit.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Deploy Queue class in more places throughout QueueStatusServer
     6        https://bugs.webkit.org/show_bug.cgi?id=47855
     7
     8        I also caught two typos from the previous change.  Unfortunately
     9        I don't yet know how to unittest request handlers yet.
     10
     11        * QueueStatusServer/handlers/dashboard.py:
     12        * QueueStatusServer/handlers/statusbubble.py:
     13        * QueueStatusServer/handlers/updateworkitems.py:
     14        * QueueStatusServer/model/activeworkitems.py:
     15        * QueueStatusServer/model/attachment.py:
     16        * QueueStatusServer/model/queuepropertymixin.py: Added.
     17        * QueueStatusServer/model/queuepropertymixin_unittest.py: Added.
     18        * QueueStatusServer/model/queuestatus.py:
     19        * QueueStatusServer/model/workitems.py:
     20
    1212010-10-18  Adam Barth  <abarth@webkit.org>
    222
  • trunk/WebKitTools/QueueStatusServer/handlers/dashboard.py

    r70006 r70016  
    4242
    4343    def _build_bubble(self, attachment, queue):
    44         queue_status = attachment.status_for_queue(queue.name())
     44        queue_status = attachment.status_for_queue(queue)
    4545        bubble = {
    4646            "status_class": attachment.state_from_queue_status(queue_status) if queue_status else "none",
  • trunk/WebKitTools/QueueStatusServer/handlers/statusbubble.py

    r70006 r70016  
    4141
    4242    def _build_bubble(self, queue, attachment):
    43         queue_status = attachment.status_for_queue(queue.name())
     43        queue_status = attachment.status_for_queue(queue)
    4444        bubble = {
    4545            "name": queue.short_name().lowercase(),
    4646            "attachment_id": attachment.id,
    47             "queue_position": attachment.position_in_queue(queue.name()),
     47            "queue_position": attachment.position_in_queue(queue),
    4848            "state": attachment.state_from_queue_status(queue_status) if queue_status else "none",
    4949            "status": queue_status,
  • trunk/WebKitTools/QueueStatusServer/handlers/updateworkitems.py

    r70006 r70016  
    4141        self.response.out.write(template.render("templates/updateworkitems.html", None))
    4242
    43     def _work_items_for_queue(self, queue_name):
    44         queue = Queue.queue_for_name(queue_name)
    45         if queue:
    46             self.response.out.write("\"%s\" is not in queues %s" % (queue_name, Queue.all()))
    47             return None
    48         work_items = WorkItems.all().filter("queue_name =", queue_name).get()
     43    def _work_items_for_queue(self, queue):
     44        work_items = WorkItems.all().filter("queue_name =", queue.name()).get()
    4945        if not work_items:
    5046            work_items = WorkItems()
    51             work_items.queue_name = queue_name
     47            work_items.queue = queue
    5248        return work_items
    5349
     
    5955    def _work_items_from_request(self):
    6056        queue_name = self.request.get("queue_name")
    61         work_items = self._work_items_for_queue(queue_name)
     57        queue = Queue.queue_for_name(queue_name)
     58        if not queue:
     59            self.response.out.write("\"%s\" is not in queues %s" % (queue_name, Queue.all()))
     60            return None
     61
     62        work_items = self._work_items_for_queue(queue)
    6263        if not work_items:
    6364            return None
  • trunk/WebKitTools/QueueStatusServer/model/activeworkitems.py

    r68491 r70016  
    3232import time
    3333
     34from model.queuepropertymixin import QueuePropertyMixin
    3435
    35 class ActiveWorkItems(db.Model):
     36
     37class ActiveWorkItems(db.Model, QueuePropertyMixin):
    3638    queue_name = db.StringProperty()
    3739    item_ids = db.ListProperty(int)
  • trunk/WebKitTools/QueueStatusServer/model/attachment.py

    r70006 r70016  
    8888        return None
    8989
    90     def position_in_queue(self, queue_name):
    91         return self._queue_positions().get(queue_name)
     90    def position_in_queue(self, queue):
     91        return self._queue_positions().get(queue.name())
    9292
    93     def status_for_queue(self, queue_name):
    94         underscore_queue_name = Queue(queue_name).name_with_underscores()
     93    def status_for_queue(self, queue):
    9594        # summary() is a horrible API and should be killed.
    96         queue_summary = self.summary().get(underscore_queue_name)
     95        queue_summary = self.summary().get(queue.name_with_underscores())
    9796        if not queue_summary:
    9897            return None
     
    110109
    111110    def _calculate_queue_positions(self):
    112         queue_positions = {}
    113         for work_items in WorkItems.all().fetch(limit=len(queues)):
    114             queue_name = str(work_items.queue_name)
    115             try:
    116                 position = work_items.item_ids.index(self.id)
    117                 # Display 1-based indecies to the user.
    118                 queue_positions[queue_name] = position + 1
    119             except ValueError, e:
    120                 queue_positions[queue_name] = None
    121         return queue_positions
     111        all_work_items = WorkItems.all().fetch(limit=len(Queues.all()))
     112        return dict([(items.queue.name(), items.display_position_for_attachment(self.id)) for items in all_work_items])
    122113
    123114    # FIXME: This is controller/view code and does not belong in a model.
     
    131122        summary["bug_id"] = first_status.active_bug_id
    132123
    133         for queue in queues:
    134             summary[queue] = None
    135             status = QueueStatus.all().filter('queue_name =', queue).filter('active_patch_id =', self.id).order('-date').get()
     124        for queue in Queues.all():
     125            summary[queue.name_with_underscores()] = None
     126            status = QueueStatus.all().filter('queue_name =', queue.name()).filter('active_patch_id =', self.id).order('-date').get()
    136127            if status:
    137                 queue_name = Queue(queue_name).name_with_underscores()
    138128                # summary() is a horrible API and should be killed.
    139                 summary[queue_name] = {
     129                summary[queue.name_with_underscores()] = {
    140130                    "state": self.state_from_queue_status(status),
    141131                    "status": status,
  • trunk/WebKitTools/QueueStatusServer/model/queuepropertymixin.py

    r70015 r70016  
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
    29 from google.appengine.ext import db
     29from model.queues import Queue
    3030
    3131
    32 class WorkItems(db.Model):
    33     queue_name = db.StringProperty()
    34     item_ids = db.ListProperty(int)
    35     date = db.DateTimeProperty(auto_now_add=True)
     32class QueuePropertyMixin(object):
     33    def _queue_getter(self):
     34        return Queue.queue_from_name(self.queue_name)
     35
     36    def _queue_setter(self, queue):
     37        self.queue_name = queue.name() if queue else None
     38
     39    queue = property(_queue_getter, _queue_setter)
  • trunk/WebKitTools/QueueStatusServer/model/queuepropertymixin_unittest.py

    r70015 r70016  
    1 # Copyright (C) 2010 Google Inc. All rights reserved.
     1# Copyright (C) 2010 Google, Inc. All rights reserved.
    22#
    33# Redistribution and use in source and binary forms, with or without
     
    55# met:
    66#
    7 #     * Redistributions of source code must retain the above copyright
     7#    * Redistributions of source code must retain the above copyright
    88# notice, this list of conditions and the following disclaimer.
    9 #     * Redistributions in binary form must reproduce the above
     9#    * Redistributions in binary form must reproduce the above
    1010# copyright notice, this list of conditions and the following disclaimer
    1111# in the documentation and/or other materials provided with the
    1212# distribution.
    13 #     * Neither the name of Google Inc. nor the names of its
     13#    * Neither the name of Research in Motion Ltd. nor the names of its
    1414# contributors may be used to endorse or promote products derived from
    1515# this software without specific prior written permission.
     
    2727# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
    29 from google.appengine.ext import db
     29import unittest
     30
     31from model.queuepropertymixin import QueuePropertyMixin
     32from model.queues import Queue
    3033
    3134
    32 class WorkItems(db.Model):
    33     queue_name = db.StringProperty()
    34     item_ids = db.ListProperty(int)
    35     date = db.DateTimeProperty(auto_now_add=True)
     35class ObjectWithQueueName(QueuePropertyMixin):
     36    def __init__(self):
     37        self.queue_name = None
     38
     39
     40class QueuePropertyMixinTest(unittest.TestCase):
     41    def test_queue_property(self):
     42        test_object = ObjectWithQueueName()
     43        mac_ews = Queue("mac-ews")
     44        test_object.queue = mac_ews
     45        self.assertEquals(test_object.queue_name, "mac-ews")
     46        test_object.queue = None
     47        self.assertEquals(test_object.queue_name, None)
     48
     49
     50if __name__ == '__main__':
     51    unittest.main()
  • trunk/WebKitTools/QueueStatusServer/model/queuestatus.py

    r68673 r70016  
    2828
    2929from google.appengine.ext import db
     30from model.queuepropertymixin import QueuePropertyMixin
    3031
    31 class QueueStatus(db.Model):
     32
     33class QueueStatus(db.Model, QueuePropertyMixin):
    3234    author = db.UserProperty()
    3335    queue_name = db.StringProperty()
  • trunk/WebKitTools/QueueStatusServer/model/workitems.py

    r59534 r70016  
    2929from google.appengine.ext import db
    3030
     31from model.queuepropertymixin import QueuePropertyMixin
    3132
    32 class WorkItems(db.Model):
     33
     34class WorkItems(db.Model, QueuePropertyMixin):
    3335    queue_name = db.StringProperty()
    3436    item_ids = db.ListProperty(int)
    3537    date = db.DateTimeProperty(auto_now_add=True)
     38
     39    def display_position_for_attachment(self, attachment_id):
     40        """Returns a 1-based index corresponding to the position
     41        of the attachment_id in the queue.  If the attachment is
     42        not in this queue, this returns None"""
     43        if attachment_id in attachment_id:
     44            return self.item_ids.index(attachment_id) + 1
     45        return None
Note: See TracChangeset for help on using the changeset viewer.