diff libervia/cli/cmd_message.py @ 4270:0d7bb4df2343

Reformatted code base using black.
author Goffi <goffi@goffi.org>
date Wed, 19 Jun 2024 18:44:57 +0200
parents 47401850dec6
children 472a938a46e3
line wrap: on
line diff
--- a/libervia/cli/cmd_message.py	Tue Jun 18 12:06:45 2024 +0200
+++ b/libervia/cli/cmd_message.py	Wed Jun 19 18:44:57 2024 +0200
@@ -55,9 +55,7 @@
             "-n",
             "--new-line",
             action="store_true",
-            help=_(
-                "add a new line at the beginning of the input"
-            ),
+            help=_("add a new line at the beginning of the input"),
         )
         self.parser.add_argument(
             "-S",
@@ -74,22 +72,29 @@
             default=C.MESS_TYPE_AUTO,
             help=_("type of the message"),
         )
-        self.parser.add_argument("-e", "--encrypt", metavar="ALGORITHM",
-                                 help=_("encrypt message using given algorithm"))
+        self.parser.add_argument(
+            "-e",
+            "--encrypt",
+            metavar="ALGORITHM",
+            help=_("encrypt message using given algorithm"),
+        )
         self.parser.add_argument(
             "--encrypt-noreplace",
             action="store_true",
-            help=_("don't replace encryption algorithm if an other one is already used"))
+            help=_("don't replace encryption algorithm if an other one is already used"),
+        )
         self.parser.add_argument(
-            "-a", "--attach", dest="attachments", action="append", metavar="FILE_PATH",
-            help=_("add a file as an attachment")
+            "-a",
+            "--attach",
+            dest="attachments",
+            action="append",
+            metavar="FILE_PATH",
+            help=_("add a file as an attachment"),
         )
         syntax = self.parser.add_mutually_exclusive_group()
         syntax.add_argument("-x", "--xhtml", action="store_true", help=_("XHTML body"))
         syntax.add_argument("-r", "--rich", action="store_true", help=_("rich body"))
-        self.parser.add_argument(
-            "jid", help=_("the destination jid")
-        )
+        self.parser.add_argument("jid", help=_("the destination jid"))
 
     async def send_stdin(self, dest_jid):
         """Send incomming data on stdin to jabber contact
@@ -98,9 +103,7 @@
         """
         header = "\n" if self.args.new_line else ""
         # FIXME: stdin is not read asynchronously at the moment
-        stdin_lines = [
-            stream for stream in sys.stdin.readlines()
-        ]
+        stdin_lines = [stream for stream in sys.stdin.readlines()]
         extra = {}
         if self.args.subject is None:
             subject = {}
@@ -134,8 +137,9 @@
                     self.disp(f"can't send header: {e}", error=True)
                     error = True
 
-            to_send.extend({self.args.lang: clean_ustr(l.replace("\n", ""))}
-                           for l in stdin_lines)
+            to_send.extend(
+                {self.args.lang: clean_ustr(l.replace("\n", ""))} for l in stdin_lines
+            )
         else:
             # we sent all in a single message
             if not (self.args.xhtml or self.args.rich):
@@ -166,7 +170,8 @@
                     subject,
                     self.args.type,
                     data_format.serialise(extra),
-                    profile_key=self.host.profile)
+                    profile_key=self.host.profile,
+                )
             except Exception as e:
                 self.disp(f"can't send message {msg!r}: {e}", error=True)
                 error = True
@@ -194,7 +199,8 @@
         if self.args.encrypt is not None:
             try:
                 namespace = await self.host.bridge.encryption_namespace_get(
-                    self.args.encrypt)
+                    self.args.encrypt
+                )
             except Exception as e:
                 self.disp(f"can't get encryption namespace: {e}", error=True)
                 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
@@ -216,24 +222,19 @@
         super().__init__(host, "retract", help=_("retract a message"))
 
     def add_parser_options(self):
-        self.parser.add_argument(
-            "message_id",
-            help=_("ID of the message (internal ID)")
-        )
+        self.parser.add_argument("message_id", help=_("ID of the message (internal ID)"))
 
     async def start(self):
         try:
-            await self.host.bridge.message_retract(
-                self.args.message_id,
-                self.profile
-            )
+            await self.host.bridge.message_retract(self.args.message_id, self.profile)
         except Exception as e:
             self.disp(f"can't retract message: {e}", error=True)
             self.host.quit(C.EXIT_BRIDGE_ERRBACK)
         else:
             self.disp(
                 "message retraction has been requested, please note that this is a "
-                "request which can't be enforced (see documentation for details).")
+                "request which can't be enforced (see documentation for details)."
+            )
             self.host.quit(C.EXIT_OK)
 
 
