diff sat/plugins/plugin_misc_merge_requests.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 a0666f17f300
children
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_merge_requests.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_misc_merge_requests.py	Sat Apr 08 13:54:42 2023 +0200
@@ -69,35 +69,35 @@
         log.info(_("Merge requests plugin initialization"))
         self.host = host
         self._s = self.host.plugins["XEP-0346"]
-        self.namespace = self._s.getSubmittedNS(APP_NS_MERGE_REQUESTS)
-        host.registerNamespace('merge_requests', self.namespace)
+        self.namespace = self._s.get_submitted_ns(APP_NS_MERGE_REQUESTS)
+        host.register_namespace('merge_requests', self.namespace)
         self._p = self.host.plugins["XEP-0060"]
         self._t = self.host.plugins["LISTS"]
         self._handlers = {}
         self._handlers_list = []  # handlers sorted by priority
         self._type_handlers = {}  # data type => handler map
-        host.bridge.addMethod("mergeRequestsGet", ".plugin",
+        host.bridge.add_method("merge_requests_get", ".plugin",
                               in_sign='ssiassss', out_sign='s',
                               method=self._get,
                               async_=True
                               )
-        host.bridge.addMethod("mergeRequestSet", ".plugin",
+        host.bridge.add_method("merge_request_set", ".plugin",
                               in_sign='ssssa{sas}ssss', out_sign='s',
                               method=self._set,
                               async_=True)
-        host.bridge.addMethod("mergeRequestsSchemaGet", ".plugin",
+        host.bridge.add_method("merge_requests_schema_get", ".plugin",
                               in_sign='sss', out_sign='s',
                               method=lambda service, nodeIdentifier, profile_key:
-                                self._s._getUISchema(service,
+                                self._s._get_ui_schema(service,
                                                      nodeIdentifier,
                                                      default_node=self.namespace,
                                                      profile_key=profile_key),
                               async_=True)
-        host.bridge.addMethod("mergeRequestParseData", ".plugin",
+        host.bridge.add_method("merge_request_parse_data", ".plugin",
                               in_sign='ss', out_sign='aa{ss}',
-                              method=self._parseData,
+                              method=self._parse_data,
                               async_=True)
-        host.bridge.addMethod("mergeRequestsImport", ".plugin",
+        host.bridge.add_method("merge_requests_import", ".plugin",
                               in_sign='ssssa{ss}s', out_sign='',
                               method=self._import,
                               async_=True
@@ -141,7 +141,7 @@
 
     def serialise(self, get_data):
         tickets_xmlui, metadata, items_patches = get_data
-        tickets_xmlui_s, metadata = self._p.transItemsData((tickets_xmlui, metadata))
+        tickets_xmlui_s, metadata = self._p.trans_items_data((tickets_xmlui, metadata))
         return data_format.serialise({
             "items": tickets_xmlui_s,
             "metadata": metadata,
@@ -151,7 +151,7 @@
     def _get(self, service='', node='', max_items=10, item_ids=None, sub_id=None,
              extra="", profile_key=C.PROF_KEY_NONE):
         extra = data_format.deserialise(extra)
-        client, service, node, max_items, extra, sub_id = self._s.prepareBridgeGet(
+        client, service, node, max_items, extra, sub_id = self._s.prepare_bridge_get(
             service, node, max_items, sub_id, extra, profile_key)
         d = self.get(client, service, node or None, max_items, item_ids, sub_id or None,
                      extra.rsm_request, extra.extra)
@@ -178,11 +178,11 @@
         # XXX: Q&D way to get list for labels when displaying them, but text when we
         #      have to modify them
         if C.bool(extra.get('labels_as_list', C.BOOL_FALSE)):
-            filters = {'labels': self._s.textbox2ListFilter}
+            filters = {'labels': self._s.textbox_2_list_filter}
         else:
             filters = {}
         tickets_xmlui, metadata = yield defer.ensureDeferred(
-            self._s.getDataFormItems(
+            self._s.get_data_form_items(
                 client,
                 service,
                 node,
@@ -199,13 +199,13 @@
             for ticket in tickets_xmlui:
                 request_type = ticket.named_widgets[FIELD_DATA_TYPE].value
                 request_data = ticket.named_widgets[FIELD_DATA].value
-                parsed_data = yield self.parseData(request_type, request_data)
+                parsed_data = yield self.parse_data(request_type, request_data)
                 parsed_patches.append(parsed_data)
         defer.returnValue((tickets_xmlui, metadata, parsed_patches))
 
     def _set(self, service, node, repository, method, values, schema=None, item_id=None,
              extra="", profile_key=C.PROF_KEY_NONE):
-        client, service, node, schema, item_id, extra = self._s.prepareBridgeSet(
+        client, service, node, schema, item_id, extra = self._s.prepare_bridge_set(
             service, node, schema, item_id, extra, profile_key)
         d = defer.ensureDeferred(
             self.set(
@@ -290,13 +290,13 @@
                                     deserialise, form_ns=APP_NS_MERGE_REQUESTS)
         return item_id
 
-    def _parseData(self, data_type, data):
-        d = self.parseData(data_type, data)
+    def _parse_data(self, data_type, data):
+        d = self.parse_data(data_type, data)
         d.addCallback(lambda parsed_patches:
             {key: str(value) for key, value in parsed_patches.items()})
         return d
 
-    def parseData(self, data_type, data):
+    def parse_data(self, data_type, data):
         """Parse a merge request data according to type
 
         @param data_type(unicode): type of the data to parse
@@ -314,7 +314,7 @@
 
     def _import(self, repository, item_id, service=None, node=None, extra=None,
                 profile_key=C.PROF_KEY_NONE):
-        client = self.host.getClient(profile_key)
+        client = self.host.get_client(profile_key)
         service = jid.JID(service) if service else None
         d = self.import_request(client, repository, item_id, service, node or None,
                                 extra=extra or None)
@@ -323,14 +323,14 @@
     @defer.inlineCallbacks
     def import_request(self, client, repository, item, service=None, node=None,
                        extra=None):
-        """Import a merge request in specified directory
+        """import a merge request in specified directory
 
         @param repository(unicode): path to the repository where the code stands
         """
         if not node:
             node = self.namespace
         tickets_xmlui, metadata = yield defer.ensureDeferred(
-            self._s.getDataFormItems(
+            self._s.get_data_form_items(
                 client,
                 service,
                 node,