aboutsummaryrefslogtreecommitdiffstats
path: root/becommands/comment.py
diff options
context:
space:
mode:
Diffstat (limited to 'becommands/comment.py')
-rw-r--r--becommands/comment.py74
1 files changed, 52 insertions, 22 deletions
diff --git a/becommands/comment.py b/becommands/comment.py
index e3a1d93..172f818 100644
--- a/becommands/comment.py
+++ b/becommands/comment.py
@@ -15,39 +15,72 @@
# 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 bugdir, cmdutil, names, utility
+from libbe import cmdutil, bugdir, utility
import os
+__desc__ = __doc__
+
def execute(args):
"""
- >>> from libbe import tests, names
- >>> import os, time
- >>> dir = tests.simple_bug_dir()
- >>> os.chdir(dir.dir)
+ >>> import time
+ >>> bd = bugdir.simple_bug_dir()
+ >>> os.chdir(bd.root)
>>> execute(["a", "This is a comment about a"])
- >>> comment = dir.get_bug("a").list_comments()[0]
- >>> comment.body
- u'This is a comment about a\\n'
- >>> comment.From == names.creator()
+ >>> bd._clear_bugs()
+ >>> bug = bd.bug_from_shortname("a")
+ >>> bug.load_comments()
+ >>> comment = bug.comment_root[0]
+ >>> print comment.body
+ This is a comment about a
+ <BLANKLINE>
+ >>> comment.From == bd.user_id
True
- >>> comment.date <= int(time.time())
+ >>> comment.time <= int(time.time())
True
>>> comment.in_reply_to is None
True
+
>>> if 'EDITOR' in os.environ:
... del os.environ["EDITOR"]
>>> execute(["b"])
Traceback (most recent call last):
UserError: No comment supplied, and EDITOR not specified.
+
>>> os.environ["EDITOR"] = "echo 'I like cheese' > "
>>> execute(["b"])
- >>> dir.get_bug("b").list_comments()[0].body
- u'I like cheese\\n'
- >>> tests.clean_up()
+ >>> bd._clear_bugs()
+ >>> bug = bd.bug_from_shortname("b")
+ >>> bug.load_comments()
+ >>> comment = bug.comment_root[0]
+ >>> print comment.body
+ I like cheese
+ <BLANKLINE>
"""
options, args = get_parser().parse_args(args)
- if len(args) < 1:
- raise cmdutil.UsageError()
- bug, parent_comment = cmdutil.get_bug_and_comment(args[0])
+ if len(args) == 0:
+ raise cmdutil.UserError("Please specify a bug or comment id.")
+ if len(args) > 2:
+ help()
+ raise cmdutil.UserError("Too many arguments.")
+
+ shortname = args[0]
+ if shortname.count(':') > 1:
+ raise cmdutil.UserError("Invalid id '%s'." % shortname)
+ elif shortname.count(':') == 1:
+ # Split shortname generated by Comment.comment_shortnames()
+ bugname = shortname.split(':')[0]
+ is_reply = True
+ else:
+ bugname = shortname
+ is_reply = False
+
+ bd = bugdir.BugDir(from_disk=True)
+ bug = bd.bug_from_shortname(bugname)
+ bug.load_comments()
+ if is_reply:
+ parent = bug.comment_root.comment_from_shortname(shortname, bug_shortname=bugname)
+ else:
+ parent = bug.comment_root
+
if len(args) == 1:
try:
body = utility.editor_string("Please enter your comment above")
@@ -61,12 +94,9 @@ def execute(args):
body = args[1]
if not body.endswith('\n'):
body+='\n'
-
- comment = bugdir.new_comment(bug, body)
- if parent_comment is not None:
- comment.in_reply_to = parent_comment.uuid
- comment.save()
-
+
+ comment = parent.new_reply(body=body)
+ bd.save()
def get_parser():
parser = cmdutil.CmdOptionParser("be comment ID COMMENT")