aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
Diffstat (limited to 'libbe')
-rw-r--r--libbe/bugdir.py15
-rw-r--r--libbe/cmdutil.py13
2 files changed, 23 insertions, 5 deletions
diff --git a/libbe/bugdir.py b/libbe/bugdir.py
index 0008be8..4a79584 100644
--- a/libbe/bugdir.py
+++ b/libbe/bugdir.py
@@ -5,7 +5,7 @@ import errno
import names
import rcs
-class NoBugDir(cmdutil.UserError):
+class NoBugDir(Exception):
def __init__(self, path):
msg = "The directory \"%s\" has no bug directory." % path
Exception.__init__(self, msg)
@@ -53,17 +53,24 @@ class BugDir:
path = os.path.join(self.bugs_path, uuid)
rcs.mkdir(path)
return Bug(self.bugs_path, uuid)
-
+class InvalidValue(Exception):
+ def __init__(self, name, value):
+ msg = "Cannot assign value %s to %s" % (value, name)
+ Exception.__init__(self, msg)
+ self.name = name
+ self.value = value
def file_property(name, valid=None):
def getter(self):
value = self._get_value(name)
if valid is not None:
- assert value in valid
+ if value not in valid:
+ raise InvalidValue(name, value)
return value
def setter(self, value):
if valid is not None:
- assert value in valid
+ if value not in valid:
+ raise InvalidValue(name, value)
return self._set_value(name, value)
return property(getter, setter)
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py
index ac67f3a..2afd53c 100644
--- a/libbe/cmdutil.py
+++ b/libbe/cmdutil.py
@@ -1,3 +1,4 @@
+import bugdir
def unique_name(bug, bugs):
chars = 1
for some_bug in bugs:
@@ -11,8 +12,18 @@ class UserError(Exception):
def __init__(self, msg):
Exception.__init__(self, msg)
-def get_bug(spec, bug_dir):
+class UserErrorWrap(UserError):
+ def __init__(self, exception):
+ UserError.__init__(self, str(exception))
+ self.exception = exception
+
+def get_bug(spec, bug_dir=None):
matches = []
+ try:
+ if bug_dir is None:
+ bug_dir = bugdir.tree_root('.')
+ except bugdir.NoBugDir, e:
+ raise UserErrorWrap(e)
bugs = list(bug_dir.list())
for bug in bugs:
if bug.uuid.startswith(spec):