annotate libervia/cli/cmd_adhoc.py @ 4318:27bb22eace65

tests (unit/email gateway): add test for XEP-0131 handling: rel 451
author Goffi <goffi@goffi.org>
date Sat, 28 Sep 2024 15:59:48 +0200
parents 0d7bb4df2343
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
824
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
3
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
4 # Libervia CLI
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3368
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
824
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
6
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
11
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
16
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
19
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
20 from . import base
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
21 from libervia.backend.core.i18n import _
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
22 from libervia.cli.constants import Const as C
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
23 from libervia.cli import xmlui_manager
824
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
24
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
25 __commands__ = ["AdHoc"]
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
26
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
27 FLAG_LOOP = "LOOP"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
28 MAGIC_BAREJID = "@PROFILE_BAREJID@"
824
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
29
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
30
824
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
31 class Remote(base.CommandBase):
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
33 super(Remote, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
34 host, "remote", use_verbose=True, help=_("remote control a software")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
35 )
824
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
36
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
37 def add_parser_options(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
38 self.parser.add_argument("software", type=str, help=_("software name"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
39 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
40 "-j",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 "--jids",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
42 nargs="*",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
43 default=[],
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
44 help=_("jids allowed to use the command"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
45 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
46 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
47 "-g",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 "--groups",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 nargs="*",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 default=[],
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
51 help=_("groups allowed to use the command"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 "--forbidden-groups",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 nargs="*",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 default=[],
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
57 help=_("groups that are *NOT* allowed to use the command"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
58 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
59 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 "--forbidden-jids",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 nargs="*",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 default=[],
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
63 help=_("jids that are *NOT* allowed to use the command"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
66 "-l", "--loop", action="store_true", help=_("loop on the commands")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 )
824
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
68
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
69 async def start(self):
824
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
70 name = self.args.software.lower()
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
71 flags = []
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
72 magics = {jid for jid in self.args.jids if jid.count("@") > 1}
824
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
73 magics.add(MAGIC_BAREJID)
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
74 jids = set(self.args.jids).difference(magics)
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
75 if self.args.loop:
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
76 flags.append(FLAG_LOOP)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
77 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
78 bus_name, methods = await self.host.bridge.ad_hoc_dbus_add_auto(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
79 name,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
80 list(jids),
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
81 self.args.groups,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
82 magics,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
83 self.args.forbidden_jids,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
84 self.args.forbidden_groups,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
85 flags,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
86 self.profile,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
87 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
88 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
89 self.disp(f"can't create remote control: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
90 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
91 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
92 if not bus_name:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
93 self.disp(_("No bus name found"), 1)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
94 self.host.quit(C.EXIT_NOT_FOUND)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
95 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
96 self.disp(_("Bus name found: [%s]" % bus_name), 1)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
97 for method in methods:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
98 path, iface, command = method
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
99 self.disp(
4270
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4167
diff changeset
100 _(
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4167
diff changeset
101 "Command found: (path:{path}, iface: {iface}) [{command}]"
0d7bb4df2343 Reformatted code base using black.
Goffi <goffi@goffi.org>
parents: 4167
diff changeset
102 ).format(path=path, iface=iface, command=command),
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
103 1,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
104 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
105 self.host.quit()
824
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
106
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
107
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
108 class Run(base.CommandBase):
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
109 """Run an Ad-Hoc command"""
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
110
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
111 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 super(Run, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
113 host, "run", use_verbose=True, help=_("run an Ad-Hoc command")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 )
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
115
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
116 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
118 "-j",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
119 "--jid",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
120 default="",
4167
319a0e47dc8b plugin ad-hoc D-Bus: fix deprecated use of python-dbus:
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
121 help=_("jid of the service (default: profile's server)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
124 "-S",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 "--submit",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 action="append_const",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 const=xmlui_manager.SUBMIT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128 dest="workflow",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
129 help=_("submit form/page"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 "-f",
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
133 "--field",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 action="append",
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
135 nargs=2,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
136 dest="workflow",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
137 metavar=("KEY", "VALUE"),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
138 help=_("field value"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 "node",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
142 nargs="?",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
143 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
144 help=_("node of the command (default: list commands)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
145 )
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
146
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
147 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
148 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
149 xmlui_raw = await self.host.bridge.ad_hoc_run(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
150 self.args.jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
151 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
152 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
153 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
154 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
155 self.disp(f"can't get ad-hoc commands list: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
156 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
157 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
158 xmlui = xmlui_manager.create(self.host, xmlui_raw)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
159 workflow = self.args.workflow
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
160 await xmlui.show(workflow)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
161 if not workflow:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
162 if xmlui.type == "form":
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
163 await xmlui.submit_form()
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
164 self.host.quit()
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
165
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
166
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
167 class List(base.CommandBase):
3368
e86b71b1aa31 core: minor typos, docstring/comments update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
168 """List Ad-Hoc commands available on a service"""
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
169
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
170 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
171 super(List, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
172 host, "list", use_verbose=True, help=_("list Ad-Hoc commands of a service")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 )
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
174
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
175 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 "-j",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
178 "--jid",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
179 default="",
3368
e86b71b1aa31 core: minor typos, docstring/comments update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
180 help=_("jid of the service (default: profile's server)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 )
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
182
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
183 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
184 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
185 xmlui_raw = await self.host.bridge.ad_hoc_list(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
186 self.args.jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
187 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
188 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
189 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
190 self.disp(f"can't get ad-hoc commands list: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
191 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
192 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
193 xmlui = xmlui_manager.create(self.host, xmlui_raw)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
194 await xmlui.show(read_only=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
195 self.host.quit()
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
196
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
197
824
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
198 class AdHoc(base.CommandBase):
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
199 subcommands = (Run, List, Remote)
824
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
200
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
201 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
202 super(AdHoc, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
203 host, "ad-hoc", use_profile=False, help=_("Ad-hoc commands")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
204 )