Mercurial > libervia-backend
diff sat_frontends/jp/cmd_identity.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_frontends/jp/cmd_identity.py Wed Sep 25 08:53:38 2019 +0200 +++ b/sat_frontends/jp/cmd_identity.py Wed Sep 25 08:56:41 2019 +0200 @@ -21,12 +21,9 @@ from . import base from sat.core.i18n import _ from sat_frontends.jp.constants import Const as C -from functools import partial __commands__ = ["Identity"] -# TODO: move date parsing to base, it may be useful for other commands - class Get(base.CommandBase): def __init__(self, host): @@ -38,29 +35,25 @@ use_verbose=True, help=_("get identity data"), ) - self.need_loop = True def add_parser_options(self): self.parser.add_argument( "jid", help=_("entity to check") ) - def identityGetCb(self, data): - self.output(data) - self.host.quit() - - def start(self): - jid_ = self.host.check_jids([self.args.jid])[0] - self.host.bridge.identityGet( - jid_, - self.profile, - callback=self.identityGetCb, - errback=partial( - self.errback, - msg=_("can't get identity data: {}"), - exit_code=C.EXIT_BRIDGE_ERRBACK, - ), - ) + async def start(self): + jid_ = (await self.host.check_jids([self.args.jid]))[0] + try: + data = await self.host.bridge.identityGet( + jid_, + self.profile, + ) + except Exception as e: + self.disp(f"can't get identity data: {e}", error=True) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) + else: + await self.output(data) + self.host.quit() class Set(base.CommandBase): @@ -78,20 +71,19 @@ required=True, help=_("identity field(s) to set"), ) - self.need_loop = True - def start(self): + async def start(self): fields = dict(self.args.fields) - self.host.bridge.identitySet( - fields, - self.profile, - callback=self.host.quit, - errback=partial( - self.errback, - msg=_("can't set identity data data: {}"), - exit_code=C.EXIT_BRIDGE_ERRBACK, - ), - ) + try: + self.host.bridge.identitySet( + fields, + self.profile, + ) + except Exception as e: + self.disp(f"can't set identity data: {e}", error=True) + self.host.quit(C.EXIT_BRIDGE_ERRBACK) + else: + self.host.quit() class Identity(base.CommandBase):