Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_adhoc.py @ 3033:0d55a52056f7
tools (async_process): log command as str
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 16 Aug 2019 17:06:51 +0200 |
parents | ab2696e34d29 |
children | fee60f17ebac |
rev | line source |
---|---|
1960 | 1 #!/usr/bin/env python2 |
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
|
2 # -*- coding: utf-8 -*- |
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 |
2771 | 5 # Copyright (C) 2009-2019 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 | 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 functools import partial |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
23 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
|
24 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
|
25 |
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 __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
|
27 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
28 FLAG_LOOP = "LOOP" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
29 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
|
30 |
2409
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
31 |
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
|
32 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
|
33 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
34 super(Remote, self).__init__( |
3028 | 35 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
|
36 ) |
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
|
37 |
c304ce32042b
jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 def add_parser_options(self): |
3028 | 39 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
|
40 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
41 "-j", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
42 "--jids", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
43 nargs="*", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
44 default=[], |
3028 | 45 help=_("jids allowed to use the command"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
47 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
48 "-g", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
49 "--groups", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
50 nargs="*", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
51 default=[], |
3028 | 52 help=_("groups allowed to use the command"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
54 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 "--forbidden-groups", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
56 nargs="*", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 default=[], |
3028 | 58 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
|
59 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
60 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
61 "--forbidden-jids", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
62 nargs="*", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 default=[], |
3028 | 64 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
|
65 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 self.parser.add_argument( |
3028 | 67 "-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
|
68 ) |
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
|
69 |
1864
96ba685162f6
jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
70 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
|
71 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
|
72 flags = [] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 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
|
74 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
|
75 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
|
76 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
|
77 flags.append(FLAG_LOOP) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
78 bus_name, methods = self.host.bridge.adHocDBusAddAuto( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
79 name, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
80 jids, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
81 self.args.groups, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
82 magics, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
83 self.args.forbidden_jids, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
84 self.args.forbidden_groups, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
85 flags, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
86 self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
87 ) |
1933
16e65f15f31f
plugin adhoc_dbus, jp (cmd/adhoc): fixes adHocDBusAddAuto when no bus is found
souliane <souliane@mailoo.org>
parents:
1864
diff
changeset
|
88 if not bus_name: |
16e65f15f31f
plugin adhoc_dbus, jp (cmd/adhoc): fixes adHocDBusAddAuto when no bus is found
souliane <souliane@mailoo.org>
parents:
1864
diff
changeset
|
89 self.disp(_("No bus name found"), 1) |
16e65f15f31f
plugin adhoc_dbus, jp (cmd/adhoc): fixes adHocDBusAddAuto when no bus is found
souliane <souliane@mailoo.org>
parents:
1864
diff
changeset
|
90 return |
1864
96ba685162f6
jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
91 self.disp(_("Bus name found: [%s]" % bus_name), 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
|
92 for method in methods: |
c304ce32042b
jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 path, iface, command = method |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
94 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
95 _( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
96 "Command found: (path:%(path)s, iface: %(iface)s) [%(command)s]" |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
97 % {"path": path, "iface": iface, "command": command} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
98 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
99 1, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
100 ) |
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
|
101 |
2409
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
102 |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
103 class Run(base.CommandBase): |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
104 """Run an Ad-Hoc command""" |
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 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
107 super(Run, self).__init__( |
3028 | 108 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
|
109 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
110 self.need_loop = True |
2409
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
111 |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
112 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 "-j", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 "--jid", |
3028 | 116 default="", |
117 help=_("jid of the service (default: profile's server"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
118 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
119 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
120 "-S", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
121 "--submit", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 action="append_const", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
123 const=xmlui_manager.SUBMIT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
124 dest="workflow", |
3028 | 125 help=_("submit form/page"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
127 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
128 "-f", |
2409
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
129 "--field", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
130 action="append", |
2409
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
131 nargs=2, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
132 dest="workflow", |
3028 | 133 metavar=("KEY", "VALUE"), |
134 help=_("field value"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
135 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
137 "node", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
138 nargs="?", |
3028 | 139 default="", |
140 help=_("node of the command (default: list commands)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
141 ) |
2409
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
142 |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
143 def adHocRunCb(self, xmlui_raw): |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
144 xmlui = xmlui_manager.create(self.host, xmlui_raw) |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
145 workflow = self.args.workflow |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
146 xmlui.show(workflow) |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
147 if not workflow: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
148 if xmlui.type == "form": |
2409
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
149 xmlui.submitForm() |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
150 else: |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
151 self.host.quit() |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
152 |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
153 def start(self): |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
154 self.host.bridge.adHocRun( |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
155 self.args.jid, |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
156 self.args.node, |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
157 self.profile, |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
158 callback=self.adHocRunCb, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
159 errback=partial( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
160 self.errback, |
3028 | 161 msg=_("can't get ad-hoc commands list: {}"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
162 exit_code=C.EXIT_BRIDGE_ERRBACK, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
163 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
164 ) |
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): |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
168 """Run an Ad-Hoc command""" |
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 | 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 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
174 self.need_loop = True |
2409
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
175 |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
176 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
177 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
178 "-j", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
179 "--jid", |
3028 | 180 default="", |
181 help=_("jid of the service (default: profile's server"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
182 ) |
2409
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
183 |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
184 def adHocListCb(self, xmlui_raw): |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
185 xmlui = xmlui_manager.create(self.host, xmlui_raw) |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
186 xmlui.readonly = True |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
187 xmlui.show() |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
188 self.host.quit() |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
189 |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
190 def start(self): |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
191 self.host.bridge.adHocList( |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
192 self.args.jid, |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
193 self.profile, |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
194 callback=self.adHocListCb, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
195 errback=partial( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
196 self.errback, |
3028 | 197 msg=_("can't get ad-hoc commands list: {}"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
198 exit_code=C.EXIT_BRIDGE_ERRBACK, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
199 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
200 ) |
2409
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
201 |
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
202 |
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
|
203 class AdHoc(base.CommandBase): |
2409
d2ff5ff3de77
jp (ad-hoc): new "list" and "run" commands:
Goffi <goffi@goffi.org>
parents:
1960
diff
changeset
|
204 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
|
205 |
c304ce32042b
jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
207 super(AdHoc, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
208 host, "ad-hoc", use_profile=False, help=_("Ad-hoc commands") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
209 ) |