From 3b168403ff5e50d767476c4c0f037d1841bb2bf9 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 21 Nov 2009 10:53:04 -0500 Subject: Broke `be comment --xml` out and extended into `be import-xml`. It should currently do everything that `be comment --xml` did, but it still has a way to go before it lives up to it's longhelp string, mostly figuring out bug/comment merging. The allowed XML format also changed a bit, becoming a bit more structured. cmdutil.bug_from_shortname() renamed to cmdutil.bug_from_id(). New functions cmdutil.parse_id() and cmdutil.bug_comment_from_id(). Additional doctests in libbe.comment.Comment.comment_shortnames() to show example output if bug_shortname==None. Brought be-xml-to-mbox and be-mbox-to-xml up to speed on the current -rooted format. * Added handling to their comment handling. * Moved extra strings from email bodies to X-Extra-String headers (some comment bodies are not text, and we should keep the estr location consistent between bugs and comments.) --- becommands/target.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'becommands/target.py') diff --git a/becommands/target.py b/becommands/target.py index 7e41451..672eb06 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -55,7 +55,7 @@ def execute(args, manipulate_encodings=True): if target and isinstance(target,str): print target return - bug = cmdutil.bug_from_shortname(bd, args[0]) + bug = cmdutil.bug_from_id(bd, args[0]) if len(args) == 1: if bug.target is None: print "No target assigned." -- cgit From 614d4e40e148520ac511cbe0606bcbdcf24c8a08 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 21 Nov 2009 15:18:02 -0500 Subject: Added restrict_file_access to becommands' execute() args. + associated adjustments in other files. See cmdutil.restrict_file_access.__doc__ for an explanation of the security hole this closes. --- becommands/target.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'becommands/target.py') diff --git a/becommands/target.py b/becommands/target.py index 672eb06..efb2479 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -22,7 +22,7 @@ from libbe import cmdutil, bugdir __desc__ = __doc__ -def execute(args, manipulate_encodings=True): +def execute(args, manipulate_encodings=True, restrict_file_access=False): """ >>> import os >>> bd = bugdir.SimpleBugDir() -- cgit From c90ed61e7deb594edf3707850f2d3a87601a581b Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 28 Nov 2009 20:24:19 -0500 Subject: BugDir.list_uuids() -> BugDir.uuids() --- becommands/target.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'becommands/target.py') diff --git a/becommands/target.py b/becommands/target.py index efb2479..9a202b1 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -50,7 +50,7 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): bd = bugdir.BugDir(from_disk=True, manipulate_encodings=manipulate_encodings) if options.list: - ts = set([bd.bug_from_uuid(bug).target for bug in bd.list_uuids()]) + ts = set([bd.bug_from_uuid(bug).target for bug in bd.uuids()]) for target in sorted(ts): if target and isinstance(target,str): print target -- cgit From 2a7cf58a422bcd55478cea92c5f859df86c911a4 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 5 Dec 2009 23:52:07 -0500 Subject: `be target` gains --resolve and loses --list. `be target` now works with bug-style targets. --- becommands/target.py | 127 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 98 insertions(+), 29 deletions(-) (limited to 'becommands/target.py') diff --git a/becommands/target.py b/becommands/target.py index 9a202b1..fbc4b37 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -18,13 +18,14 @@ # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -"""Show or change a bug's target for fixing""" +"""Assorted bug target manipulations and queries""" from libbe import cmdutil, bugdir +from becommands import depend __desc__ = __doc__ def execute(args, manipulate_encodings=True, restrict_file_access=False): """ - >>> import os + >>> import os, StringIO, sys >>> bd = bugdir.SimpleBugDir() >>> os.chdir(bd.root) >>> execute(["a"], manipulate_encodings=False) @@ -32,8 +33,19 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): >>> execute(["a", "tomorrow"], manipulate_encodings=False) >>> execute(["a"], manipulate_encodings=False) tomorrow - >>> execute(["--list"], manipulate_encodings=False) + + >>> orig_stdout = sys.stdout + >>> tmp_stdout = StringIO.StringIO() + >>> sys.stdout = tmp_stdout + >>> execute(["--resolve", "tomorrow"], manipulate_encodings=False) + >>> sys.stdout = orig_stdout + >>> output = tmp_stdout.getvalue().strip() + >>> target = bd.bug_from_uuid(output) + >>> print target.summary tomorrow + >>> print target.severity + target + >>> execute(["a", "none"], manipulate_encodings=False) >>> execute(["a"], manipulate_encodings=False) No target assigned. @@ -44,52 +56,109 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): cmdutil.default_complete(options, args, parser, bugid_args={0: lambda bug : bug.active==True}) - if len(args) not in (1, 2): - if not (options.list == True and len(args) == 0): - raise cmdutil.UsageError + if (options.resolve == False and len(args) not in (1, 2)) \ + or (options.resolve == True and len(args) not in (0, 1)): + raise cmdutil.UsageError('Incorrect number of arguments.') bd = bugdir.BugDir(from_disk=True, manipulate_encodings=manipulate_encodings) - if options.list: - ts = set([bd.bug_from_uuid(bug).target for bug in bd.uuids()]) - for target in sorted(ts): - if target and isinstance(target,str): - print target + if options.resolve == True: + if len(args) == 0: + summary = None + else: + summary = args[0] + bug = bug_from_target_summary(bd, summary) + if bug == None: + print 'No target assigned.' + else: + print bug.uuid return bug = cmdutil.bug_from_id(bd, args[0]) if len(args) == 1: - if bug.target is None: + target = bug_target(bd, bug) + if target is None: print "No target assigned." else: - print bug.target + print target.summary else: - assert len(args) == 2 if args[1] == "none": - bug.target = None + target = remove_target(bd, bug) else: - bug.target = args[1] + target = add_target(bd, bug, args[1]) def get_parser(): - parser = cmdutil.CmdOptionParser("be target BUG-ID [TARGET]\nor: be target --list") - parser.add_option("-l", "--list", action="store_true", dest="list", - help="List all available targets and exit") + parser = cmdutil.CmdOptionParser("be target BUG-ID [TARGET]\nor: be target --resolve [TARGET]") + parser.add_option("-r", "--resolve", action="store_true", dest="resolve", + help="Print the UUID for the target bug whose summary matches TARGET. If TARGET is not given, print the UUID of the current bugdir target. If that is not set, don't print anything.", + default=False) return parser longhelp=""" -Show or change a bug's target for fixing. +Assorted bug target manipulations and queries. + +If no target is specified, the bug's current target is printed. If +TARGET is specified, it will be assigned to the bug, creating a new +target bug if necessary. -If no target is specified, the current value is printed. If a target -is specified, it will be assigned to the bug. +Targets are free-form; any text may be specified. They will generally +be milestone names or release numbers. The value "none" can be used +to unset the target. -Targets are freeform; any text may be specified. They will generally be -milestone names or release numbers. +In the alternative `be target --resolve TARGET` form, print the UUID +of the target-bug with summary TARGET. If target is not given, return +use the bugdir's current target (see `be set`). -The value "none" can be used to unset the target. +If you want to list all bugs blocking the current target, try + $ be depend --status -closed,fixed,wontfix --severity -target \ + $(be target --resolve) -In the alternative `be target --list` form print a list of all -currently specified targets. Note that bug status -(i.e. opened/closed) is ignored. If you want to list all bugs -matching a current target, see `be list --target TARGET'. +If you want to set the current bugdir target by summary (rather than +by UUID), try + $ be set target $(be target --resolve SUMMARY) """ def help(): return get_parser().help_str() + longhelp + +def bug_from_target_summary(bugdir, summary=None): + if summary == None: + if bugdir.target == None: + return None + else: + return bugdir.bug_from_uuid(bugdir.target) + matched = [] + for uuid in bugdir.uuids(): + bug = bugdir.bug_from_uuid(uuid) + if bug.severity == 'target' and bug.summary == summary: + matched.append(bug) + if len(matched) == 0: + return None + if len(matched) > 1: + raise Exception('Several targets with same summary: %s' + % '\n '.join([bug.uuid for bug in matched])) + return matched[0] + +def bug_target(bugdir, bug): + matched = [] + for blocked in depend.get_blocks(bugdir, bug): + if blocked.severity == 'target': + matched.append(blocked) + if len(matched) == 0: + return None + if len(matched) > 1: + raise Exception('This bug (%s) blocks several targets: %s' + % (bug.uuid, + '\n '.join([b.uuid for b in matched]))) + return matched[0] + +def remove_target(bugdir, bug): + target = bug_target(bugdir, bug) + depend.remove_block(target, bug) + return target + +def add_target(bugdir, bug, summary): + target = bug_from_target_summary(bugdir, summary) + if target == None: + target = bugdir.new_bug(summary=summary) + target.severity = 'target' + depend.add_block(target, bug) + return target -- cgit From bca7a2a9311a5a23d98229d9918b13d66302537e Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 6 Dec 2009 03:11:39 -0500 Subject: becommands.target.bug_target(TARGET-BUG) now returns TARGET-BUG --- becommands/target.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'becommands/target.py') diff --git a/becommands/target.py b/becommands/target.py index fbc4b37..9ccbacc 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -138,6 +138,8 @@ def bug_from_target_summary(bugdir, summary=None): return matched[0] def bug_target(bugdir, bug): + if bug.severity == 'target': + return bug matched = [] for blocked in depend.get_blocks(bugdir, bug): if blocked.severity == 'target': -- cgit From fdf9925ffaada614544d1b2d3ccecb42f1549acb Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 7 Dec 2009 07:18:48 -0500 Subject: be --dir DIR COMMAND now roots the bugdir in DIR without changing directories. Previously, for the directory structure A |-- X `-- Y You could do something like A$ be --dir X diff --dir ../Y Now it's A$ be --dir X diff --dir Y The --root option to `be init` has been removed as redundant. Replace calls like be init --root DIR with be --dir DIR init --- becommands/target.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'becommands/target.py') diff --git a/becommands/target.py b/becommands/target.py index 9ccbacc..5dd5d38 100644 --- a/becommands/target.py +++ b/becommands/target.py @@ -23,7 +23,8 @@ from libbe import cmdutil, bugdir from becommands import depend __desc__ = __doc__ -def execute(args, manipulate_encodings=True, restrict_file_access=False): +def execute(args, manipulate_encodings=True, restrict_file_access=False, + dir="."): """ >>> import os, StringIO, sys >>> bd = bugdir.SimpleBugDir() @@ -60,7 +61,8 @@ def execute(args, manipulate_encodings=True, restrict_file_access=False): or (options.resolve == True and len(args) not in (0, 1)): raise cmdutil.UsageError('Incorrect number of arguments.') bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings) + manipulate_encodings=manipulate_encodings, + root=dir) if options.resolve == True: if len(args) == 0: summary = None -- cgit From 49a7771336ce09f6d42c7699ef32aecea0e83182 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 7 Dec 2009 20:07:55 -0500 Subject: Initial directory restructuring to clarify dependencies --- becommands/target.py | 168 --------------------------------------------------- 1 file changed, 168 deletions(-) delete mode 100644 becommands/target.py (limited to 'becommands/target.py') diff --git a/becommands/target.py b/becommands/target.py deleted file mode 100644 index 5dd5d38..0000000 --- a/becommands/target.py +++ /dev/null @@ -1,168 +0,0 @@ -# Copyright (C) 2005-2009 Aaron Bentley and Panometrics, Inc. -# Chris Ball -# Gianluca Montecchi -# Marien Zwart -# Thomas Gerigk -# W. Trevor King -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -"""Assorted bug target manipulations and queries""" -from libbe import cmdutil, bugdir -from becommands import depend -__desc__ = __doc__ - -def execute(args, manipulate_encodings=True, restrict_file_access=False, - dir="."): - """ - >>> import os, StringIO, sys - >>> bd = bugdir.SimpleBugDir() - >>> os.chdir(bd.root) - >>> execute(["a"], manipulate_encodings=False) - No target assigned. - >>> execute(["a", "tomorrow"], manipulate_encodings=False) - >>> execute(["a"], manipulate_encodings=False) - tomorrow - - >>> orig_stdout = sys.stdout - >>> tmp_stdout = StringIO.StringIO() - >>> sys.stdout = tmp_stdout - >>> execute(["--resolve", "tomorrow"], manipulate_encodings=False) - >>> sys.stdout = orig_stdout - >>> output = tmp_stdout.getvalue().strip() - >>> target = bd.bug_from_uuid(output) - >>> print target.summary - tomorrow - >>> print target.severity - target - - >>> execute(["a", "none"], manipulate_encodings=False) - >>> execute(["a"], manipulate_encodings=False) - No target assigned. - >>> bd.cleanup() - """ - parser = get_parser() - options, args = parser.parse_args(args) - cmdutil.default_complete(options, args, parser, - bugid_args={0: lambda bug : bug.active==True}) - - if (options.resolve == False and len(args) not in (1, 2)) \ - or (options.resolve == True and len(args) not in (0, 1)): - raise cmdutil.UsageError('Incorrect number of arguments.') - bd = bugdir.BugDir(from_disk=True, - manipulate_encodings=manipulate_encodings, - root=dir) - if options.resolve == True: - if len(args) == 0: - summary = None - else: - summary = args[0] - bug = bug_from_target_summary(bd, summary) - if bug == None: - print 'No target assigned.' - else: - print bug.uuid - return - bug = cmdutil.bug_from_id(bd, args[0]) - if len(args) == 1: - target = bug_target(bd, bug) - if target is None: - print "No target assigned." - else: - print target.summary - else: - if args[1] == "none": - target = remove_target(bd, bug) - else: - target = add_target(bd, bug, args[1]) - -def get_parser(): - parser = cmdutil.CmdOptionParser("be target BUG-ID [TARGET]\nor: be target --resolve [TARGET]") - parser.add_option("-r", "--resolve", action="store_true", dest="resolve", - help="Print the UUID for the target bug whose summary matches TARGET. If TARGET is not given, print the UUID of the current bugdir target. If that is not set, don't print anything.", - default=False) - return parser - -longhelp=""" -Assorted bug target manipulations and queries. - -If no target is specified, the bug's current target is printed. If -TARGET is specified, it will be assigned to the bug, creating a new -target bug if necessary. - -Targets are free-form; any text may be specified. They will generally -be milestone names or release numbers. The value "none" can be used -to unset the target. - -In the alternative `be target --resolve TARGET` form, print the UUID -of the target-bug with summary TARGET. If target is not given, return -use the bugdir's current target (see `be set`). - -If you want to list all bugs blocking the current target, try - $ be depend --status -closed,fixed,wontfix --severity -target \ - $(be target --resolve) - -If you want to set the current bugdir target by summary (rather than -by UUID), try - $ be set target $(be target --resolve SUMMARY) -""" - -def help(): - return get_parser().help_str() + longhelp - -def bug_from_target_summary(bugdir, summary=None): - if summary == None: - if bugdir.target == None: - return None - else: - return bugdir.bug_from_uuid(bugdir.target) - matched = [] - for uuid in bugdir.uuids(): - bug = bugdir.bug_from_uuid(uuid) - if bug.severity == 'target' and bug.summary == summary: - matched.append(bug) - if len(matched) == 0: - return None - if len(matched) > 1: - raise Exception('Several targets with same summary: %s' - % '\n '.join([bug.uuid for bug in matched])) - return matched[0] - -def bug_target(bugdir, bug): - if bug.severity == 'target': - return bug - matched = [] - for blocked in depend.get_blocks(bugdir, bug): - if blocked.severity == 'target': - matched.append(blocked) - if len(matched) == 0: - return None - if len(matched) > 1: - raise Exception('This bug (%s) blocks several targets: %s' - % (bug.uuid, - '\n '.join([b.uuid for b in matched]))) - return matched[0] - -def remove_target(bugdir, bug): - target = bug_target(bugdir, bug) - depend.remove_block(target, bug) - return target - -def add_target(bugdir, bug, summary): - target = bug_from_target_summary(bugdir, summary) - if target == None: - target = bugdir.new_bug(summary=summary) - target.severity = 'target' - depend.add_block(target, bug) - return target -- cgit