From: Alex Schroeder Date: Thu, 15 Aug 2019 14:47:25 +0000 (+0200) Subject: Add debug command X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=33144acdd404facd90fad4deaa15389ee5d745ac;p=jan-pona-mute.git Add debug command --- diff --git a/jan-pona-mute.py b/jan-pona-mute.py index 8366ed5..64e37ee 100755 --- a/jan-pona-mute.py +++ b/jan-pona-mute.py @@ -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():