diff options
-rw-r--r-- | becommands/comment.py | 27 | ||||
-rw-r--r-- | libbe/bug.py | 9 | ||||
-rw-r--r-- | libbe/cmdutil.py | 1 | ||||
-rw-r--r-- | libbe/comment.py | 6 |
4 files changed, 38 insertions, 5 deletions
diff --git a/becommands/comment.py b/becommands/comment.py index 5eac102..8fdbe42 100644 --- a/becommands/comment.py +++ b/becommands/comment.py @@ -57,7 +57,7 @@ def execute(args, test=False): """ parser = get_parser() options, args = parser.parse_args(args) - cmdutil.default_complete(options, args, parser) + complete(options, args, parser) if len(args) == 0: raise cmdutil.UsageError("Please specify a bug or comment id.") if len(args) > 2: @@ -113,3 +113,28 @@ created. def help(): return get_parser().help_str() + longhelp + +def complete(options, args, parser): + for option,value in cmdutil.option_value_pairs(options, parser): + if value == "--complete": + # no argument-options at the moment, so this is future-proofing + raise cmdutil.GetCompletions() + for pos,value in enumerate(args): + if value == "--complete": + if pos == 0: # fist positional argument is a bug or comment id + ids = [] + try: + bd = bugdir.BugDir(from_disk=True, + manipulate_encodings=False) + bd.load_all_bugs() + bugs = [bug for bug in bd if bug.active == True] + for bug in bugs: + shortname = bd.bug_shortname(bug) + ids.append(shortname) + bug.load_comments() + for id,comment in bug.comment_shortnames(shortname): + ids.append(id) + except bugdir.NoBugDir: + pass + raise cmdutil.GetCompletions(ids) + raise cmdutil.GetCompletions() diff --git a/libbe/bug.py b/libbe/bug.py index 67051f2..f47bcba 100644 --- a/libbe/bug.py +++ b/libbe/bug.py @@ -183,7 +183,7 @@ class Bug(object): if self._comments_loaded == False: self.load_comments() # take advantage of the string_thread(auto_name_map=True) - # SIDE-EFFECT of sorting by bug time. + # SIDE-EFFECT of sorting by comment time. comout = self.comment_root.string_thread(flatten=False, auto_name_map=True, bug_shortname=shortname) @@ -272,6 +272,13 @@ class Bug(object): def comment_from_uuid(self, uuid): return self.comment_root.comment_from_uuid(uuid) + def comment_shortnames(self, shortname=None): + """ + SIDE-EFFECT : Comment.comment_shortnames will sort the comment + tree by comment.time + """ + for id, comment in self.comment_root.comment_shortnames(shortname): + yield (id, comment) # the general rule for bug sorting is that "more important" bugs are # less than "less important" bugs. This way sorting a list of bugs diff --git a/libbe/cmdutil.py b/libbe/cmdutil.py index 0382664..eefed58 100644 --- a/libbe/cmdutil.py +++ b/libbe/cmdutil.py @@ -156,7 +156,6 @@ def default_complete(options, args, parser, bugid_args={}): bugs = [bug for bug in bd if filter(bug) == True] bugshortnames = [bd.bug_shortname(bug) for bug in bugs] except bugdir.NoBugDir: - bugshortnames = ["NOBUGDIR"] pass raise GetCompletions(bugshortnames) raise GetCompletions() diff --git a/libbe/comment.py b/libbe/comment.py index 0c8372e..ab0973d 100644 --- a/libbe/comment.py +++ b/libbe/comment.py @@ -249,7 +249,7 @@ class Comment(Tree): Return a sting displaying a thread of comments. bug_shortname is only used if auto_name_map == True. - SIDE-EFFECT: if auto_name_map==True, calls comment_shornames() + SIDE-EFFECT: if auto_name_map==True, calls comment_shortnames() which will sort the tree by comment.time. Avoid by calling name_map = {} for shortname,comment in comm.comment_shortnames(bug_shortname): @@ -334,7 +334,7 @@ class Comment(Tree): stringlist.append(comment.string(indent=ind, shortname=sname)) return '\n'.join(stringlist) - def comment_shortnames(self, bug_shortname=""): + def comment_shortnames(self, bug_shortname=None): """ Iterate through (id, comment) pairs, in time order. (This is a user-friendly id, not the comment uuid). @@ -355,6 +355,8 @@ class Comment(Tree): bug-1:3 c bug-1:4 d """ + if bug_shortname == None: + bug_shortname = "" self.sort(key=lambda comm : comm.time) for num,comment in enumerate(self.traverse()): yield ("%s:%d" % (bug_shortname, num+1), comment) |