comparison sat_frontends/jp/cmd_adhoc.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 003b8b4b56a7
children fee60f17ebac
comparison
equal deleted inserted replaced
3027:ff5bcb12ae60 3028:ab2696e34d29
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 import base 20 from . import base
21 from sat.core.i18n import _ 21 from sat.core.i18n import _
22 from functools import partial 22 from functools import partial
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
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__( 34 super(Remote, self).__init__(
35 host, "remote", use_verbose=True, help=_(u"remote control a software") 35 host, "remote", use_verbose=True, help=_("remote control a software")
36 ) 36 )
37 37
38 def add_parser_options(self): 38 def add_parser_options(self):
39 self.parser.add_argument("software", type=str, help=_(u"software name")) 39 self.parser.add_argument("software", type=str, help=_("software name"))
40 self.parser.add_argument( 40 self.parser.add_argument(
41 "-j", 41 "-j",
42 "--jids", 42 "--jids",
43 type=base.unicode_decoder, 43 nargs="*",
44 nargs="*", 44 default=[],
45 default=[], 45 help=_("jids allowed to use the command"),
46 help=_(u"jids allowed to use the command"),
47 ) 46 )
48 self.parser.add_argument( 47 self.parser.add_argument(
49 "-g", 48 "-g",
50 "--groups", 49 "--groups",
51 type=base.unicode_decoder, 50 nargs="*",
52 nargs="*", 51 default=[],
53 default=[], 52 help=_("groups allowed to use the command"),
54 help=_(u"groups allowed to use the command"),
55 ) 53 )
56 self.parser.add_argument( 54 self.parser.add_argument(
57 "--forbidden-groups", 55 "--forbidden-groups",
58 type=base.unicode_decoder, 56 nargs="*",
59 nargs="*", 57 default=[],
60 default=[], 58 help=_("groups that are *NOT* allowed to use the command"),
61 help=_(u"groups that are *NOT* allowed to use the command"),
62 ) 59 )
63 self.parser.add_argument( 60 self.parser.add_argument(
64 "--forbidden-jids", 61 "--forbidden-jids",
65 type=base.unicode_decoder, 62 nargs="*",
66 nargs="*", 63 default=[],
67 default=[], 64 help=_("jids that are *NOT* allowed to use the command"),
68 help=_(u"jids that are *NOT* allowed to use the command"), 65 )
69 ) 66 self.parser.add_argument(
70 self.parser.add_argument( 67 "-l", "--loop", action="store_true", help=_("loop on the commands")
71 "-l", "--loop", action="store_true", help=_(u"loop on the commands")
72 ) 68 )
73 69
74 def start(self): 70 def start(self):
75 name = self.args.software.lower() 71 name = self.args.software.lower()
76 flags = [] 72 flags = []
107 class Run(base.CommandBase): 103 class Run(base.CommandBase):
108 """Run an Ad-Hoc command""" 104 """Run an Ad-Hoc command"""
109 105
110 def __init__(self, host): 106 def __init__(self, host):
111 super(Run, self).__init__( 107 super(Run, self).__init__(
112 host, "run", use_verbose=True, help=_(u"run an Ad-Hoc command") 108 host, "run", use_verbose=True, help=_("run an Ad-Hoc command")
113 ) 109 )
114 self.need_loop = True 110 self.need_loop = True
115 111
116 def add_parser_options(self): 112 def add_parser_options(self):
117 self.parser.add_argument( 113 self.parser.add_argument(
118 "-j", 114 "-j",
119 "--jid", 115 "--jid",
120 type=base.unicode_decoder, 116 default="",
121 default=u"", 117 help=_("jid of the service (default: profile's server"),
122 help=_(u"jid of the service (default: profile's server"),
123 ) 118 )
124 self.parser.add_argument( 119 self.parser.add_argument(
125 "-S", 120 "-S",
126 "--submit", 121 "--submit",
127 action="append_const", 122 action="append_const",
128 const=xmlui_manager.SUBMIT, 123 const=xmlui_manager.SUBMIT,
129 dest="workflow", 124 dest="workflow",
130 help=_(u"submit form/page"), 125 help=_("submit form/page"),
131 ) 126 )
132 self.parser.add_argument( 127 self.parser.add_argument(
133 "-f", 128 "-f",
134 "--field", 129 "--field",
135 type=base.unicode_decoder,
136 action="append", 130 action="append",
137 nargs=2, 131 nargs=2,
138 dest="workflow", 132 dest="workflow",
139 metavar=(u"KEY", u"VALUE"), 133 metavar=("KEY", "VALUE"),
140 help=_(u"field value"), 134 help=_("field value"),
141 ) 135 )
142 self.parser.add_argument( 136 self.parser.add_argument(
143 "node", 137 "node",
144 type=base.unicode_decoder,
145 nargs="?", 138 nargs="?",
146 default=u"", 139 default="",
147 help=_(u"node of the command (default: list commands)"), 140 help=_("node of the command (default: list commands)"),
148 ) 141 )
149 142
150 def adHocRunCb(self, xmlui_raw): 143 def adHocRunCb(self, xmlui_raw):
151 xmlui = xmlui_manager.create(self.host, xmlui_raw) 144 xmlui = xmlui_manager.create(self.host, xmlui_raw)
152 workflow = self.args.workflow 145 workflow = self.args.workflow
163 self.args.node, 156 self.args.node,
164 self.profile, 157 self.profile,
165 callback=self.adHocRunCb, 158 callback=self.adHocRunCb,
166 errback=partial( 159 errback=partial(
167 self.errback, 160 self.errback,
168 msg=_(u"can't get ad-hoc commands list: {}"), 161 msg=_("can't get ad-hoc commands list: {}"),
169 exit_code=C.EXIT_BRIDGE_ERRBACK, 162 exit_code=C.EXIT_BRIDGE_ERRBACK,
170 ), 163 ),
171 ) 164 )
172 165
173 166
174 class List(base.CommandBase): 167 class List(base.CommandBase):
175 """Run an Ad-Hoc command""" 168 """Run an Ad-Hoc command"""
176 169
177 def __init__(self, host): 170 def __init__(self, host):
178 super(List, self).__init__( 171 super(List, self).__init__(
179 host, "list", use_verbose=True, help=_(u"list Ad-Hoc commands of a service") 172 host, "list", use_verbose=True, help=_("list Ad-Hoc commands of a service")
180 ) 173 )
181 self.need_loop = True 174 self.need_loop = True
182 175
183 def add_parser_options(self): 176 def add_parser_options(self):
184 self.parser.add_argument( 177 self.parser.add_argument(
185 "-j", 178 "-j",
186 "--jid", 179 "--jid",
187 type=base.unicode_decoder, 180 default="",
188 default=u"", 181 help=_("jid of the service (default: profile's server"),
189 help=_(u"jid of the service (default: profile's server"),
190 ) 182 )
191 183
192 def adHocListCb(self, xmlui_raw): 184 def adHocListCb(self, xmlui_raw):
193 xmlui = xmlui_manager.create(self.host, xmlui_raw) 185 xmlui = xmlui_manager.create(self.host, xmlui_raw)
194 xmlui.readonly = True 186 xmlui.readonly = True
200 self.args.jid, 192 self.args.jid,
201 self.profile, 193 self.profile,
202 callback=self.adHocListCb, 194 callback=self.adHocListCb,
203 errback=partial( 195 errback=partial(
204 self.errback, 196 self.errback,
205 msg=_(u"can't get ad-hoc commands list: {}"), 197 msg=_("can't get ad-hoc commands list: {}"),
206 exit_code=C.EXIT_BRIDGE_ERRBACK, 198 exit_code=C.EXIT_BRIDGE_ERRBACK,
207 ), 199 ),
208 ) 200 )
209 201
210 202