Added becommands/comment completion.
authorW. Trevor King <wking@drexel.edu>
Thu, 27 Nov 2008 16:34:44 +0000 (11:34 -0500)
committerW. Trevor King <wking@drexel.edu>
Thu, 27 Nov 2008 16:34:44 +0000 (11:34 -0500)
becommands/comment.py
libbe/bug.py
libbe/cmdutil.py
libbe/comment.py

index 5eac102f37ae3777a9fe45641fa1038200b1487c..8fdbe429ab98bb8085aaf53b625ea226806e458f 100644 (file)
@@ -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()
index 67051f2e8ab7ed672723a4b2d077bffe8e70a621..f47bcba3e7120d21aa2e1e370c422af0c296628f 100644 (file)
@@ -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
index 03826641f44e544c0e296c6ecc1adaf6dccdb6e9..eefed5835a970724169283a2058ee6757bb39e16 100644 (file)
@@ -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()
index 0c8372e3407b5ecf3bd19833a840d47199442317..ab0973d5fe4619bed00cfa796c87882dc577fd02 100644 (file)
@@ -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)