aboutsummaryrefslogtreecommitdiffstats
path: root/becommands
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-07-10 17:58:49 -0400
committerW. Trevor King <wking@drexel.edu>2009-07-10 17:58:49 -0400
commitf0300038113e2754d83ee73f32a51072ad9b1f3b (patch)
treed0f0f0a8aaff5d812b77b78f82fda9ccabd5c7fe /becommands
parentc5da71a900d6263e29deb94d81aa22e6ba6f34ea (diff)
downloadbugseverywhere-f0300038113e2754d83ee73f32a51072ad9b1f3b.tar.gz
seems to work ;)
Diffstat (limited to 'becommands')
-rw-r--r--becommands/comment.py43
1 files changed, 38 insertions, 5 deletions
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 <cjb@laptop.org>
# W. Trevor King <wking@drexel.edu>
-# <abentley@panoramicfeedback.com>
#
# 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 <bug> or <comment-list>")
+ 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 <bug> or <comment-list> with one or more <comment> children. The syntax for the <comment> 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. <content-type>) or auto-generated (e.g <uuid>). An exception is raised if <uuid> conflicts with an existing comment.") # Are comment UUIDs global? no. should match on alt_id anyway...
return parser
longhelp="""