Add debug command
authorAlex Schroeder <alex@gnu.org>
Thu, 15 Aug 2019 14:47:25 +0000 (16:47 +0200)
committerAlex Schroeder <alex@gnu.org>
Thu, 15 Aug 2019 14:47:25 +0000 (16:47 +0200)
jan-pona-mute.py

index 8366ed55ac1ac674a70aca1b1a12564bc778ec73..64e37ee57d55817a4a9202027f11934daf526e1e 100755 (executable)
@@ -353,8 +353,8 @@ or get it from the cache."""
             try:
                 self.post = diaspy.models.Post(connection = self.connection, id = id)
                 self.post_cache[id] = self.post
-            except diaspy.errors.PostError:
-                print("Cannot load this post.")
+            except diaspy.errors.PostError as e:
+                print("Cannot load this post: %s" % e)
                 return None
         return self.post
 
@@ -711,6 +711,33 @@ the user enabled those."""
         else:
             shortcuts[words[0]] = words[1]
 
+    def do_debug(self, line):
+        """Debug notifications, posts, or comments."""
+        words = line.strip().split()
+        if len(words) != 2:
+            print("Debug takes two arguments: what to debug, and a number.")
+            return
+        if words[0] == "post":
+            items = self.home
+        elif words[0] == "notification":
+            items = self.notifications
+        elif words[0] == "comments":
+            if self.post == None:
+                print("Use the 'show' command to show a post, first.")
+                return
+            items = self.post.comments
+        try:
+            n = int(words[1])
+            item = items[n-1]
+        except ValueError:
+            print("Debugging a %s requires an integer." % words[0])
+            return
+        except IndexError:
+            print("There is no %s #%d" % n)
+            return
+        print(self.header("Debug %s #%d" % (words[0], n)))
+        print(item.__dict__)
+
 # Main function
 def main():