Added ability to create, close, open bugs
authorAaron Bentley <abentley@panoramicfeedback.com>
Wed, 9 Mar 2005 19:32:17 +0000 (19:32 +0000)
committerAaron Bentley <abentley@panoramicfeedback.com>
Wed, 9 Mar 2005 19:32:17 +0000 (19:32 +0000)
.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/creator [new file with mode: 0644]
.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/name [new file with mode: 0644]
.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/severity [new file with mode: 0644]
.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/status [new file with mode: 0644]
.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/summary [new file with mode: 0644]
.be/bugs/f51dc5a7-37b7-4ce1-859a-b7cb58be6494/status
be
libbe/bugdir.py
libbe/cmdutil.py
libbe/names.py [new file with mode: 0644]

diff --git a/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/creator b/.be/bugs/74cccfbf-069d-4e99-8cab-adaa35f9a2eb/creator
new file mode 100644 (file)
index 0000000..ce73549
--- /dev/null
@@ -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 (file)
index 0000000..d8dfad2
--- /dev/null
@@ -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 (file)
index 0000000..acb503f
--- /dev/null
@@ -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 (file)
index 0000000..1ac2082
--- /dev/null
@@ -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 (file)
index 0000000..5ac52ed
--- /dev/null
@@ -0,0 +1 @@
+Can't close bugs
index f510327578a4562e26a7c64bdf061e4a49f85ee6..1ac208286a54bf10746bac5466010b15663a0a6e 100644 (file)
@@ -1 +1 @@
-open
+closed
diff --git a/be b/be
index 11e8c5cb3c2a896b0906121f384ea453daf36457..47eec40c4b5e9dffa4c97fa7b532ef19ca33d254 100755 (executable)
--- 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])
index efb392d205f524bd33182b58421bb077ca02d82d..5e1d4094f87eb581a00dac63e389bdab35f06968 100644 (file)
@@ -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"
 
index 4cc7d128b928f979e07601810d6dd5516767e933..560c78d2128513cd805ca2f3f66653c51180edd0 100644 (file)
@@ -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 (file)
index 0000000..a0c579b
--- /dev/null
@@ -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)
+
+