annotate sat_frontends/jp/cmd_adhoc.py @ 3512:d018d2d8a9e5

docker: separate build instructions for demo compose file
author Goffi <goffi@goffi.org>
date Fri, 23 Apr 2021 10:08:58 +0200
parents be6d91572633
children 04283582966f
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
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # jp: a SAT command line tool
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
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
21 from sat.core.i18n import _
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
22 from sat_frontends.jp.constants import Const as C
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
23 from sat_frontends.jp 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:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
78 bus_name, methods = await self.host.bridge.adHocDBusAddAuto(
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(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
100 _(f"Command found: (path:{path}, iface: {iface}) [{command}]"),
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
101 1,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
102 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
103 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
104
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
105
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
106 class Run(base.CommandBase):
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
107 """Run an Ad-Hoc command"""
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
108
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
109 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 super(Run, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
111 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
112 )
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
113
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
114 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
115 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 "-j",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 "--jid",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
118 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
119 help=_("jid of the service (default: profile's server"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
120 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
121 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 "-S",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 "--submit",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
124 action="append_const",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 const=xmlui_manager.SUBMIT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 dest="workflow",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
127 help=_("submit form/page"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 "-f",
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
131 "--field",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 action="append",
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
133 nargs=2,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 dest="workflow",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
135 metavar=("KEY", "VALUE"),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
136 help=_("field value"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
137 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 "node",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 nargs="?",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
141 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
142 help=_("node of the command (default: list commands)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
143 )
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
144
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
145 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
146 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
147 xmlui_raw = await self.host.bridge.adHocRun(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
148 self.args.jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
149 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
150 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
151 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
152 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
153 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
154 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
155 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
156 xmlui = xmlui_manager.create(self.host, xmlui_raw)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
157 workflow = self.args.workflow
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
158 await xmlui.show(workflow)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
159 if not workflow:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
160 if xmlui.type == "form":
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
161 await xmlui.submitForm()
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
162 self.host.quit()
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
163
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
164
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
165 class List(base.CommandBase):
3368
e86b71b1aa31 core: minor typos, docstring/comments update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
166 """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
167
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
168 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 super(List, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
170 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
171 )
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
172
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
173 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
174 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
175 "-j",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 "--jid",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
177 default="",
3368
e86b71b1aa31 core: minor typos, docstring/comments update
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
178 help=_("jid of the service (default: profile's server)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
179 )
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
180
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
181 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
182 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
183 xmlui_raw = await self.host.bridge.adHocList(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
184 self.args.jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
185 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
186 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
187 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
188 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
189 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
190 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
191 xmlui = xmlui_manager.create(self.host, xmlui_raw)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
192 await xmlui.show(read_only=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
193 self.host.quit()
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
194
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
195
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
196 class AdHoc(base.CommandBase):
2409
d2ff5ff3de77 jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents: 1960
diff changeset
197 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
198
c304ce32042b jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff changeset
199 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
200 super(AdHoc, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
201 host, "ad-hoc", use_profile=False, help=_("Ad-hoc commands")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
202 )