diff sat_frontends/jp/cmd_file.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 584379473925
children 1877c5c477ec
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_file.py	Mon Jun 14 12:19:21 2021 +0200
+++ b/sat_frontends/jp/cmd_file.py	Mon Jun 14 18:35:12 2021 +0200
@@ -54,9 +54,7 @@
         self.parser.add_argument(
             "files", type=str, nargs="+", metavar="file", help=_("a list of file")
         )
-        self.parser.add_argument(
-            "jid", help=_("the destination jid")
-        )
+        self.parser.add_argument("jid", help=_("the destination jid"))
         self.parser.add_argument(
             "-b", "--bz2", action="store_true", help=_("make a bzip2 tarball")
         )
@@ -101,19 +99,21 @@
             await self.set_progress_id(data["progress"])
         except KeyError:
             # TODO: if 'xmlui' key is present, manage xmlui message display
-            self.disp(
-                _("Can't send file to {jid}".format(jid=self.args.jid)), error=True
-            )
+            self.disp(_("Can't send file to {jid}".format(jid=self.args.jid)), error=True)
             self.host.quit(2)
 
     async def start(self):
         for file_ in self.args.files:
             if not os.path.exists(file_):
-                self.disp(_(f"file {file_!r} doesn't exist!"), error=True)
+                self.disp(
+                    _("file {file_} doesn't exist!").format(file_=repr(file_)), error=True
+                )
                 self.host.quit(C.EXIT_BAD_ARG)
             if not self.args.bz2 and os.path.isdir(file_):
                 self.disp(
-                    _(f"{file_!r} is a dir! Please send files inside or use compression")
+                    _(
+                        "{file_} is a dir! Please send files inside or use compression"
+                    ).format(file_=repr(file_))
                 )
                 self.host.quit(C.EXIT_BAD_ARG)
 
@@ -188,9 +188,7 @@
         return self.args.name or self.args.hash or "output"
 
     def add_parser_options(self):
-        self.parser.add_argument(
-            "jid", help=_("the destination jid")
-        )
+        self.parser.add_argument("jid", help=_("the destination jid"))
         self.parser.add_argument(
             "-D",
             "--dest",
@@ -258,7 +256,8 @@
 
         if os.path.exists(path) and not self.args.force:
             message = _("File {path} already exists! Do you want to overwrite?").format(
-                path = path)
+                path=path
+            )
             await self.host.confirmOrQuit(message, _("file request cancelled"))
 
         self.full_dest_jid = await self.host.get_full_jid(self.args.jid)
@@ -278,7 +277,7 @@
                 self.profile,
             )
         except Exception as e:
-            self.disp(msg=_(f"can't request file: {e}"), error=True)
+            self.disp(msg=_("can't request file: {e}").format(e=e), error=True)
             self.host.quit(C.EXIT_BRIDGE_ERRBACK)
         else:
             await self.set_progress_id(progress_id)
@@ -334,15 +333,16 @@
         self.disp(_("File received successfully"), 2)
         if metadata.get("hash_verified", False):
             try:
-                self.disp(_(
-                    f"hash checked: {metadata['hash_algo']}:{metadata['hash']}"), 1)
+                self.disp(
+                    _("hash checked: {metadata['hash_algo']}:{metadata['hash']}"), 1
+                )
             except KeyError:
                 self.disp(_("hash is checked but hash value is missing", 1), error=True)
         else:
             self.disp(_("hash can't be verified"), 1)
 
     async def onProgressError(self, e):
-        self.disp(_(f"Error while receiving file: {e}"), error=True)
+        self.disp(_("Error while receiving file: {e}").format(e=e), error=True)
 
     def getXmluiId(self, action_data):
         # FIXME: we temporarily use ElementTree, but a real XMLUI managing module
@@ -413,8 +413,12 @@
         try:
             from_jid = jid.JID(action_data["meta_from_jid"])
         except ValueError:
-            self.disp(_('invalid "from_jid" value received, ignoring: {value}').format(
-                value=from_jid), error=True)
+            self.disp(
+                _('invalid "from_jid" value received, ignoring: {value}').format(
+                    value=from_jid
+                ),
+                error=True,
+            )
             return
         except KeyError:
             self.disp(_('ignoring action without "from_jid" value'), error=True)
@@ -448,18 +452,23 @@
 
 
 class Get(base.CommandBase):
