Now you don't have to edit them out by hand.
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
+ try:
+ comment.list_to_root(new_comments,bug,root=parent, # link new comments
+ ignore_missing_references=options.ignore_missing_references)
+ except comment.MissingReference, e:
+ raise cmdutil.UserError(e)
# Protect against programmer error causing data loss:
kids = [c.uuid for c in parent.traverse()]
for nc in new_comments:
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. The comment UUIDs are always auto-generated, so if you set a <uuid> field, but no <alt-id> field, your <uuid> will be used as the comment's <alt-id>. An exception is raised if <alt-id> conflicts with an existing comment.")
+ parser.add_option("-i", "--ignore-missing-references", action="store_true",
+ dest="ignore_missing_references",
+ help="For XML import, if any comment's <in-reply-to> refers to a non-existent comment, ignore it (instead of raising an exception).")
return parser
longhelp="""
def execute(cmd, args):
enc = encoding.get_encoding()
- get_command(cmd).execute([a.decode(enc) for a in args])
+ cmd = get_command(cmd)
+ cmd.execute([a.decode(enc) for a in args])
return 0
def help(cmd=None):
import base64
import os
import os.path
+import sys
import time
import types
try: # import core module, Python >= 2.5
self.element = element
self.comment = comment
+class MissingReference(ValueError):
+ def __init__(self, comment):
+ msg = "Missing reference to %s" % (comment.in_reply_to)
+ ValueError.__init__(self, msg)
+ self.reference = comment.in_reply_to
+ self.comment = comment
+
INVALID_UUID = "!!~~\n INVALID-UUID \n~~!!"
-def list_to_root(comments, bug, root=None):
+def list_to_root(comments, bug, root=None,
+ ignore_missing_references=False):
"""
Convert a raw list of comments to single root comment. We use a
dummy root comment by default, because there can be several
root_comments.append(comm)
else:
parentUUID = comm.in_reply_to
- parent = uuid_map[parentUUID]
- parent.add_reply(comm)
+ try:
+ parent = uuid_map[parentUUID]
+ parent.add_reply(comm)
+ except KeyError, e:
+ if ignore_missing_references == True:
+ print >> sys.stderr, \
+ "Ignoring missing reference to %s" % parentUUID
+ comm.in_reply_to = None
+ root_comments.append(comm)
+ else:
+ raise MissingReference(comm)
root.extend(root_comments)
return root