1# Copyright (C) 2010 Google Inc. All rights reserved. 2# 3# Redistribution and use in source and binary forms, with or without 4# modification, are permitted provided that the following conditions are 5# met: 6# 7# * Redistributions of source code must retain the above copyright 8# notice, this list of conditions and the following disclaimer. 9# * Redistributions in binary form must reproduce the above 10# copyright notice, this list of conditions and the following disclaimer 11# in the documentation and/or other materials provided with the 12# distribution. 13# * Neither the name of Google Inc. nor the names of its 14# contributors may be used to endorse or promote products derived from 15# this software without specific prior written permission. 16# 17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 29 30import re 31 32from model.activeworkitems import ActiveWorkItems 33from model.workitems import WorkItems 34 35 36class Queue(object): 37 38 # Eventually the list of queues may be stored in the data store. 39 _all_queue_names = [ 40 "commit-queue", 41 "style-queue", 42 "chromium-ews", 43 "qt-ews", 44 "gtk-ews", 45 "mac-ews", 46 "win-ews", 47 "efl-ews", 48 "cr-mac-ews", 49 ] 50 51 def __init__(self, name): 52 assert(name in self._all_queue_names) 53 self._name = name 54 55 @classmethod 56 def queue_with_name(cls, queue_name): 57 if queue_name not in cls._all_queue_names: 58 return None 59 return Queue(queue_name) 60 61 @classmethod 62 def all(cls): 63 return [Queue(name) for name in cls._all_queue_names] 64 65 @classmethod 66 def all_ews(cls): 67 return [queue for queue in cls.all() if queue.is_ews()] 68 69 def name(self): 70 return self._name 71 72 def work_items(self): 73 return WorkItems.lookup_by_queue(self._name) 74 75 # FIXME: active_work_items is a bad name for this lock-table. 76 def active_work_items(self): 77 return ActiveWorkItems.lookup_by_queue(self._name) 78 79 def _caplitalize_after_dash(self, string): 80 return "-".join([word[0].upper() + word[1:] for word in string.split("-")]) 81 82 # For use in status bubbles or table headers 83 def short_name(self): 84 # HACK: chromium-ews is incorrectly named. 85 short_name = self._name.replace("chromium-ews", "Cr-Linux-ews") 86 short_name = short_name.replace("-ews", "") 87 short_name = short_name.replace("-queue", "") 88 return self._caplitalize_after_dash(short_name.capitalize()) 89 90 def display_name(self): 91 # HACK: chromium-ews is incorrectly named. 92 display_name = self._name.replace("chromium-ews", "cr-linux-ews") 93 94 display_name = display_name.replace("-", " ") 95 display_name = display_name.replace("cr", "chromium") 96 display_name = display_name.title() 97 display_name = display_name.replace("Ews", "EWS") 98 return display_name 99 100 _dash_regexp = re.compile("-") 101 102 def name_with_underscores(self): 103 return self._dash_regexp.sub("_", self._name) 104 105 def is_ews(self): 106 # Note: The style-queue is just like an EWS in that it has an EWS 107 # bubble, and it works off of the r? patches. If at some later 108 # point code wants to not treat the style-queue as an EWS 109 # (e.g. expecting is_ews() queues to have build results?) 110 # then we should fix all callers and change this check. 111 return self._name.endswith("-ews") or self._name == "style-queue" 112