-
     def __init__(self, host):
         super(Get, self).__init__(
-            host, "get", use_progress=True, use_verbose=True,
-            help=_("download a file from URI")
+            host,
+            "get",
+            use_progress=True,
+            use_verbose=True,
+            help=_("download a file from URI"),
         )
 
     def add_parser_options(self):
         self.parser.add_argument(
-            '-o', '--dest-file', type=str, default='',
-            help=_("destination file (DEFAULT: filename from URL)")
-            )
+            "-o",
+            "--dest-file",
+            type=str,
+            default="",
+            help=_("destination file (DEFAULT: filename from URL)"),
+        )
         self.parser.add_argument(
             "-f",
             "--force",
@@ -482,8 +491,8 @@
         try:
             await self.set_progress_id(data["progress"])
         except KeyError:
-            if 'xmlui' in data:
-                ui = xmlui_manager.create(self.host, data['xmlui'])
+            if "xmlui" in data:
+                ui = xmlui_manager.create(self.host, data["xmlui"])
                 await ui.show()
             else:
                 self.disp(_("Can't download file"), error=True)
@@ -499,7 +508,8 @@
         dest_file = Path(dest_file).expanduser().resolve()
         if dest_file.exists() and not self.args.force:
             message = _("File {path} already exists! Do you want to overwrite?").format(
-                path = dest_file)
+                path=dest_file
+            )
             await self.host.confirmOrQuit(message, _("file download cancelled"))
 
         options = {}
@@ -569,8 +579,8 @@
         try:
             await self.set_progress_id(data["progress"])
         except KeyError:
-            if 'xmlui' in data:
-                ui = xmlui_manager.create(self.host, data['xmlui'])
+            if "xmlui" in data:
+                ui = xmlui_manager.create(self.host, data["xmlui"])
                 await ui.show()
             else:
                 self.disp(_("Can't upload file"), error=True)
@@ -579,10 +589,12 @@
     async def start(self):
         file_ = self.args.file
         if not os.path.exists(file_):
-            self.disp(_(f"file {file_!r} doesn't exist !"), error=True)
+            self.disp(
+                _("file {file_} doesn't exist !").format(file_=repr(file_)), error=True
+            )
             self.host.quit(C.EXIT_BAD_ARG)
         if os.path.isdir(file_):
-            self.disp(_(f"{file_!r} is a dir! Can't upload a dir"))
+            self.disp(_("{file_} is a dir! Can't upload a dir").format(file_=repr(file_)))
             self.host.quit(C.EXIT_BAD_ARG)
 
         if self.args.jid is None:
@@ -613,7 +625,6 @@
 
 
 class ShareAffiliationsSet(base.CommandBase):
-
     def __init__(self, host):
         super(ShareAffiliationsSet, self).__init__(
             host,
@@ -720,7 +731,6 @@
 
 
 class ShareConfigurationSet(base.CommandBase):
-
     def __init__(self, host):
         super(ShareConfigurationSet, self).__init__(
             host,
@@ -822,8 +832,10 @@
 
     def __init__(self, host):
         super(ShareConfiguration, self).__init__(
-            host, "configuration", use_profile=False,
-            help=_("file sharing node configuration")
+            host,
+            "configuration",
+            use_profile=False,
+            help=_("file sharing node configuration"),
         )
 
 
@@ -962,7 +974,11 @@
             self.disp(f"can't share path: {e}", error=True)
             self.host.quit(C.EXIT_BRIDGE_ERRBACK)
         else:
-            self.disp(_(f'{self.path} shared under the name "{name}"'))
+            self.disp(
+                _('{path} shared under the name "{name}"').format(
+                    path=self.path, name=name
+                )
+            )
             self.host.quit()
 
 
@@ -1015,10 +1031,10 @@
         self.path = os.path.normpath(self.args.path) if self.args.path else ""
         extra = {}
         if self.args.thumbnail is not None:
-            if not self.args.thumbnail.startswith('http'):
+            if not self.args.thumbnail.startswith("http"):
                 self.parser.error(_("only http(s) links are allowed with --thumbnail"))
             else:
-                extra['thumb_url'] = self.args.thumbnail
+                extra["thumb_url"] = self.args.thumbnail
         try:
             await self.host.bridge.FISInvite(
                 self.args.jid,
@@ -1034,15 +1050,18 @@
             self.disp(f"can't send invitation: {e}", error=True)
             self.host.quit(C.EXIT_BRIDGE_ERRBACK)
         else:
-            self.disp(
-                _(f'invitation sent to {self.args.jid}')
-            )
+            self.disp(_("invitation sent to {jid}").format(jid=self.args.jid))
             self.host.quit()
 
 
 class Share(base.CommandBase):
     subcommands = (
-        ShareList, SharePath, ShareInvite, ShareAffiliations, ShareConfiguration)
+        ShareList,
+        SharePath,
+        ShareInvite,
+        ShareAffiliations,
+        ShareConfiguration,
+    )
 
     def __init__(self, host):
         super(Share, self).__init__(