diff options
author | W. Trevor King <wking@drexel.edu> | 2009-12-05 20:52:29 -0500 |
---|---|---|
committer | W. Trevor King <wking@drexel.edu> | 2009-12-05 20:52:29 -0500 |
commit | 1e32ab1eb4b4ed4d19de8514db1fd8c1b4fafc4e (patch) | |
tree | 25e326b3456fa26da755352c12b20e2246e1b8a4 | |
parent | f4a87cfb4fd66ad14ab6d077fe2defcb76dd2972 (diff) | |
download | bugseverywhere-1e32ab1eb4b4ed4d19de8514db1fd8c1b4fafc4e.tar.gz |
Added --limit-status and --limit-severity to `be depend'.
Currently only effective in tree mode, but that's where it matters
most.
-rw-r--r-- | becommands/depend.py | 91 |
1 files changed, 79 insertions, 12 deletions
diff --git a/becommands/depend.py b/becommands/depend.py index f50d693..6cf42eb 100644 --- a/becommands/depend.py +++ b/becommands/depend.py @@ -15,7 +15,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """Add/remove bug dependencies""" -from libbe import cmdutil, bugdir, tree +from libbe import cmdutil, bugdir, bug, tree import os, copy __desc__ = __doc__ @@ -69,8 +69,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): parser = get_parser() options, args = parser.parse_args(args) cmdutil.default_complete(options, args, parser, - bugid_args={0: lambda bug : bug.active==True, - 1: lambda bug : bug.active==True}) + bugid_args={0: lambda _bug : _bug.active==True, + 1: lambda _bug : _bug.active==True}) if options.repair == True: if len(args) > 0: @@ -82,7 +82,6 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): raise cmdutil.UsageError("Too many arguments.") elif len(args) == 2 and options.tree_depth != None: raise cmdutil.UsageError("Only one bug id used in tree mode.") - bd = bugdir.BugDir(from_disk=True, manipulate_encodings=manipulate_encodings) @@ -95,10 +94,16 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): for blockee,blocker in fixed]) return 0 + allowed_status_values = _allowed_values(options.limit_status, + bug.status_values) + allowed_severity_values = _allowed_values(options.limit_severity, + bug.severity_values) bugA = cmdutil.bug_from_id(bd, args[0]) if options.tree_depth != None: - dtree = DependencyTree(bd, bugA, options.tree_depth) + dtree = DependencyTree(bd, bugA, options.tree_depth, + allowed_status_values, + allowed_severity_values) if len(dtree.blocked_by_tree()) > 0: print "%s blocked by:" % bugA.uuid for depth,node in dtree.blocked_by_tree().thread(): @@ -122,18 +127,18 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): if len(blocked_by) > 0: print "%s blocked by:" % bugA.uuid if options.show_status == True: - print '\n'.join(["%s\t%s" % (bug.uuid, bug.status) - for bug in blocked_by]) + print '\n'.join(["%s\t%s" % (_bug.uuid, _bug.status) + for _bug in blocked_by]) else: - print '\n'.join([bug.uuid for bug in blocked_by]) + print '\n'.join([_bug.uuid for _bug in blocked_by]) blocks = get_blocks(bd, bugA) if len(blocks) > 0: print "%s blocks:" % bugA.uuid if options.show_status == True: - print '\n'.join(["%s\t%s" % (bug.uuid, bug.status) - for bug in blocks]) + print '\n'.join(["%s\t%s" % (_bug.uuid, _bug.status) + for _bug in blocks]) else: - print '\n'.join([bug.uuid for bug in blocks]) + print '\n'.join([_bug.uuid for _bug in blocks]) def get_parser(): parser = cmdutil.CmdOptionParser("be depend BUG-ID [BUG-ID]\nor: be depend --repair") @@ -143,6 +148,11 @@ def get_parser(): parser.add_option("-s", "--show-status", action="store_true", dest="show_status", default=False, help="Show status of blocking bugs") + parser.add_option("--limit-status", dest="limit_status", metavar="STATUS", + help="Only show bugs matching the STATUS specifier") + parser.add_option("--limit-severity", dest="limit_severity", + metavar="SEVERITY", + help="Only show bugs matching the SEVERITY specifier") parser.add_option("-t", "--tree-depth", metavar="DEPTH", default=None, type="int", dest="tree_depth", help="Print dependency tree rooted at BUG-ID with DEPTH levels of both blockers and blockees. Set DEPTH <= 0 to disable the depth limit.") @@ -158,6 +168,15 @@ If bug B is not specified, just print a list of bugs blocking (A). To search for bugs blocked by a particular bug, try $ be list --extra-strings BLOCKED-BY:<your-bug-uuid> +The --limit-* options allow you to either blacklist or whitelist +values, for example + $ be list --limit-status open,assigned +will only follow and print dependencies with open or assigned status. +You select blacklist mode by starting the list with a minus sign, for +example + $ be list --limit-severity -target +which will only follow and print dependencies with non-target severity. + In repair mode, add the missing direction to any one-way links. The "|--" symbol in the repair-mode output is inspired by the @@ -170,6 +189,44 @@ def help(): # internal helper functions +def _allowed_values(limit_string, possible_values, name="unkown"): + """ + >>> _allowed_values(None, ['abc', 'def', 'hij']) + ['abc', 'def', 'hij'] + >>> _allowed_values('-abc,hij', ['abc', 'def', 'hij']) + ['def'] + >>> _allowed_values('abc,hij', ['abc', 'def', 'hij']) + ['abc', 'hij'] + >>> _allowed_values('-xyz,hij', ['abc', 'def', 'hij'], name="value") + Traceback (most recent call last): + ... + UserError: Invalid value xyz + ['abc', 'def', 'hij'] + >>> _allowed_values('xyz,hij', ['abc', 'def', 'hij'], name="value") + Traceback (most recent call last): + ... + UserError: Invalid value xyz + ['abc', 'def', 'hij'] + """ + possible_values = list(possible_values) # don't alter the original + if limit_string == None: + pass + elif limit_string.startswith('-'): + blacklisted_values = set(limit_string[1:].split(',')) + for value in blacklisted_values: + if value not in possible_values: + raise cmdutil.UserError('Invalid %s %s\n %s' + % (name, value, possible_values)) + possible_values.remove(value) + else: + whitelisted_values = limit_string.split(',') + for value in whitelisted_values: + if value not in possible_values: + raise cmdutil.UserError('Invalid %s %s\n %s' + % (name, value, possible_values)) + possible_values = whitelisted_values + return possible_values + def _generate_blocks_string(blocked_bug): return "%s%s" % (BLOCKS_TAG, blocked_bug.uuid) @@ -310,10 +367,14 @@ class DependencyTree (object): """ Note: should probably be DependencyDiGraph. """ - def __init__(self, bugdir, root_bug, depth_limit=0): + def __init__(self, bugdir, root_bug, depth_limit=0, + allowed_status_values=None, + allowed_severity_values=None): self.bugdir = bugdir self.root_bug = root_bug self.depth_limit = depth_limit + self.allowed_status_values = allowed_status_values + self.allowed_severity_values = allowed_severity_values def _build_tree(self, child_fn): root = tree.Tree() root.bug = self.root_bug @@ -324,6 +385,12 @@ class DependencyTree (object): if self.depth_limit > 0 and node.depth == self.depth_limit: continue for bug in child_fn(self.bugdir, node.bug): + if self.allowed_status_values != None \ + and not bug.status in self.allowed_status_values: + continue + if self.allowed_severity_values != None \ + and not bug.severity in self.allowed_severity_values: + continue child = tree.Tree() child.bug = bug child.depth = node.depth+1 |