diff sat/bridge/bridge_constructor/base_constructor.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 c605a0d6506f
children
line wrap: on
line diff
--- a/sat/bridge/bridge_constructor/base_constructor.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/bridge/bridge_constructor/base_constructor.py	Sat Apr 08 13:54:42 2023 +0200
@@ -74,7 +74,7 @@
             function[option] = value
         return function
 
-    def getDefault(self, name):
+    def get_default(self, name):
         """Return default values of a function in a dict
         @param name: Name of the function to get
         @return: dict, each key is the integer param number (no key if no default value)"""
@@ -106,7 +106,7 @@
                 flags.append(option)
         return flags
 
-    def getArgumentsDoc(self, name):
+    def get_arguments_doc(self, name):
         """Return documentation of arguments
         @param name: Name of the function to get
         @return: dict, each key is the integer param number (no key if no argument doc), value is a tuple (name, doc)"""
@@ -131,7 +131,7 @@
                 doc_dict[idx] = (value_match.group(1), value_match.group(2))
         return doc_dict
 
-    def getDoc(self, name):
+    def get_doc(self, name):
         """Return documentation of the method
         @param name: Name of the function to get
         @return: string documentation, or None"""
@@ -139,7 +139,7 @@
             return self.bridge_template.get(name, "doc")
         return None
 
-    def argumentsParser(self, signature):
+    def arguments_parser(self, signature):
         """Generator which return individual arguments signatures from a global signature"""
         start = 0
         i = 0
@@ -176,19 +176,19 @@
             yield signature[start:i]
             start = i
 
-    def getArguments(self, signature, name=None, default=None, unicode_protect=False):
+    def get_arguments(self, signature, name=None, default=None, unicode_protect=False):
         """Return arguments to user given a signature
 
         @param signature: signature in the short form (using s,a,i,b etc)
-        @param name: dictionary of arguments name like given by getArgumentsDoc
-        @param default: dictionary of default values, like given by getDefault
+        @param name: dictionary of arguments name like given by get_arguments_doc
+        @param default: dictionary of default values, like given by get_default
         @param unicode_protect: activate unicode protection on strings (return strings as unicode(str))
         @return (str): arguments that correspond to a signature (e.g.: "sss" return "arg1, arg2, arg3")
         """
         idx = 0
         attr_string = []
 
-        for arg in self.argumentsParser(signature):
+        for arg in self.arguments_parser(signature):
             attr_string.append(
                 (
                     "str(%(name)s)%(default)s"
@@ -206,7 +206,7 @@
 
         return ", ".join(attr_string)
 
-    def getTemplatePath(self, template_file):
+    def get_template_path(self, template_file):
         """return template path corresponding to file name
 
         @param template_file(str): name of template file
@@ -232,12 +232,12 @@
     def generate(self, side):
         """generate bridge
 
-        call generateCoreSide or generateFrontendSide if they exists
+        call generate_core_side or generateFrontendSide if they exists
         else call generic self._generate method
         """
         try:
             if side == "core":
-                method = self.generateCoreSide
+                method = self.generate_core_side
             elif side == "frontend":
                 if not self.FRONTEND_ACTIVATE:
                     print("This constructor only handle core, please use core side")
@@ -272,8 +272,8 @@
         for section in sections:
             function = self.getValues(section)
             print(("Adding %s %s" % (section, function["type"])))
-            default = self.getDefault(section)
-            arg_doc = self.getArgumentsDoc(section)
+            default = self.get_default(section)
+            arg_doc = self.get_arguments_doc(section)
             async_ = "async" in self.getFlags(section)
             completion = {
                 "sig_in": function["sig_in"] or "",
@@ -281,10 +281,10 @@
                 "category": "plugin" if function["category"] == "plugin" else "core",
                 "name": section,
                 # arguments with default values
-                "args": self.getArguments(
+                "args": self.get_arguments(
                     function["sig_in"], name=arg_doc, default=default
                 ),
-                "args_no_default": self.getArguments(function["sig_in"], name=arg_doc),
+                "args_no_default": self.get_arguments(function["sig_in"], name=arg_doc),
             }
 
             extend_method = getattr(
@@ -305,7 +305,7 @@
             for env, v in os.environ.items()
             if env.startswith(C.ENV_OVERRIDE)
         }
-        template_path = self.getTemplatePath(TEMPLATE)
+        template_path = self.get_template_path(TEMPLATE)
         try:
             with open(template_path) as template:
                 for line in template:
@@ -332,9 +332,9 @@
             sys.exit(1)
 
         # now we write to final file
-        self.finalWrite(DEST, bridge)
+        self.final_write(DEST, bridge)
 
-    def finalWrite(self, filename, file_buf):
+    def final_write(self, filename, file_buf):
         """Write the final generated file in [dest dir]/filename
 
         @param filename: name of the file to generate