Implemented sorting by severity level
authorAaron Bentley <abentley@panoramicfeedback.com>
Fri, 18 Mar 2005 18:53:49 +0000 (18:53 +0000)
committerAaron Bentley <abentley@panoramicfeedback.com>
Fri, 18 Mar 2005 18:53:49 +0000 (18:53 +0000)
becommands/list.py
libbe/bugdir.py

index 5bd54a2034f7c39dff60d37f9a1b0ae49a945cce..0b27a25458ced5de38ca30154e48955eb1e2200f 100644 (file)
@@ -29,6 +29,7 @@ def execute(args):
             other_bugs.append(bug)
 
     def list_bugs(cur_bugs, title):
+        cur_bugs.sort(bugdir.cmp_severity)
         if len(cur_bugs) > 0:
             print cmdutil.underlined(title)
             for bug in cur_bugs:
index addefe026e4db29daf9bc72686e6b661fca5f8ca..e1c95c56ba86424ff4fd638d53e0f7e7107850c1 100644 (file)
@@ -94,6 +94,11 @@ def checked_property(name, valid):
         return self.__setattr__("_"+name, value)
     return property(getter, setter)
 
+severity_levels = ("wishlist", "minor", "serious", "critical", "fatal")
+
+severity_value = {}
+for i in range(len(severity_levels)):
+    severity_value[severity_levels[i]] = i
 
 class Bug(object):
     status = checked_property("status", (None, "open", "closed"))
@@ -141,3 +146,25 @@ class Bug(object):
             rcs.add_id(path)
         output = file(path, "wb")
         mapfile.generate(output, map)
+
+class MockBug:
+    def __init__(self, severity):
+        self.severity = severity
+
+def cmp_severity(bug_1, bug_2):
+    """
+    Compare the severity levels of two bugs, with more sever bugs comparing
+    as less.
+
+    >>> cmp_severity(MockBug(None), MockBug(None))
+    0
+    >>> cmp_severity(MockBug("wishlist"), MockBug(None)) < 0
+    True
+    >>> cmp_severity(MockBug(None), MockBug("wishlist")) > 0
+    True
+    >>> cmp_severity(MockBug("critical"), MockBug("wishlist")) < 0
+    True
+    """
+    val_1 = severity_value.get(bug_1.severity)
+    val_2 = severity_value.get(bug_2.severity)
+    return -cmp(val_1, val_2)