--- /dev/null
+abentley-2
--- /dev/null
+Can't close bugs
"""
from libbe.cmdutil import *
from libbe.bugdir import tree_root
+from libbe import names
import sys
import os
def list_bugs(args):
active = True
- status = ("minor", "serious", "critical", "fatal")
+ severity = ("minor", "serious", "critical", "fatal")
def filter(bug):
if active is not None:
if bug.active != active:
return False
- if bug.status not in status:
+ if bug.severity not in severity:
return False
return True
- bugs = [b for b in tree_root(os.getcwd()).list() ]
+ bugs = [b for b in tree_root(os.getcwd()).list() if filter(b) ]
if len(bugs) == 0:
print "No matching bugs found"
for bug in bugs:
print "id: %s severity: %s%s\n%s\n" % (unique_name(bug, bugs),
bug.severity, target, bug.summary)
-
+def new_bug(args):
+ if len(args) != 1:
+ raise UserError("Please supply a summary message")
+ dir = tree_root(".")
+ bugs = (dir.list())
+ bug = dir.new_bug()
+ bug.creator = names.creator()
+ bug.name = names.friendly_name(bugs, bug.creator)
+ bug.severity = "minor"
+ bug.status = "open"
+ bug.summary = args[0]
+
+def close_bug(args):
+ assert(len(args) == 1)
+ get_bug(args[0], tree_root('.')).status = "closed"
+
+def open_bug(args):
+ assert(len(args) == 1)
+ get_bug(args[0], tree_root('.')).status = "open"
if len(sys.argv) == 1:
print __doc__
try:
try:
cmd = {
- "list": list_bugs
+ "list": list_bugs,
+ "new": new_bug,
+ "close": close_bug,
+ "open": open_bug,
}[sys.argv[1]]
except KeyError, e:
raise UserError("Unknown command \"%s\"" % e.args[0])
import os.path
import cmdutil
import errno
-
+import names
class NoBugDir(cmdutil.UserError):
def __init__(self, path):
continue
yield Bug(self.bugs_path, uuid)
+ def new_bug(self):
+ uuid = names.uuid()
+ path = os.path.join(self.bugs_path, uuid)
+ os.mkdir(path)
+ return Bug(self.bugs_path, uuid)
+
+
def file_property(name, valid=None):
def getter(self):
value = self._get_value(name)
summary = file_property("summary")
creator = file_property("creator")
target = file_property("target")
+ status = file_property("status", valid=("open", "closed"))
severity = file_property("severity", valid=("wishlist", "minor", "serious",
"critical", "fatal"))
- def _check_status(status):
- assert status in ("open", "closed")
-
- def _set_status(self, status):
- self._check_status(status)
- self._set_value("status", status)
-
- def _get_status(self):
- status = self._get_value("status")
- assert status in ("open", "closed")
- return status
-
- status = property(_get_status, _set_status)
-
def _get_active(self):
return self.status == "open"
class UserError(Exception):
def __init__(self, msg):
Exception.__init__(self, msg)
+
+def get_bug(spec, bug_dir):
+ bugs = list(bug_dir.list())
+ for bug in bugs:
+ if bug.uuid == spec:
+ return bug
+ matches = []
+ for bug in bugs:
+ if bug.name == spec:
+ matches.append(bug)
+ if len(matches) > 1:
+ raise UserError("More than one bug has the name %s. Please use the"
+ " uuid." % spec)
+ if len(matches) == 0:
+ raise UserError("No bug has the name %s" % spec)
+ return matches[0]
--- /dev/null
+import commands
+import os
+
+def uuid():
+ return commands.getoutput('uuidgen')
+
+def creator():
+ return os.environ["LOGNAME"]
+
+def friendly_name(bugs, ctor):
+ last = 0
+ for bug in bugs:
+ name = bug.name
+ if name is None:
+ continue
+ if name.startswith(ctor):
+ num = int(name.split("-")[-1])
+ if num > last:
+ last = num
+ return "%s-%i" % (ctor, num+1)
+
+