comparison sat/plugins/plugin_import.py @ 3040:fee60f17ebac

jp: jp asyncio port: /!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\ This patch implements the port of jp to asyncio, so it is now correctly using the bridge asynchronously, and it can be used with bridges like `pb`. This also simplify the code, notably for things which were previously implemented with many callbacks (like pagination with RSM). During the process, some behaviours have been modified/fixed, in jp and backends, check diff for details.
author Goffi <goffi@goffi.org>
date Wed, 25 Sep 2019 08:56:41 +0200
parents ab2696e34d29
children 9d0df638c8b4
comparison
equal deleted inserted replaced
3039:a1bc34f90fa5 3040:fee60f17ebac
62 - publishItem: actualy publish an item 62 - publishItem: actualy publish an item
63 - itemFilters: modify item according to options 63 - itemFilters: modify item according to options
64 @param name(unicode): import handler name 64 @param name(unicode): import handler name
65 """ 65 """
66 assert name == name.lower().strip() 66 assert name == name.lower().strip()
67 log.info(_("initializing {name} import handler").format(name=name)) 67 log.info(_(f"initializing {name} import handler"))
68 import_handler.name = name 68 import_handler.name = name
69 import_handler.register = partial(self.register, import_handler) 69 import_handler.register = partial(self.register, import_handler)
70 import_handler.unregister = partial(self.unregister, import_handler) 70 import_handler.unregister = partial(self.unregister, import_handler)
71 import_handler.importers = {} 71 import_handler.importers = {}
72 72
137 ) 137 )
138 ) 138 )
139 else: 139 else:
140 return importer.short_desc, importer.long_desc 140 return importer.short_desc, importer.long_desc
141 141
142 def _doImport( 142 def _doImport(self, import_handler, name, location, options, pubsub_service="",
143 self, 143 pubsub_node="", profile=C.PROF_KEY_NONE):
144 import_handler,
145 name,
146 location,
147 options,
148 pubsub_service="",
149 pubsub_node="",
150 profile=C.PROF_KEY_NONE,
151 ):
152 client = self.host.getClient(profile) 144 client = self.host.getClient(profile)
153 options = {key: str(value) for key, value in options.items()} 145 options = {key: str(value) for key, value in options.items()}
154 for option in import_handler.BOOL_OPTIONS: 146 for option in import_handler.BOOL_OPTIONS:
155 try: 147 try:
156 options[option] = C.bool(options[option]) 148 options[option] = C.bool(options[option])
157 except KeyError: 149 except KeyError:
158 pass 150 pass
159 for option in import_handler.JSON_OPTIONS: 151 for option in import_handler.JSON_OPTIONS:
160 try: 152 try:
161 options[option] = json.loads(options[option]) 153 options[option] = json.loads(options[option])
154 except KeyError:
155 pass
162 except ValueError: 156 except ValueError:
163 raise exceptions.DataError( 157 raise exceptions.DataError(
164 _("invalid json option: {name}").format(name=option) 158 _(f"invalid json option: {option}")
165 ) 159 )
166 pubsub_service = jid.JID(pubsub_service) if pubsub_service else None 160 pubsub_service = jid.JID(pubsub_service) if pubsub_service else None
167 return self.doImport( 161 return self.doImport(
168 client, 162 client,
169 import_handler, 163 import_handler,
173 pubsub_service, 167 pubsub_service,
174 pubsub_node or None, 168 pubsub_node or None,
175 ) 169 )
176 170
177 @defer.inlineCallbacks 171 @defer.inlineCallbacks
178 def doImport( 172 def doImport(self, client, import_handler, name, location, options=None,
179 self, 173 pubsub_service=None, pubsub_node=None,):
180 client,
181 import_handler,
182 name,
183 location,
184 options=None,
185 pubsub_service=None,
186 pubsub_node=None,
187 ):
188 """Import data 174 """Import data
189 175
190 @param import_handler(object): instance of the import handler 176 @param import_handler(object): instance of the import handler
191 @param name(unicode): name of the importer 177 @param name(unicode): name of the importer
192 @param location(unicode): location of the data to import 178 @param location(unicode): location of the data to import
193 can be an url, a file path, or anything which make sense 179 can be an url, a file path, or anything which make sense
194 check importer description for more details 180 check importer description for more details
195 @param options(dict, None): extra options. 181 @param options(dict, None): extra options.
196 @param pubsub_service(jid.JID, None): jid of the PubSub service where data must be imported 182 @param pubsub_service(jid.JID, None): jid of the PubSub service where data must be
183 imported.
197 None to use profile's server 184 None to use profile's server
198 @param pubsub_node(unicode, None): PubSub node to use 185 @param pubsub_node(unicode, None): PubSub node to use
199 None to use importer's default node 186 None to use importer's default node
200 @return (unicode): progress id 187 @return (unicode): progress id
201 """ 188 """