aboutsummaryrefslogtreecommitdiffstats
path: root/libbe/diff.py
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-12-05 01:58:41 -0500
committerW. Trevor King <wking@drexel.edu>2009-12-05 01:58:41 -0500
commit129c100046231ed15d2f16eaa90b5c01e41a442c (patch)
tree8f78ec47beb7f9d44fb8f72178d8b5f658d90b39 /libbe/diff.py
parent281e98e998b4a1ec550c6702aee0eead003905be (diff)
downloadbugseverywhere-129c100046231ed15d2f16eaa90b5c01e41a442c.tar.gz
Moved subscription types from becommands/subscribe.py to libbe/diff.py.
Diffstat (limited to 'libbe/diff.py')
-rw-r--r--libbe/diff.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/libbe/diff.py b/libbe/diff.py
index c25f7a7..66d9f4b 100644
--- a/libbe/diff.py
+++ b/libbe/diff.py
@@ -27,6 +27,52 @@ if libbe.TESTING == True:
import doctest
+class SubscriptionType (tree.Tree):
+ """
+ Trees of subscription types to allow users to select exactly what
+ notifications they want to subscribe to.
+ """
+ def __init__(self, type_name, *args, **kwargs):
+ tree.Tree.__init__(self, *args, **kwargs)
+ self.type = type_name
+ def __str__(self):
+ return self.type
+ def __repr__(self):
+ return "<SubscriptionType: %s>" % str(self)
+ def string_tree(self, indent=0):
+ lines = []
+ for depth,node in self.thread():
+ lines.append("%s%s" % (" "*(indent+2*depth), node))
+ return "\n".join(lines)
+
+BUGDIR_TYPE_NEW = SubscriptionType("new")
+BUGDIR_TYPE_ALL = SubscriptionType("all", [BUGDIR_TYPE_NEW])
+
+# same name as BUGDIR_TYPE_ALL for consistency
+BUG_TYPE_ALL = SubscriptionType(str(BUGDIR_TYPE_ALL))
+
+INVALID_TYPE = SubscriptionType("INVALID")
+
+class InvalidType (ValueError):
+ def __init__(self, type_name, type_root):
+ msg = "Invalid type %s for tree:\n%s" \
+ % (type_name, type_root.string_tree(4))
+ ValueError.__init__(self, msg)
+ self.type_name = type_name
+ self.type_root = type_root
+
+def type_from_name(name, type_root, default=None, default_ok=False):
+ if name == str(type_root):
+ return type_root
+ for t in type_root.traverse():
+ if name == str(t):
+ return t
+ if default_ok:
+ return default
+ raise InvalidType(name, type_root)
+
+
+
class DiffTree (tree.Tree):
"""
A tree holding difference data for easy report generation.