Move compare function to BuildStatus class
authorMatthieu Patou <mat@matws.net>
Tue, 9 Nov 2010 21:09:03 +0000 (00:09 +0300)
committerMatthieu Patou <mat@matws.net>
Tue, 9 Nov 2010 21:09:03 +0000 (00:09 +0300)
buildfarm/data.py
web/build.py

index a637c3cc207cadcbc1a493c7769a34996223e100..ffe4d64f6c799b7e6d7486c3abf1e013cc45e2a2 100644 (file)
@@ -57,6 +57,29 @@ class BuildStatus(object):
             return False
         return cmp(self._status_tuple(), other._status_tuple())
 
+    def cmp(a, b):
+
+        #Give more importance to other failures
+        if len(b.other_failures):
+            return 1
+        if len(a.other_failures):
+            return -1
+
+        la = len(a.stages)
+        lb = len(b.stages)
+        if la > lb:
+            return 1
+        elif lb > la:
+            return -1
+        else:
+            if la == 0:
+                return 0
+
+            sa = a.stages[-1]
+            sb = b.stages[-1]
+
+            return cmp(sb[1], sa[1])
+
     def __str__(self):
         return repr((self.stages, self.other_failures))
 
index b8dbe70320f41b0f5db12224a051430c3d4dd4a2..a4bed10baf7c470dc2ca0ed49c325c3e8cde5fe6 100755 (executable)
@@ -257,37 +257,13 @@ def view_recent_builds(myself, tree, sort_by):
     last_host = ""
     all_builds = []
 
-    def status_cmp(a, b):
-
-        #put other failure on top
-        if len(b.other_failures):
-            return 1
-        if len(a.other_failures):
-            return -1
-
-        la = len(a.stages)
-        lb = len(b.stages)
-        if la > lb:
-            return 1
-        elif lb > la:
-            return -1
-        else:
-            sa = a.stages[-1]
-            sb = b.stages[-1]
-            if sa[0] == "TEST" and sa[1] == 0:
-                return 1
-            if sb[0] == "TEST" and sb[1] == 0:
-                return -1
-
-            return (sb[-1] <= sb[-1])
-
     cmp_funcs = {
         "revision": lambda a, b: cmp(a[7], b[7]),
         "age": lambda a, b: cmp(a[0], b[0]),
         "host": lambda a, b: cmp(a[2], b[2]),
         "platform": lambda a, b: cmp(a[1], b[1]),
         "compiler": lambda a, b: cmp(a[3], b[3]),
-        "status": lambda a, b: status_cmp(a[6], b[6]),
+        "status": lambda a, b: a[6].cmp(b[6]),
         }
 
     assert tree in trees, "not a build tree"