aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-12-05 04:11:39 -0500
committerW. Trevor King <wking@drexel.edu>2009-12-05 04:11:39 -0500
commitfbb8504a6c0438e90b046e44a60608159f4e3f63 (patch)
tree23358fae96603fd1a92ead1256f40456c7c02512
parente95de5d97dc05ce5dbb9a553d5e42e437ceccbbf (diff)
downloadbugseverywhere-fbb8504a6c0438e90b046e44a60608159f4e3f63.tar.gz
Created diff.subscriptions_from_string()
-rw-r--r--becommands/diff.py16
-rw-r--r--libbe/diff.py23
2 files changed, 28 insertions, 11 deletions
diff --git a/becommands/diff.py b/becommands/diff.py
index 5a94462..e2ff052 100644
--- a/becommands/diff.py
+++ b/becommands/diff.py
@@ -63,17 +63,11 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False):
revision = args[0]
if len(args) > 1:
raise cmdutil.UsageError('Too many arguments.')
- if options.subscribe == None:
- subscriptions = [diff.Subscription(diff.BUGDIR_ID,
- diff.BUGDIR_TYPE_ALL)]
- else:
- subscriptions = []
- for subscription in options.subscribe.split(','):
- fields = subscription.split(':')
- if len(fields) != 2:
- raise cmdutil.UsageError('Invalid subscription "%s", should be ID:TYPE')
- id,type = fields
- subscriptions.append(diff.Subscription(id, type))
+ try:
+ subscriptions = diff.subscriptions_from_string(
+ options.subscribe)
+ except ValueError, e:
+ raise cmdutil.UsageError(e.msg)
bd = bugdir.BugDir(from_disk=True,
manipulate_encodings=manipulate_encodings)
if bd.vcs.versioned == False:
diff --git a/libbe/diff.py b/libbe/diff.py
index 3122fe8..e947021 100644
--- a/libbe/diff.py
+++ b/libbe/diff.py
@@ -108,6 +108,29 @@ class Subscription (object):
def __repr__(self):
return "<Subscription: %s (%s)>" % (self.id, self.type)
+def subscriptions_from_string(string=None, subscription_sep=',', id_sep=':'):
+ """
+ >>> subscriptions_from_string(None)
+ [<Subscription: DIR (all)>]
+ >>> subscriptions_from_string('DIR:new,DIR:rem,ABC:all,XYZ:all')
+ [<Subscription: DIR (new)>, <Subscription: DIR (rem)>, <Subscription: ABC (all)>, <Subscription: XYZ (all)>]
+ >>> subscriptions_from_string('DIR::new')
+ Traceback (most recent call last):
+ ...
+ ValueError: Invalid subscription "DIR::new", should be ID:TYPE
+ """
+ if string == None:
+ return [Subscription(BUGDIR_ID, BUGDIR_TYPE_ALL)]
+ subscriptions = []
+ for subscription in string.split(','):
+ fields = subscription.split(':')
+ if len(fields) != 2:
+ raise ValueError('Invalid subscription "%s", should be ID:TYPE'
+ % subscription)
+ id,type = fields
+ subscriptions.append(Subscription(id, type))
+ return subscriptions
+
class DiffTree (tree.Tree):
"""
A tree holding difference data for easy report generation.