diff sat/plugins/plugin_exp_command_export.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents be6d91572633
children c23cad65ae99
line wrap: on
line diff
--- a/sat/plugins/plugin_exp_command_export.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_exp_command_export.py	Sat Apr 08 13:54:42 2023 +0200
@@ -72,7 +72,7 @@
     def write(self, message):
         self.transport.write(message.encode("utf-8"))
 
-    def boolOption(self, key):
+    def bool_option(self, key):
         """ Get boolean value from options
         @param key: name of the option
         @return: True if key exists and set to "true" (case insensitive),
@@ -92,13 +92,13 @@
         log.info(_("Plugin command export initialization"))
         self.host = host
         self.spawned = {}  # key = entity
-        host.trigger.add("messageReceived", self.messageReceivedTrigger, priority=10000)
-        host.bridge.addMethod(
-            "exportCommand",
+        host.trigger.add("messageReceived", self.message_received_trigger, priority=10000)
+        host.bridge.add_method(
+            "command_export",
             ".plugin",
             in_sign="sasasa{ss}s",
             out_sign="",
-            method=self._exportCommand,
+            method=self._export_command,
         )
 
     def removeProcess(self, entity, process):
@@ -113,7 +113,7 @@
         except ValueError:
             pass
 
-    def messageReceivedTrigger(self, client, message_elt, post_treat):
+    def message_received_trigger(self, client, message_elt, post_treat):
         """ Check if source is linked and repeat message, else do nothing  """
         from_jid = jid.JID(message_elt["from"])
         spawned_key = (from_jid.userhostJID(), client.profile)
@@ -131,15 +131,15 @@
             exclusive = False
             for process in processes_set:
                 process.write(mess_data)
-                _continue &= process.boolOption("continue")
-                exclusive |= process.boolOption("exclusive")
+                _continue &= process.bool_option("continue")
+                exclusive |= process.bool_option("exclusive")
             if exclusive:
                 raise trigger.SkipOtherTriggers
             return _continue
 
         return True
 
-    def _exportCommand(self, command, args, targets, options, profile_key):
+    def _export_command(self, command, args, targets, options, profile_key):
         """ Export a commands to authorised targets
         @param command: full path of the command to execute
         @param args: list of arguments, with command name as first one
@@ -150,7 +150,7 @@
                         - pty: if set, launch in a pseudo terminal
                         - continue: continue normal messageReceived handling
         """
-        client = self.host.getClient(profile_key)
+        client = self.host.get_client(profile_key)
         for target in targets:
             try:
                 _jid = jid.JID(target)
@@ -163,5 +163,5 @@
             process_prot = ExportCommandProtocol(self, client, _jid, options)
             self.spawned.setdefault((_jid, client.profile), set()).add(process_prot)
             reactor.spawnProcess(
-                process_prot, command, args, usePTY=process_prot.boolOption("pty")
+                process_prot, command, args, usePTY=process_prot.bool_option("pty")
             )