Mercurial > libervia-backend
comparison frontends/src/jp/cmd_adhoc.py @ 1864:96ba685162f6
jp: all commands now use the new start method and set need_loop in __init__ when needed
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 29 Feb 2016 16:52:51 +0100 |
parents | d17772b0fe22 |
children | 16e65f15f31f |
comparison
equal
deleted
inserted
replaced
1863:b2ddd7f5dcdf | 1864:96ba685162f6 |
---|---|
15 # GNU Affero General Public License for more details. | 15 # GNU Affero General Public License for more details. |
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from logging import debug, info, error, warning | |
21 | |
22 import base | 20 import base |
23 import sys | |
24 import os | |
25 from sat.core.i18n import _ | 21 from sat.core.i18n import _ |
26 | 22 |
27 __commands__ = ["AdHoc"] | 23 __commands__ = ["AdHoc"] |
28 | 24 |
29 FLAG_LOOP = 'LOOP' | 25 FLAG_LOOP = 'LOOP' |
30 MAGIC_BAREJID = '@PROFILE_BAREJID@' | 26 MAGIC_BAREJID = '@PROFILE_BAREJID@' |
31 | 27 |
32 class Remote(base.CommandBase): | 28 class Remote(base.CommandBase): |
33 def __init__(self, host): | 29 def __init__(self, host): |
34 super(Remote, self).__init__(host, 'remote', help=_('Remote control a software')) | 30 super(Remote, self).__init__(host, 'remote', use_verbose=True, help=_('Remote control a software')) |
35 | 31 |
36 def add_parser_options(self): | 32 def add_parser_options(self): |
37 self.parser.add_argument("software", type=str, help=_("Software name")) | 33 self.parser.add_argument("software", type=str, help=_("Software name")) |
38 self.parser.add_argument("-j", "--jids", type=base.unicode_decoder, nargs='*', default=[], help=_("Jids allowed to use the command")) | 34 self.parser.add_argument("-j", "--jids", type=base.unicode_decoder, nargs='*', default=[], help=_("Jids allowed to use the command")) |
39 self.parser.add_argument("-g", "--groups", type=base.unicode_decoder, nargs='*', default=[], help=_("Groups allowed to use the command")) | 35 self.parser.add_argument("-g", "--groups", type=base.unicode_decoder, nargs='*', default=[], help=_("Groups allowed to use the command")) |
40 self.parser.add_argument("--forbidden-groups", type=base.unicode_decoder, nargs='*', default=[], help=_("Groups that are *NOT* allowed to use the command")) | 36 self.parser.add_argument("--forbidden-groups", type=base.unicode_decoder, nargs='*', default=[], help=_("Groups that are *NOT* allowed to use the command")) |
41 self.parser.add_argument("--forbidden-jids", type=base.unicode_decoder, nargs='*', default=[], help=_("Jids that are *NOT* allowed to use the command")) | 37 self.parser.add_argument("--forbidden-jids", type=base.unicode_decoder, nargs='*', default=[], help=_("Jids that are *NOT* allowed to use the command")) |
42 self.parser.add_argument("-l", "--loop", action="store_true", help=_("Loop on the commands")) | 38 self.parser.add_argument("-l", "--loop", action="store_true", help=_("Loop on the commands")) |
43 | 39 |
44 def connected(self): | 40 def start(self): |
45 super(Remote, self).connected() | |
46 name = self.args.software.lower() | 41 name = self.args.software.lower() |
47 flags = [] | 42 flags = [] |
48 magics = {jid for jid in self.args.jids if jid.count('@')>1} | 43 magics = {jid for jid in self.args.jids if jid.count('@')>1} |
49 magics.add(MAGIC_BAREJID) | 44 magics.add(MAGIC_BAREJID) |
50 jids = set(self.args.jids).difference(magics) | 45 jids = set(self.args.jids).difference(magics) |
51 if self.args.loop: | 46 if self.args.loop: |
52 flags.append(FLAG_LOOP) | 47 flags.append(FLAG_LOOP) |
53 bus_name, methods = self.host.bridge.adHocDBusAddAuto(name, jids, self.args.groups, magics, | 48 bus_name, methods = self.host.bridge.adHocDBusAddAuto(name, jids, self.args.groups, magics, |
54 self.args.forbidden_jids, self.args.forbidden_groups, | 49 self.args.forbidden_jids, self.args.forbidden_groups, |
55 flags, self.profile) | 50 flags, self.profile) |
56 debug(_("Bus name found: [%s]" % bus_name)) | 51 self.disp(_("Bus name found: [%s]" % bus_name), 1) |
57 for method in methods: | 52 for method in methods: |
58 path, iface, command = method | 53 path, iface, command = method |
59 debug (_("Command found: (path:%(path)s, iface: %(iface)s) [%(command)s]" % {'path': path, | 54 self.disp(_("Command found: (path:%(path)s, iface: %(iface)s) [%(command)s]" % {'path': path, |
60 'iface': iface, | 55 'iface': iface, |
61 'command': command | 56 'command': command |
62 })) | 57 }),1) |
63 | 58 |
64 class AdHoc(base.CommandBase): | 59 class AdHoc(base.CommandBase): |
65 subcommands = (Remote,) | 60 subcommands = (Remote,) |
66 | 61 |
67 def __init__(self, host): | 62 def __init__(self, host): |