diff sat_frontends/jp/cmd_bookmarks.py @ 3568:04283582966f

core, frontends: fix invalid translatable strings. Some f-strings where used in translatable text, this has been fixed by using explicit `format()` call (using a script based on `tokenize`). As tokenize messes with spaces, a reformating tool (`black`) has been applied to some files afterwards.
author Goffi <goffi@goffi.org>
date Mon, 14 Jun 2021 18:35:12 +0200
parents be6d91572633
children 524856bd7b19
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_bookmarks.py	Mon Jun 14 12:19:21 2021 +0200
+++ b/sat_frontends/jp/cmd_bookmarks.py	Mon Jun 14 18:35:12 2021 +0200
@@ -23,25 +23,41 @@
 
 __commands__ = ["Bookmarks"]
 
-STORAGE_LOCATIONS = ('local', 'private', 'pubsub')
-TYPES = ('muc', 'url')
+STORAGE_LOCATIONS = ("local", "private", "pubsub")
+TYPES = ("muc", "url")
+
 
 class BookmarksCommon(base.CommandBase):
     """Class used to group common options of bookmarks subcommands"""
 
-    def add_parser_options(self, location_default='all'):
-        self.parser.add_argument('-l', '--location', type=str, choices=(location_default,) + STORAGE_LOCATIONS, default=location_default, help=_("storage location (default: %(default)s)"))
-        self.parser.add_argument('-t', '--type', type=str, choices=TYPES, default=TYPES[0], help=_("bookmarks type (default: %(default)s)"))
+    def add_parser_options(self, location_default="all"):
+        self.parser.add_argument(
+            "-l",
+            "--location",
+            type=str,
+            choices=(location_default,) + STORAGE_LOCATIONS,
+            default=location_default,
+            help=_("storage location (default: %(default)s)"),
+        )
+        self.parser.add_argument(
+            "-t",
+            "--type",
+            type=str,
+            choices=TYPES,
+            default=TYPES[0],
+            help=_("bookmarks type (default: %(default)s)"),
+        )
+
 
 class BookmarksList(BookmarksCommon):
-
     def __init__(self, host):
-        super(BookmarksList, self).__init__(host, 'list', help=_('list bookmarks'))
+        super(BookmarksList, self).__init__(host, "list", help=_("list bookmarks"))
 
     async def start(self):
         try:
             data = await self.host.bridge.bookmarksList(
-                self.args.type, self.args.location, self.host.profile)
+                self.args.type, self.args.location, self.host.profile
+            )
         except Exception as e:
             self.disp(f"can't get bookmarks list: {e}", error=True)
             self.host.quit(C.EXIT_BRIDGE_ERRBACK)
@@ -54,32 +70,40 @@
             loc_mess.append(f"{location}:")
             book_mess = []
             for book_link, book_data in list(data[location].items()):
-                name = book_data.get('name')
-                autojoin = book_data.get('autojoin', 'false') == 'true'
-                nick = book_data.get('nick')
-                book_mess.append("\t%s[%s%s]%s" % ((name+' ') if name else '',
-                                                 book_link,
-                                                 ' (%s)' % nick if nick else '',
-                                                 ' (*)' if autojoin else ''))
-            loc_mess.append('\n'.join(book_mess))
-            mess.append('\n'.join(loc_mess))
+                name = book_data.get("name")
+                autojoin = book_data.get("autojoin", "false") == "true"
+                nick = book_data.get("nick")
+                book_mess.append(
+                    "\t%s[%s%s]%s"
+                    % (
+                        (name + " ") if name else "",
+                        book_link,
+                        " (%s)" % nick if nick else "",
+                        " (*)" if autojoin else "",
+                    )
+                )
+            loc_mess.append("\n".join(book_mess))
+            mess.append("\n".join(loc_mess))
 
-        print('\n\n'.join(mess))
+        print("\n\n".join(mess))
         self.host.quit()
 
 
 class BookmarksRemove(BookmarksCommon):
-
     def __init__(self, host):
