#!/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
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
"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])
--- /dev/null
+"""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.
+"""
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)
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)
+import bugdir
def unique_name(bug, bugs):
chars = 1
for some_bug in bugs:
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):