From: Aaron Bentley Date: Wed, 9 Mar 2005 19:32:17 +0000 (+0000) Subject: Added ability to create, close, open bugs X-Git-Tag: 1.0.0~383 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=006b0cb118041cac8081032ad2d401fdd69fe6ae;p=be.git Added ability to create, close, open bugs --- diff --git a/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/creator b/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/creator new file mode 100644 index 0000000..ce73549 --- /dev/null +++ b/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/creator @@ -0,0 +1 @@ +abentley diff --git a/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/name b/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/name new file mode 100644 index 0000000..d8dfad2 --- /dev/null +++ b/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/name @@ -0,0 +1 @@ +abentley-2 diff --git a/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/severity b/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/severity new file mode 100644 index 0000000..acb503f --- /dev/null +++ b/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/severity @@ -0,0 +1 @@ +minor diff --git a/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/status b/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/status new file mode 100644 index 0000000..1ac2082 --- /dev/null +++ b/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/status @@ -0,0 +1 @@ +closed diff --git a/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/summary b/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/summary new file mode 100644 index 0000000..5ac52ed --- /dev/null +++ b/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/summary @@ -0,0 +1 @@ +Can't close bugs diff --git a/.be/bugs/f51dc5a7-37b7-4ce1-859a-b7cb58be6494/status b/.be/bugs/f51dc5a7-37b7-4ce1-859a-b7cb58be6494/status index f510327..1ac2082 100644 --- a/.be/bugs/f51dc5a7-37b7-4ce1-859a-b7cb58be6494/status +++ b/.be/bugs/f51dc5a7-37b7-4ce1-859a-b7cb58be6494/status @@ -1 +1 @@ -open +closed diff --git a/be b/be index 11e8c5c..47eec40 100755 --- a/be +++ b/be @@ -8,21 +8,22 @@ be set-root: assign the root directory for bug tracking """ 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: @@ -34,7 +35,25 @@ def list_bugs(args): 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__ @@ -42,7 +61,10 @@ else: 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]) diff --git a/libbe/bugdir.py b/libbe/bugdir.py index efb392d..5e1d409 100644 --- a/libbe/bugdir.py +++ b/libbe/bugdir.py @@ -2,7 +2,7 @@ import os import os.path import cmdutil import errno - +import names class NoBugDir(cmdutil.UserError): def __init__(self, path): @@ -38,6 +38,13 @@ class BugDir: 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) @@ -68,23 +75,10 @@ class Bug(object): 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" diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py index 4cc7d12..560c78d 100644 --- a/libbe/cmdutil.py +++ b/libbe/cmdutil.py @@ -4,3 +4,19 @@ def unique_name(bug, bugs): 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] diff --git a/libbe/names.py b/libbe/names.py new file mode 100644 index 0000000..a0c579b --- /dev/null +++ b/libbe/names.py @@ -0,0 +1,22 @@ +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) + +