Added basic bug-listing functionality
authorAaron Bentley <abentley@panoramicfeedback.com>
Wed, 9 Mar 2005 17:25:46 +0000 (17:25 +0000)
committerAaron Bentley <abentley@panoramicfeedback.com>
Wed, 9 Mar 2005 17:25:46 +0000 (17:25 +0000)
.be/bugs/f51dc5a7-37b7-4ce1-859a-b7cb58be6494/name [new file with mode: 0644]
.be/bugs/f51dc5a7-37b7-4ce1-859a-b7cb58be6494/summary [new file with mode: 0644]
.be/version [new file with mode: 0644]
be [new file with mode: 0755]
libbe/__init__.py [new file with mode: 0644]
libbe/__init__.pyc [new file with mode: 0644]
libbe/cmdutil.py [new file with mode: 0644]
libbe/cmdutil.pyc [new file with mode: 0644]

diff --git a/.be/bugs/f51dc5a7-37b7-4ce1-859a-b7cb58be6494/name b/.be/bugs/f51dc5a7-37b7-4ce1-859a-b7cb58be6494/name
new file mode 100644 (file)
index 0000000..49529a8
--- /dev/null
@@ -0,0 +1 @@
+abentley-1
diff --git a/.be/bugs/f51dc5a7-37b7-4ce1-859a-b7cb58be6494/summary b/.be/bugs/f51dc5a7-37b7-4ce1-859a-b7cb58be6494/summary
new file mode 100644 (file)
index 0000000..1c2d1a3
--- /dev/null
@@ -0,0 +1 @@
+Can't create bugs
diff --git a/.be/version b/.be/version
new file mode 100644 (file)
index 0000000..25c1c63
--- /dev/null
@@ -0,0 +1 @@
+Bugs Everywhere Tree 0 0
diff --git a/be b/be
new file mode 100755 (executable)
index 0000000..f1e6cb3
--- /dev/null
+++ b/be
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+"""Bugs Everywhere - Distributed bug tracking
+
+be list: list bugs
+be status: view or set the status of a bug
+be comment: append a comment to a bug
+be set-root: assign the root directory for bug tracking
+"""
+from libbe.cmdutil import *
+import sys
+
+def list_bugs(args):
+    bugs = list(tree_root(os.getcwd()).list())
+    if len(bugs) == 0:
+        print "No bugs found"
+    for bug in bugs:
+        print "%s: %s" % (unique_name(bug, bugs), bug.summary)
+
+
+        
+    
+
+if len(sys.argv) == 1:
+    print __doc__
+else:
+    {
+        "list": list_bugs
+    }[sys.argv[1]](sys.argv[2:])
+
+    
diff --git a/libbe/__init__.py b/libbe/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/libbe/__init__.pyc b/libbe/__init__.pyc
new file mode 100644 (file)
index 0000000..c79880a
Binary files /dev/null and b/libbe/__init__.pyc differ
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py
new file mode 100644 (file)
index 0000000..6c5285a
--- /dev/null
@@ -0,0 +1,73 @@
+import os
+import os.path
+
+class NoBugDir(Exception):
+    def __init__(self, path):
+        msg = "The directory \"%s\" has no bug directory." % path
+        Exception.__init__(self, msg)
+        self.path = path
+    
+
+def tree_root(dir):
+    rootdir = os.path.realpath(dir)
+    while (True):
+        versionfile=os.path.join(rootdir, ".be/version")
+        if os.path.exists(versionfile):
+            test_version(versionfile)
+            break;
+        elif rootdir == "/":
+            raise NoBugDir(dir)
+        rootdir=os.path.dirname(rootdir)
+    return BugDir(os.path.join(rootdir, ".be"))
+
+def test_version(path):
+    assert (file(path, "rb").read() == "Bugs Everywhere Tree 0 0\n")
+
+class BugDir:
+    def __init__(self, dir):
+        self.dir = dir
+        self.bugs_path = os.path.join(self.dir, "bugs")
+
+
+    def list(self):
+        for uuid in os.listdir(self.bugs_path):
+            if (uuid.startswith('.')):
+                continue
+            yield Bug(self.bugs_path, uuid)
+
+def unique_name(bug, bugs):
+    return bug.name
+
+def file_property(name):
+    def getter(self):
+        return self._get_value(name)
+    def setter(self, value):
+        return self._set_value(name, value)
+    return property(getter, setter)
+
+class Bug(object):
+    def __init__(self, path, uuid):
+        self.path = os.path.join(path, uuid)
+        self.uuid = uuid
+
+    def get_path(self, file):
+        return os.path.join(self.path, file)
+
+    def _get_name(self):
+        return self._get_value("name")
+    
+    def _set_name(self, value):
+        return self._set_value("name", value)
+    
+    name = file_property("name")
+    summary = file_property("summary")
+
+    def _set_status(self, status):
+        assert status in ("open", "closed")
+
+    def _get_value(self, name):
+        return file(self.get_path(name), "rb").read().rstrip("\n")
+
+    def _set_value(self, name, value):
+        file(self.get_path(name), "wb").write("%s\n" % value)
+
diff --git a/libbe/cmdutil.pyc b/libbe/cmdutil.pyc
new file mode 100644 (file)
index 0000000..8515fb9
Binary files /dev/null and b/libbe/cmdutil.pyc differ