aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-07-12 14:32:55 -0400
committerW. Trevor King <wking@drexel.edu>2009-07-12 14:32:55 -0400
commitb5c4896d7ffd219a3118a3e6885db5956bf79e55 (patch)
tree1c09b1ce9989073027683409e5c028ae608bb29e /libbe
parent37c4e7f0f0d012e8df88b94022bc9a9d75373831 (diff)
downloadbugseverywhere-b5c4896d7ffd219a3118a3e6885db5956bf79e55.tar.gz
Added "be comment --xml --ignore-missing-references ID COMMENT".
Now you don't have to edit them out by hand.
Diffstat (limited to 'libbe')
-rw-r--r--libbe/cmdutil.py3
-rw-r--r--libbe/comment.py24
2 files changed, 23 insertions, 4 deletions
diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py
index b39aa51..0bee9db 100644
--- a/libbe/cmdutil.py
+++ b/libbe/cmdutil.py
@@ -71,7 +71,8 @@ def get_command(command_name):
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):
diff --git a/libbe/comment.py b/libbe/comment.py
index a085741..68deaf3 100644
--- a/libbe/comment.py
+++ b/libbe/comment.py
@@ -20,6 +20,7 @@
import base64
import os
import os.path
+import sys
import time
import types
try: # import core module, Python >= 2.5
@@ -54,9 +55,17 @@ class InvalidXML(ValueError):
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
@@ -88,8 +97,17 @@ def list_to_root(comments, bug, root=None):
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