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.
This commit is contained in:
Goffi 2019-09-25 08:56:41 +02:00
commit 76aadbb3fb

View file

@ -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 @@ class Get(base.CommandBase):
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 @@ class Set(base.CommandBase):
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):