@@ -241,36 +242,66 @@
 
     def __init__(self, host):
         super(MAM, self).__init__(
-            host, "mam", use_output=C.OUTPUT_MESS, use_verbose=True,
-            help=_("query archives using MAM"))
+            host,
+            "mam",
+            use_output=C.OUTPUT_MESS,
+            use_verbose=True,
+            help=_("query archives using MAM"),
+        )
 
     def add_parser_options(self):
         self.parser.add_argument(
-            "-s", "--service", default="",
-            help=_("jid of the service (default: profile's server"))
+            "-s",
+            "--service",
+            default="",
+            help=_("jid of the service (default: profile's server"),
+        )
         self.parser.add_argument(
-            "-S", "--start", dest="mam_start", type=base.date_decoder,
-            help=_(
-                "start fetching archive from this date (default: from the beginning)"))
+            "-S",
+            "--start",
+            dest="mam_start",
+            type=base.date_decoder,
+            help=_("start fetching archive from this date (default: from the beginning)"),
+        )
         self.parser.add_argument(
-            "-E", "--end", dest="mam_end", type=base.date_decoder,
-            help=_("end fetching archive after this date (default: no limit)"))
+            "-E",
+            "--end",
+            dest="mam_end",
+            type=base.date_decoder,
+            help=_("end fetching archive after this date (default: no limit)"),
+        )
         self.parser.add_argument(
-            "-W", "--with", dest="mam_with",
-            help=_("retrieve only archives with this jid"))
+            "-W",
+            "--with",
+            dest="mam_with",
+            help=_("retrieve only archives with this jid"),
+        )
         self.parser.add_argument(
-            "-m", "--max", dest="rsm_max", type=int, default=20,
-            help=_("maximum number of items to retrieve, using RSM (default: 20))"))
+            "-m",
+            "--max",
+            dest="rsm_max",
+            type=int,
+            default=20,
+            help=_("maximum number of items to retrieve, using RSM (default: 20))"),
+        )
         rsm_page_group = self.parser.add_mutually_exclusive_group()
         rsm_page_group.add_argument(
-            "-a", "--after", dest="rsm_after",
-            help=_("find page after this item"), metavar='ITEM_ID')
+            "-a",
+            "--after",
+            dest="rsm_after",
+            help=_("find page after this item"),
+            metavar="ITEM_ID",
+        )
         rsm_page_group.add_argument(
-            "-b", "--before", dest="rsm_before",
-            help=_("find page before this item"), metavar='ITEM_ID')
+            "-b",
+            "--before",
+            dest="rsm_before",
+            help=_("find page before this item"),
+            metavar="ITEM_ID",
+        )
         rsm_page_group.add_argument(
-            "--index", dest="rsm_index", type=int,
-            help=_("index of the page to retrieve"))
+            "--index", dest="rsm_index", type=int, help=_("index of the page to retrieve")
+        )
 
     async def start(self):
         extra = {}
@@ -280,14 +311,15 @@
             extra["mam_end"] = float(self.args.mam_end)
         if self.args.mam_with is not None:
             extra["mam_with"] = self.args.mam_with
-        for suff in ('max', 'after', 'before', 'index'):
-            key = 'rsm_' + suff
-            value = getattr(self.args,key)
+        for suff in ("max", "after", "before", "index"):
+            key = "rsm_" + suff
+            value = getattr(self.args, key)
             if value is not None:
                 extra[key] = str(value)
         try:
             data, metadata_s, profile = await self.host.bridge.mam_get(
-                self.args.service, data_format.serialise(extra), self.profile)
+                self.args.service, data_format.serialise(extra), self.profile
+            )
         except Exception as e:
             self.disp(f"can't retrieve MAM archives: {e}", error=True)
             self.host.quit(C.EXIT_BRIDGE_ERRBACK)
@@ -308,12 +340,17 @@
         # FIXME: metadata are not displayed correctly and don't play nice with output
         #        they should be added to output data somehow
         if self.verbosity:
-            for value in ("rsm_first", "rsm_last", "rsm_index", "rsm_count",
-                          "mam_complete", "mam_stable"):
+            for value in (
+                "rsm_first",
+                "rsm_last",
+                "rsm_index",
+                "rsm_count",
+                "mam_complete",
+                "mam_stable",
+            ):
                 if value in metadata:
                     label = value.split("_")[1]
-                    self.disp(A.color(
-                        C.A_HEADER, label, ': ' , A.RESET, metadata[value]))
+                    self.disp(A.color(C.A_HEADER, label, ": ", A.RESET, metadata[value]))
 
         self.host.quit()