Mercurial > libervia-backend
diff 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 |
line wrap: on
line diff
--- a/sat/plugins/plugin_import.py Wed Sep 25 08:53:38 2019 +0200 +++ b/sat/plugins/plugin_import.py Wed Sep 25 08:56:41 2019 +0200 @@ -64,7 +64,7 @@ @param name(unicode): import handler name """ assert name == name.lower().strip() - log.info(_("initializing {name} import handler").format(name=name)) + log.info(_(f"initializing {name} import handler")) import_handler.name = name import_handler.register = partial(self.register, import_handler) import_handler.unregister = partial(self.unregister, import_handler) @@ -139,16 +139,8 @@ else: return importer.short_desc, importer.long_desc - def _doImport( - self, - import_handler, - name, - location, - options, - pubsub_service="", - pubsub_node="", - profile=C.PROF_KEY_NONE, - ): + def _doImport(self, import_handler, name, location, options, pubsub_service="", + pubsub_node="", profile=C.PROF_KEY_NONE): client = self.host.getClient(profile) options = {key: str(value) for key, value in options.items()} for option in import_handler.BOOL_OPTIONS: @@ -159,9 +151,11 @@ for option in import_handler.JSON_OPTIONS: try: options[option] = json.loads(options[option]) + except KeyError: + pass except ValueError: raise exceptions.DataError( - _("invalid json option: {name}").format(name=option) + _(f"invalid json option: {option}") ) pubsub_service = jid.JID(pubsub_service) if pubsub_service else None return self.doImport( @@ -175,16 +169,8 @@ ) @defer.inlineCallbacks - def doImport( - self, - client, - import_handler, - name, - location, - options=None, - pubsub_service=None, - pubsub_node=None, - ): + def doImport(self, client, import_handler, name, location, options=None, + pubsub_service=None, pubsub_node=None,): """Import data @param import_handler(object): instance of the import handler @@ -193,7 +179,8 @@ can be an url, a file path, or anything which make sense check importer description for more details @param options(dict, None): extra options. - @param pubsub_service(jid.JID, None): jid of the PubSub service where data must be imported + @param pubsub_service(jid.JID, None): jid of the PubSub service where data must be + imported. None to use profile's server @param pubsub_node(unicode, None): PubSub node to use None to use importer's default node