-        super(BookmarksRemove, self).__init__(host, 'remove', help=_('remove a bookmark'))
+        super(BookmarksRemove, self).__init__(host, "remove", help=_("remove a bookmark"))
 
     def add_parser_options(self):
         super(BookmarksRemove, self).add_parser_options()
         self.parser.add_argument(
-            'bookmark', help=_('jid (for muc bookmark) or url of to remove'))
+            "bookmark", help=_("jid (for muc bookmark) or url of to remove")
+        )
         self.parser.add_argument(
-            "-f", "--force", action="store_true",
-            help=_("delete bookmark without confirmation"),)
+            "-f",
+            "--force",
+            action="store_true",
+            help=_("delete bookmark without confirmation"),
+        )
 
     async def start(self):
         if not self.args.force:
@@ -87,50 +111,58 @@
 
         try:
             await self.host.bridge.bookmarksRemove(
-                self.args.type, self.args.bookmark, self.args.location, self.host.profile)
+                self.args.type, self.args.bookmark, self.args.location, self.host.profile
+            )
         except Exception as e:
-            self.disp(_(f"can't delete bookmark: {e}"), error=True)
+            self.disp(_("can't delete bookmark: {e}").format(e=e), error=True)
             self.host.quit(C.EXIT_BRIDGE_ERRBACK)
         else:
-            self.disp(_('bookmark deleted'))
+            self.disp(_("bookmark deleted"))
             self.host.quit()
 
 
 class BookmarksAdd(BookmarksCommon):
-
     def __init__(self, host):
-        super(BookmarksAdd, self).__init__(host, 'add', help=_('add a bookmark'))
+        super(BookmarksAdd, self).__init__(host, "add", help=_("add a bookmark"))
 
     def add_parser_options(self):
-        super(BookmarksAdd, self).add_parser_options(location_default='auto')
+        super(BookmarksAdd, self).add_parser_options(location_default="auto")
         self.parser.add_argument(
-            'bookmark', help=_('jid (for muc bookmark) or url of to remove'))
-        self.parser.add_argument('-n', '--name', help=_("bookmark name"))
-        muc_group = self.parser.add_argument_group(_('MUC specific options'))
-        muc_group.add_argument('-N', '--nick', help=_('nickname'))
+            "bookmark", help=_("jid (for muc bookmark) or url of to remove")
+        )
+        self.parser.add_argument("-n", "--name", help=_("bookmark name"))
+        muc_group = self.parser.add_argument_group(_("MUC specific options"))
+        muc_group.add_argument("-N", "--nick", help=_("nickname"))
         muc_group.add_argument(
-            '-a', '--autojoin', action='store_true',
-            help=_('join room on profile connection'))
+            "-a",
+            "--autojoin",
+            action="store_true",
+            help=_("join room on profile connection"),
+        )
 
     async def start(self):
-        if self.args.type == 'url' and (self.args.autojoin or self.args.nick is not None):
+        if self.args.type == "url" and (self.args.autojoin or self.args.nick is not None):
             self.parser.error(_("You can't use --autojoin or --nick with --type url"))
         data = {}
         if self.args.autojoin:
-            data['autojoin'] = 'true'
+            data["autojoin"] = "true"
         if self.args.nick is not None:
-            data['nick'] = self.args.nick
+            data["nick"] = self.args.nick
         if self.args.name is not None:
-            data['name'] = self.args.name
+            data["name"] = self.args.name
         try:
             await self.host.bridge.bookmarksAdd(
-                self.args.type, self.args.bookmark, data, self.args.location,
-                self.host.profile)
+                self.args.type,
+                self.args.bookmark,
+                data,
+                self.args.location,
+                self.host.profile,
+            )
         except Exception as e:
             self.disp(f"can't add bookmark: {e}", error=True)
             self.host.quit(C.EXIT_BRIDGE_ERRBACK)
         else:
-            self.disp(_('bookmark successfully added'))
+            self.disp(_("bookmark successfully added"))
             self.host.quit()
 
 
@@ -138,4 +170,6 @@
     subcommands = (BookmarksList, BookmarksRemove, BookmarksAdd)
 
     def __init__(self, host):
-        super(Bookmarks, self).__init__(host, 'bookmarks', use_profile=False, help=_('manage bookmarks'))
+        super(Bookmarks, self).__init__(
+            host, "bookmarks", use_profile=False, help=_("manage bookmarks")
+        )