comparison frontends/src/jp/cmd_adhoc.py @ 824:c304ce32042b

jp: added ad-hoc subcommand with a remote sub-subcommand to create a D-Bus remote
author Goffi <goffi@goffi.org>
date Mon, 17 Feb 2014 18:57:53 +0100
parents
children 069ad98b360d
comparison
equal deleted inserted replaced
823:300b4de701a6 824:c304ce32042b
1 #! /usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # jp: a SAT command line tool
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org)
6
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
16
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/>.
19
20 from logging import debug, info, error, warning
21
22 import base
23 import sys
24 import os
25 from sat.core.i18n import _
26
27 __commands__ = ["AdHoc"]
28
29 FLAG_LOOP = 'LOOP'
30 MAGIC_BAREJID = '@PROFILE_BAREJID@'
31
32 class Remote(base.CommandBase):
33 def __init__(self, host):
34 super(Remote, self).__init__(host, 'remote', help=_('Remote control a software'))
35
36 def add_parser_options(self):
37 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"))
39 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"))
41 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"))
43
44 def connected(self):
45 super(Remote, self).connected()
46 name = self.args.software.lower()
47 flags = []
48 magics = {jid for jid in self.args.jids if jid.count('@')>1}
49 magics.add(MAGIC_BAREJID)
50 jids = set(self.args.jids).difference(magics)
51 if self.args.loop:
52 flags.append(FLAG_LOOP)
53 bus_name, methods = self.host.bridge.adHocDBusAddAuto(name, jids, self.args.groups, magics,
54 self.args.forbidden_jids, self.args.forbidden_groups,
55 flags, self.profile)
56 debug(_("Bus name found: [%s]" % bus_name))
57 for method in methods:
58 path, iface, command = method
59 debug (_("Command found: (path:%(path)s, iface: %(iface)s) [%(command)s]" % {'path': path,
60 'iface': iface,
61 'command': command
62 }))
63
64 class AdHoc(base.CommandBase):
65 subcommands = (Remote,)
66
67 def __init__(self, host):
68 super(AdHoc, self).__init__(host, 'ad-hoc', use_profile=False, help=_('Ad-hoc commands'))