comparison sat_frontends/jp/cmd_adhoc.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 003b8b4b56a7
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
23 from sat_frontends.jp.constants import Const as C 23 from sat_frontends.jp.constants import Const as C
24 from sat_frontends.jp import xmlui_manager 24 from sat_frontends.jp import xmlui_manager
25 25
26 __commands__ = ["AdHoc"] 26 __commands__ = ["AdHoc"]
27 27
28 FLAG_LOOP = 'LOOP' 28 FLAG_LOOP = "LOOP"
29 MAGIC_BAREJID = '@PROFILE_BAREJID@' 29 MAGIC_BAREJID = "@PROFILE_BAREJID@"
30 30
31 31
32 class Remote(base.CommandBase): 32 class Remote(base.CommandBase):
33 def __init__(self, host): 33 def __init__(self, host):
34 super(Remote, self).__init__(host, 'remote', use_verbose=True, help=_(u'remote control a software')) 34 super(Remote, self).__init__(
35 host, "remote", use_verbose=True, help=_(u"remote control a software")
36 )
35 37
36 def add_parser_options(self): 38 def add_parser_options(self):
37 self.parser.add_argument("software", type=str, help=_(u"software name")) 39 self.parser.add_argument("software", type=str, help=_(u"software name"))
38 self.parser.add_argument("-j", "--jids", type=base.unicode_decoder, nargs='*', default=[], help=_(u"jids allowed to use the command")) 40 self.parser.add_argument(
39 self.parser.add_argument("-g", "--groups", type=base.unicode_decoder, nargs='*', default=[], help=_(u"groups allowed to use the command")) 41 "-j",
40 self.parser.add_argument("--forbidden-groups", type=base.unicode_decoder, nargs='*', default=[], help=_(u"groups that are *NOT* allowed to use the command")) 42 "--jids",
41 self.parser.add_argument("--forbidden-jids", type=base.unicode_decoder, nargs='*', default=[], help=_(u"jids that are *NOT* allowed to use the command")) 43 type=base.unicode_decoder,
42 self.parser.add_argument("-l", "--loop", action="store_true", help=_(u"loop on the commands")) 44 nargs="*",
45 default=[],
46 help=_(u"jids allowed to use the command"),
47 )
48 self.parser.add_argument(
49 "-g",
50 "--groups",
51 type=base.unicode_decoder,
52 nargs="*",
53 default=[],
54 help=_(u"groups allowed to use the command"),
55 )
56 self.parser.add_argument(
57 "--forbidden-groups",
58 type=base.unicode_decoder,
59 nargs="*",
60 default=[],
61 help=_(u"groups that are *NOT* allowed to use the command"),
62 )
63 self.parser.add_argument(
64 "--forbidden-jids",
65 type=base.unicode_decoder,
66 nargs="*",
67 default=[],
68 help=_(u"jids that are *NOT* allowed to use the command"),
69 )
70 self.parser.add_argument(
71 "-l", "--loop", action="store_true", help=_(u"loop on the commands")
72 )
43 73
44 def start(self): 74 def start(self):
45 name = self.args.software.lower() 75 name = self.args.software.lower()
46 flags = [] 76 flags = []
47 magics = {jid for jid in self.args.jids if jid.count('@')>1} 77 magics = {jid for jid in self.args.jids if jid.count("@") > 1}
48 magics.add(MAGIC_BAREJID) 78 magics.add(MAGIC_BAREJID)
49 jids = set(self.args.jids).difference(magics) 79 jids = set(self.args.jids).difference(magics)
50 if self.args.loop: 80 if self.args.loop:
51 flags.append(FLAG_LOOP) 81 flags.append(FLAG_LOOP)
52 bus_name, methods = self.host.bridge.adHocDBusAddAuto(name, jids, self.args.groups, magics, 82 bus_name, methods = self.host.bridge.adHocDBusAddAuto(
53 self.args.forbidden_jids, self.args.forbidden_groups, 83 name,
54 flags, self.profile) 84 jids,
85 self.args.groups,
86 magics,
87 self.args.forbidden_jids,
88 self.args.forbidden_groups,
89 flags,
90 self.profile,
91 )
55 if not bus_name: 92 if not bus_name:
56 self.disp(_("No bus name found"), 1) 93 self.disp(_("No bus name found"), 1)
57 return 94 return
58 self.disp(_("Bus name found: [%s]" % bus_name), 1) 95 self.disp(_("Bus name found: [%s]" % bus_name), 1)
59 for method in methods: 96 for method in methods:
60 path, iface, command = method 97 path, iface, command = method
61 self.disp(_("Command found: (path:%(path)s, iface: %(iface)s) [%(command)s]" % {'path': path, 98 self.disp(
62 'iface': iface, 99 _(
63 'command': command 100 "Command found: (path:%(path)s, iface: %(iface)s) [%(command)s]"
64 }),1) 101 % {"path": path, "iface": iface, "command": command}
102 ),
103 1,
104 )
65 105
66 106
67 class Run(base.CommandBase): 107 class Run(base.CommandBase):
68 """Run an Ad-Hoc command""" 108 """Run an Ad-Hoc command"""
69 109
70 def __init__(self, host): 110 def __init__(self, host):
71 super(Run, self).__init__(host, 'run', use_verbose=True, help=_(u'run an Ad-Hoc command')) 111 super(Run, self).__init__(
72 self.need_loop=True 112 host, "run", use_verbose=True, help=_(u"run an Ad-Hoc command")
113 )
114 self.need_loop = True
73 115
74 def add_parser_options(self): 116 def add_parser_options(self):
75 self.parser.add_argument('-j', '--jid', type=base.unicode_decoder, default=u'', help=_(u"jid of the service (default: profile's server")) 117 self.parser.add_argument(
76 self.parser.add_argument("-S", "--submit", action='append_const', const=xmlui_manager.SUBMIT, dest='workflow', help=_(u"submit form/page")) 118 "-j",
77 self.parser.add_argument("-f", 119 "--jid",
120 type=base.unicode_decoder,
121 default=u"",
122 help=_(u"jid of the service (default: profile's server"),
123 )
124 self.parser.add_argument(
125 "-S",
126 "--submit",
127 action="append_const",
128 const=xmlui_manager.SUBMIT,
129 dest="workflow",
130 help=_(u"submit form/page"),
131 )
132 self.parser.add_argument(
133 "-f",
78 "--field", 134 "--field",
79 type=base.unicode_decoder, 135 type=base.unicode_decoder,
80 action='append', 136 action="append",
81 nargs=2, 137 nargs=2,
82 dest='workflow', 138 dest="workflow",
83 metavar=(u"KEY", u"VALUE"), 139 metavar=(u"KEY", u"VALUE"),
84 help=_(u"field value")) 140 help=_(u"field value"),
85 self.parser.add_argument('node', type=base.unicode_decoder, nargs='?', default=u'', help=_(u"node of the command (default: list commands)")) 141 )
142 self.parser.add_argument(
143 "node",
144 type=base.unicode_decoder,
145 nargs="?",
146 default=u"",
147 help=_(u"node of the command (default: list commands)"),
148 )
86 149
87 def adHocRunCb(self, xmlui_raw): 150 def adHocRunCb(self, xmlui_raw):
88 xmlui = xmlui_manager.create(self.host, xmlui_raw) 151 xmlui = xmlui_manager.create(self.host, xmlui_raw)
89 workflow = self.args.workflow 152 workflow = self.args.workflow
90 xmlui.show(workflow) 153 xmlui.show(workflow)
91 if not workflow: 154 if not workflow:
92 if xmlui.type == 'form': 155 if xmlui.type == "form":
93 xmlui.submitForm() 156 xmlui.submitForm()
94 else: 157 else:
95 self.host.quit() 158 self.host.quit()
96 159
97 def start(self): 160 def start(self):
98 self.host.bridge.adHocRun( 161 self.host.bridge.adHocRun(
99 self.args.jid, 162 self.args.jid,
100 self.args.node, 163 self.args.node,
101 self.profile, 164 self.profile,
102 callback=self.adHocRunCb, 165 callback=self.adHocRunCb,
103 errback=partial(self.errback, 166 errback=partial(
104 msg=_(u"can't get ad-hoc commands list: {}"), 167 self.errback,
105 exit_code=C.EXIT_BRIDGE_ERRBACK)) 168 msg=_(u"can't get ad-hoc commands list: {}"),
169 exit_code=C.EXIT_BRIDGE_ERRBACK,
170 ),
171 )
106 172
107 173
108 class List(base.CommandBase): 174 class List(base.CommandBase):
109 """Run an Ad-Hoc command""" 175 """Run an Ad-Hoc command"""
110 176
111 def __init__(self, host): 177 def __init__(self, host):
112 super(List, self).__init__(host, 'list', use_verbose=True, help=_(u'list Ad-Hoc commands of a service')) 178 super(List, self).__init__(
113 self.need_loop=True 179 host, "list", use_verbose=True, help=_(u"list Ad-Hoc commands of a service")
180 )
181 self.need_loop = True
114 182
115 def add_parser_options(self): 183 def add_parser_options(self):
116 self.parser.add_argument('-j', '--jid', type=base.unicode_decoder, default=u'', help=_(u"jid of the service (default: profile's server")) 184 self.parser.add_argument(
185 "-j",
186 "--jid",
187 type=base.unicode_decoder,
188 default=u"",
189 help=_(u"jid of the service (default: profile's server"),
190 )
117 191
118 def adHocListCb(self, xmlui_raw): 192 def adHocListCb(self, xmlui_raw):
119 xmlui = xmlui_manager.create(self.host, xmlui_raw) 193 xmlui = xmlui_manager.create(self.host, xmlui_raw)
120 xmlui.readonly = True 194 xmlui.readonly = True
121 xmlui.show() 195 xmlui.show()
124 def start(self): 198 def start(self):
125 self.host.bridge.adHocList( 199 self.host.bridge.adHocList(
126 self.args.jid, 200 self.args.jid,
127 self.profile, 201 self.profile,
128 callback=self.adHocListCb, 202 callback=self.adHocListCb,
129 errback=partial(self.errback, 203 errback=partial(
130 msg=_(u"can't get ad-hoc commands list: {}"), 204 self.errback,
131 exit_code=C.EXIT_BRIDGE_ERRBACK)) 205 msg=_(u"can't get ad-hoc commands list: {}"),
206 exit_code=C.EXIT_BRIDGE_ERRBACK,
207 ),
208 )
132 209
133 210
134 class AdHoc(base.CommandBase): 211 class AdHoc(base.CommandBase):
135 subcommands = (Run, List, Remote) 212 subcommands = (Run, List, Remote)
136 213
137 def __init__(self, host): 214 def __init__(self, host):
138 super(AdHoc, self).__init__(host, 'ad-hoc', use_profile=False, help=_('Ad-hoc commands')) 215 super(AdHoc, self).__init__(
216 host, "ad-hoc", use_profile=False, help=_("Ad-hoc commands")
217 )