Added severity command
authorAaron Bentley <abentley@panoramicfeedback.com>
Fri, 11 Mar 2005 17:45:05 +0000 (17:45 +0000)
committerAaron Bentley <abentley@panoramicfeedback.com>
Fri, 11 Mar 2005 17:45:05 +0000 (17:45 +0000)
be
commands/__init__.py [new file with mode: 0644]
commands/severity.py [new file with mode: 0644]
libbe/bugdir.py
libbe/cmdutil.py

diff --git a/be b/be
index 1dbcee0e7a40130fcee3bdb641552fd2634fd827..5c0490614c31c64d25a8fa4b8ed6cd2c35e201fa 100755 (executable)
--- a/be
+++ b/be
@@ -1,5 +1,12 @@
 #!/usr/bin/env python
-"""Bugs Everywhere - Distributed bug tracking
+from libbe.cmdutil import *
+from libbe.bugdir import tree_root, create_bug_dir
+from libbe import names
+import sys
+import os
+import commands
+import commands.severity
+__doc__ = """Bugs Everywhere - Distributed bug tracking
 
 Supported commands
  set-root: assign the root directory for bug tracking
@@ -8,15 +15,11 @@ Supported commands
      show: show a particular bug
     close: close a bug
      open: re-open a bug
+ severity: %s
 
 Unimplemented commands
   comment: append a comment to a bug
-"""
-from libbe.cmdutil import *
-from libbe.bugdir import tree_root, create_bug_dir
-from libbe import names
-import sys
-import os
+""" % commands.severity.__desc__
 
 def list_bugs(args):
     active = True
@@ -77,6 +80,7 @@ else:
                 "new": new_bug,
                 "close": close_bug,
                 "open": open_bug,
+                "severity": commands.severity.execute,
             }[sys.argv[1]]
         except KeyError, e:
             raise UserError("Unknown command \"%s\"" % e.args[0])
diff --git a/commands/__init__.py b/commands/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/commands/severity.py b/commands/severity.py
new file mode 100644 (file)
index 0000000..7a5051a
--- /dev/null
@@ -0,0 +1,38 @@
+"""Show or change a bug's severity level"""
+from libbe.bugdir import tree_root
+from libbe.cmdutil import get_bug
+from libbe import bugdir
+from libbe import cmdutil 
+__desc__ = __doc__
+def execute(args):
+    assert(len(args) in (0, 1, 2))
+    if len(args) == 0:
+        print help()
+        return
+    bug = get_bug(args[0])
+    if len(args) == 1:
+        print bug.severity
+    elif len(args) == 2:
+        try:
+            bug.severity = args[1]
+        except bugdir.InvalidValue, e:
+            if e.name != "severity":
+                raise
+            raise cmdutil.UserError ("Invalid severity level: %s" % e.value)
+
+
+def help():
+    return """be severity bug-id [severity]
+
+Show or change a bug's severity level.  
+
+If no severity is specified, the current value is printed.  If a severity level
+is specified, it will be assigned to the bug.
+
+Severity levels are:
+wishlist: A feature that could improve usefulness, but not a bug. 
+   minor: The standard bug level.
+ serious: A bug that requires workarounds.
+critical: A bug that prevents some features from working at all.
+   fatal: A bug that makes the package unusable.
+"""
index 0008be8dbd1a395e2a53c1c801119f45fa0d7d73..4a79584a7713a277819814cb459a660d69485891 100644 (file)
@@ -5,7 +5,7 @@ import errno
 import names
 import rcs
 
-class NoBugDir(cmdutil.UserError):
+class NoBugDir(Exception):
     def __init__(self, path):
         msg = "The directory \"%s\" has no bug directory." % path
         Exception.__init__(self, msg)
@@ -53,17 +53,24 @@ class BugDir:
         path = os.path.join(self.bugs_path, uuid)
         rcs.mkdir(path)
         return Bug(self.bugs_path, uuid)
-
+class InvalidValue(Exception):
+    def __init__(self, name, value):
+        msg = "Cannot assign value %s to %s" % (value, name)
+        Exception.__init__(self, msg)
+        self.name = name
+        self.value = value
 
 def file_property(name, valid=None):
     def getter(self):
         value = self._get_value(name) 
         if valid is not None:
-            assert value in valid
+            if value not in valid:
+                raise InvalidValue(name, value)
         return value
     def setter(self, value):
         if valid is not None:
-            assert value in valid
+            if value not in valid:
+                raise InvalidValue(name, value)
         return self._set_value(name, value)
     return property(getter, setter)
 
index ac67f3a8d79094e3121c8b345b403998e6d63570..2afd53cc0dd87458ebff3f220385707be45cf9ff 100644 (file)
@@ -1,3 +1,4 @@
+import bugdir
 def unique_name(bug, bugs):
     chars = 1
     for some_bug in bugs:
@@ -11,8 +12,18 @@ class UserError(Exception):
     def __init__(self, msg):
         Exception.__init__(self, msg)
 
-def get_bug(spec, bug_dir):
+class UserErrorWrap(UserError):
+    def __init__(self, exception):
+        UserError.__init__(self, str(exception))
+        self.exception = exception
+
+def get_bug(spec, bug_dir=None):
     matches = []
+    try:
+        if bug_dir is None:
+            bug_dir = bugdir.tree_root('.')
+    except bugdir.NoBugDir, e:
+        raise UserErrorWrap(e)
     bugs = list(bug_dir.list())
     for bug in bugs:
         if bug.uuid.startswith(spec):