comparison sat/plugins/plugin_tickets_import.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 6c5f0fbc519b
children
comparison
equal deleted inserted replaced
4036:c4464d7ae97b 4037:524856bd7b19
52 BOOL_OPTIONS = () 52 BOOL_OPTIONS = ()
53 JSON_OPTIONS = (OPT_MAPPING,) 53 JSON_OPTIONS = (OPT_MAPPING,)
54 OPT_DEFAULTS = {} 54 OPT_DEFAULTS = {}
55 55
56 def __init__(self, host): 56 def __init__(self, host):
57 log.info(_("plugin Tickets Import initialization")) 57 log.info(_("plugin Tickets import initialization"))
58 self.host = host 58 self.host = host
59 self._importers = {} 59 self._importers = {}
60 self._p = host.plugins["XEP-0060"] 60 self._p = host.plugins["XEP-0060"]
61 self._m = host.plugins["XEP-0277"] 61 self._m = host.plugins["XEP-0277"]
62 self._s = host.plugins["XEP-0346"] 62 self._s = host.plugins["XEP-0346"]
63 host.plugins["IMPORT"].initialize(self, "tickets") 63 host.plugins["IMPORT"].initialize(self, "tickets")
64 64
65 @defer.inlineCallbacks 65 @defer.inlineCallbacks
66 def importItem( 66 def import_item(
67 self, client, item_import_data, session, options, return_data, service, node 67 self, client, item_import_data, session, options, return_data, service, node
68 ): 68 ):
69 """ 69 """
70 70
71 @param item_import_data(dict): no key is mandatory, but if a key doesn't exists in dest form, it will be ignored. 71 @param item_import_data(dict): no key is mandatory, but if a key doesn't exists in dest form, it will be ignored.
119 except KeyError: 119 except KeyError:
120 continue 120 continue
121 if session["root_node"] is None: 121 if session["root_node"] is None:
122 session["root_node"] = NS_TICKETS 122 session["root_node"] = NS_TICKETS
123 if not "schema" in session: 123 if not "schema" in session:
124 session["schema"] = yield self._s.getSchemaForm( 124 session["schema"] = yield self._s.get_schema_form(
125 client, service, node or session["root_node"] 125 client, service, node or session["root_node"]
126 ) 126 )
127 defer.returnValue(item_import_data) 127 defer.returnValue(item_import_data)
128 128
129 @defer.inlineCallbacks 129 @defer.inlineCallbacks
130 def importSubItems(self, client, item_import_data, ticket_data, session, options): 130 def import_sub_items(self, client, item_import_data, ticket_data, session, options):
131 # TODO: force "open" permission (except if private, check below) 131 # TODO: force "open" permission (except if private, check below)
132 # TODO: handle "private" metadata, to have non public access for node 132 # TODO: handle "private" metadata, to have non public access for node
133 # TODO: node access/publish model should be customisable 133 # TODO: node access/publish model should be customisable
134 comments = ticket_data.get("comments", []) 134 comments = ticket_data.get("comments", [])
135 service = yield self._m.getCommentsService(client) 135 service = yield self._m.get_comments_service(client)
136 node = self._m.getCommentsNode(session["root_node"] + "_" + ticket_data["id"]) 136 node = self._m.get_comments_node(session["root_node"] + "_" + ticket_data["id"])
137 node_options = { 137 node_options = {
138 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN, 138 self._p.OPT_ACCESS_MODEL: self._p.ACCESS_OPEN,
139 self._p.OPT_PERSIST_ITEMS: 1, 139 self._p.OPT_PERSIST_ITEMS: 1,
140 self._p.OPT_DELIVER_PAYLOADS: 1, 140 self._p.OPT_DELIVER_PAYLOADS: 1,
141 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1, 141 self._p.OPT_SEND_ITEM_SUBSCRIBE: 1,
142 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN, 142 self._p.OPT_PUBLISH_MODEL: self._p.ACCESS_OPEN,
143 } 143 }
144 yield self._p.createIfNewNode(client, service, node, options=node_options) 144 yield self._p.create_if_new_node(client, service, node, options=node_options)
145 ticket_data["comments_uri"] = uri.buildXMPPUri( 145 ticket_data["comments_uri"] = uri.build_xmpp_uri(
146 "pubsub", subtype="microblog", path=service.full(), node=node 146 "pubsub", subtype="microblog", path=service.full(), node=node
147 ) 147 )
148 for comment in comments: 148 for comment in comments:
149 if "updated" not in comment and "published" in comment: 149 if "updated" not in comment and "published" in comment:
150 # we don't want an automatic update date 150 # we don't want an automatic update date
151 comment["updated"] = comment["published"] 151 comment["updated"] = comment["published"]
152 yield self._m.send(client, comment, service, node) 152 yield self._m.send(client, comment, service, node)
153 153
154 def publishItem(self, client, ticket_data, service, node, session): 154 def publish_item(self, client, ticket_data, service, node, session):
155 if node is None: 155 if node is None:
156 node = NS_TICKETS 156 node = NS_TICKETS
157 id_ = ticket_data.pop("id", None) 157 id_ = ticket_data.pop("id", None)
158 log.debug( 158 log.debug(
159 "uploading item [{id}]: {title}".format( 159 "uploading item [{id}]: {title}".format(
160 id=id_, title=ticket_data.get("title", "") 160 id=id_, title=ticket_data.get("title", "")
161 ) 161 )
162 ) 162 )
163 return defer.ensureDeferred( 163 return defer.ensureDeferred(
164 self._s.sendDataFormItem( 164 self._s.send_data_form_item(
165 client, service, node, ticket_data, session["schema"], id_ 165 client, service, node, ticket_data, session["schema"], id_
166 ) 166 )
167 ) 167 )
168 168
169 def itemFilters(self, client, ticket_data, session, options): 169 def item_filters(self, client, ticket_data, session, options):
170 mapping = options.get(OPT_MAPPING) 170 mapping = options.get(OPT_MAPPING)
171 if mapping is not None: 171 if mapping is not None:
172 if not isinstance(mapping, dict): 172 if not isinstance(mapping, dict):
173 raise exceptions.DataError(_("mapping option must be a dictionary")) 173 raise exceptions.DataError(_("mapping option must be a dictionary"))
174 174