From fbb8504a6c0438e90b046e44a60608159f4e3f63 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 5 Dec 2009 04:11:39 -0500 Subject: [PATCH] Created diff.subscriptions_from_string() --- becommands/diff.py | 16 +++++----------- libbe/diff.py | 23 +++++++++++++++++++++++ 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 "" % (self.id, self.type) +def subscriptions_from_string(string=None, subscription_sep=',', id_sep=':'): + """ + >>> subscriptions_from_string(None) + [] + >>> subscriptions_from_string('DIR:new,DIR:rem,ABC:all,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. -- 2.26.2