From f0300038113e2754d83ee73f32a51072ad9b1f3b Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 10 Jul 2009 17:58:49 -0400 Subject: seems to work ;) --- becommands/comment.py | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'becommands') diff --git a/becommands/comment.py b/becommands/comment.py index 0b3a576..a11cd90 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -1,7 +1,6 @@ # Copyright (C) 2005-2009 Aaron Bentley and Panometrics, Inc. # Chris Ball # 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 @@ -17,9 +16,13 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """Add a comment to a bug""" -from libbe import cmdutil, bugdir, settings_object, editor +from libbe import cmdutil, bugdir, comment, settings_object, editor import os import sys +try: # import core module, Python >= 2.5 + from xml.etree import ElementTree +except ImportError: # look for non-core module + from elementtree import ElementTree __desc__ = __doc__ def execute(args, test=False): @@ -108,15 +111,45 @@ def execute(args, test=False): if not body.endswith('\n'): body+='\n' - comment = parent.new_reply(body=body) - if options.content_type != None: - comment.content_type = options.content_type + if options.XML == False: + new = parent.new_reply(body=body) + if options.content_type != None: + new.content_type = options.content_type + else: # import XML comment [list] + # read in the comments + comment_list = ElementTree.XML(body) + if comment_list.tag not in ["bug", "comment-list"]: + raise comment.InvalidXML( + comment_list, "root element must be or ") + new_comments = [] + uuids = [c.uuid for c in bug.comment_root.traverse()] # unique uuid check should be unique alt_id check + for child in comment_list.getchildren(): + if child.tag == "comment": + new = comment.Comment(bug) + new.from_xml(ElementTree.tostring(child)) + if new.uuid in uuids: + raise cmdutil.UserError( + "Clashing comment uuids: %s" % new.uuid) + uuids.append(new.uuid) + if new.in_reply_to in [settings_object.EMPTY, None]: + new.in_reply_to = parent.uuid + new_comments.append(new) + else: + print >> sys.stderr, "Ignoring unknown tag %s in %s" \ + % (child.tag, comment_list.tag) + comment.list_to_root(new_comments,bug,root=parent) # link new comments + # Protect against programmer error causing data loss: + kids = [c.uuid for c in parent.traverse()] + for nc in new_comments: + assert nc.uuid in kids, "%s wasn't added to %s" % (nc.uuid, parent.uuid) bd.save() def get_parser(): parser = cmdutil.CmdOptionParser("be comment ID [COMMENT]") parser.add_option("-c", "--content-type", metavar="MIME", dest="content_type", help="Set comment content-type (e.g. text/plain)", default=None) + parser.add_option("-x", "--xml", action="store_true", default=False, + dest='XML', help="Use COMMENT to specify an XML comment description rather than the comment body. The root XML element should be either or with one or more children. The syntax for the elements should match that generated by 'be show --xml COMMENT-ID'. Unrecognized tags are ignored. Missing tags are left at the default value (e.g. ) or auto-generated (e.g ). An exception is raised if conflicts with an existing comment.") # Are comment UUIDs global? no. should match on alt_id anyway... return parser longhelp=""" -- cgit