Moved code into bugdir, handled unknown commands
authorAaron Bentley <abentley@panoramicfeedback.com>
Wed, 9 Mar 2005 17:37:13 +0000 (17:37 +0000)
committerAaron Bentley <abentley@panoramicfeedback.com>
Wed, 9 Mar 2005 17:37:13 +0000 (17:37 +0000)
be
libbe/cmdutil.py
libbe/cmdutil.pyc

diff --git a/be b/be
index f1e6cb385dedd1e27d7cb9f35f6505bf805fffa6..e87ed0ba1d6ecff855adfc5c6c807fc8056da23c 100755 (executable)
--- a/be
+++ b/be
@@ -7,7 +7,9 @@ be comment: append a comment to a bug
 be set-root: assign the root directory for bug tracking
 """
 from libbe.cmdutil import *
+from libbe.bugdir import tree_root
 import sys
+import os
 
 def list_bugs(args):
     bugs = list(tree_root(os.getcwd()).list())
@@ -16,15 +18,19 @@ def list_bugs(args):
     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:])
-
-    
+    try:
+        try:
+            cmd = {
+                "list": list_bugs
+            }[sys.argv[1]]
+        except KeyError, e:
+            raise UserError("Unknown command \"%s\"" % e.args[0])
+        cmd(sys.argv[2:])
+    except UserError, e:
+        print e
+        sys.exit(1)
index 6c5285a92a12b109c1fc2e0aa92ee4dbb03d8cba..4cc7d128b928f979e07601810d6dd5516767e933 100644 (file)
@@ -1,73 +1,6 @@
-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)
-
+class UserError(Exception):
+    def __init__(self, msg):
+        Exception.__init__(self, msg)
index 8515fb9105267cb365f42bd43cdf68c3c0d8883d..1098304c6474fb1056f6600091f45f0eef9f90cc 100644 (file)
Binary files a/libbe/cmdutil.pyc and b/libbe/cmdutil.pyc differ