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

@ -19,7 +19,6 @@
from . import base
from sat.core.i18n import _
from functools import partial
from sat_frontends.jp.constants import Const as C
from sat_frontends.jp import xmlui_manager
@ -67,7 +66,7 @@ class Remote(base.CommandBase):
"-l", "--loop", action="store_true", help=_("loop on the commands")
)
def start(self):
async def start(self):
name = self.args.software.lower()
flags = []
magics = {jid for jid in self.args.jids if jid.count("@") > 1}
@ -75,29 +74,33 @@ class Remote(base.CommandBase):
jids = set(self.args.jids).difference(magics)
if self.args.loop:
flags.append(FLAG_LOOP)
bus_name, methods = self.host.bridge.adHocDBusAddAuto(
name,
jids,
self.args.groups,
magics,
self.args.forbidden_jids,
self.args.forbidden_groups,
flags,
self.profile,
)
if not bus_name:
self.disp(_("No bus name found"), 1)
return
self.disp(_("Bus name found: [%s]" % bus_name), 1)
for method in methods:
path, iface, command = method
self.disp(
_(
"Command found: (path:%(path)s, iface: %(iface)s) [%(command)s]"
% {"path": path, "iface": iface, "command": command}
),
1,
try:
bus_name, methods = await self.host.bridge.adHocDBusAddAuto(
name,
list(jids),
self.args.groups,
magics,
self.args.forbidden_jids,
self.args.forbidden_groups,
flags,
self.profile,
)
except Exception as e:
self.disp(f"can't create remote control: {e}", error=True)
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
else:
if not bus_name:
self.disp(_("No bus name found"), 1)
self.host.quit(C.EXIT_NOT_FOUND)
else:
self.disp(_("Bus name found: [%s]" % bus_name), 1)
for method in methods:
path, iface, command = method
self.disp(
_(f"Command found: (path:{path}, iface: {iface}) [{command}]"),
1,
)
self.host.quit()
class Run(base.CommandBase):
@ -107,7 +110,6 @@ class Run(base.CommandBase):
super(Run, self).__init__(
host, "run", use_verbose=True, help=_("run an Ad-Hoc command")
)
self.need_loop = True
def add_parser_options(self):
self.parser.add_argument(
@ -140,28 +142,24 @@ class Run(base.CommandBase):
help=_("node of the command (default: list commands)"),
)
def adHocRunCb(self, xmlui_raw):
xmlui = xmlui_manager.create(self.host, xmlui_raw)
workflow = self.args.workflow
xmlui.show(workflow)
if not workflow:
if xmlui.type == "form":
xmlui.submitForm()
else:
self.host.quit()
def start(self):
self.host.bridge.adHocRun(
self.args.jid,
self.args.node,
self.profile,
callback=self.adHocRunCb,
errback=partial(
self.errback,
msg=_("can't get ad-hoc commands list: {}"),
exit_code=C.EXIT_BRIDGE_ERRBACK,
),
)
async def start(self):
try:
xmlui_raw = await self.host.bridge.adHocRun(
self.args.jid,
self.args.node,
self.profile,
)
except Exception as e:
self.disp(f"can't get ad-hoc commands list: {e}", error=True)
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
else:
xmlui = xmlui_manager.create(self.host, xmlui_raw)
workflow = self.args.workflow
await xmlui.show(workflow)
if not workflow:
if xmlui.type == "form":
await xmlui.submitForm()
self.host.quit()
class List(base.CommandBase):
@ -171,7 +169,6 @@ class List(base.CommandBase):
super(List, self).__init__(
host, "list", use_verbose=True, help=_("list Ad-Hoc commands of a service")
)
self.need_loop = True
def add_parser_options(self):
self.parser.add_argument(
@ -181,23 +178,19 @@ class List(base.CommandBase):
help=_("jid of the service (default: profile's server"),
)
def adHocListCb(self, xmlui_raw):
xmlui = xmlui_manager.create(self.host, xmlui_raw)
xmlui.readonly = True
xmlui.show()
self.host.quit()
def start(self):
self.host.bridge.adHocList(
self.args.jid,
self.profile,
callback=self.adHocListCb,
errback=partial(
self.errback,
msg=_("can't get ad-hoc commands list: {}"),
exit_code=C.EXIT_BRIDGE_ERRBACK,
),
)
async def start(self):
try:
xmlui_raw = await self.host.bridge.adHocList(
self.args.jid,
self.profile,
)
except Exception as e:
self.disp(f"can't get ad-hoc commands list: {e}", error=True)
self.host.quit(C.EXIT_BRIDGE_ERRBACK)
else:
xmlui = xmlui_manager.create(self.host, xmlui_raw)
await xmlui.show(read_only=True)
self.host.quit()
class AdHoc(base.CommandBase):