comparison sat_frontends/jp/cmd_message.py @ 2663:32b5f68a23b4

jp (message): new encryption/algorithms command to retrieve available encryptions algorithms.
author Goffi <goffi@goffi.org>
date Sat, 11 Aug 2018 18:24:55 +0200
parents 56f94936df1e
children 0b5deb9a35fd
comparison
equal deleted inserted replaced
2662:0bef44f8e8ca 2663:32b5f68a23b4
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 sat_frontends.jp import base 20 from sat_frontends.jp import base
21 from sat_frontends.jp.constants import Const as C
21 import sys 22 import sys
22 from sat.core.i18n import _ 23 from sat.core.i18n import _
23 from sat.core.constants import Const as C
24 from sat.tools.utils import clean_ustr 24 from sat.tools.utils import clean_ustr
25 from functools import partial
25 26
26 __commands__ = ["Message"] 27 __commands__ = ["Message"]
27 28
28 29
29 class Send(base.CommandBase): 30 class Send(base.CommandBase):
37 self.parser.add_argument( 38 self.parser.add_argument(
38 "-s", 39 "-s",
39 "--separate", 40 "--separate",
40 action="store_true", 41 action="store_true",
41 help=_( 42 help=_(
42 u"separate xmpp messages: send one message per line instead of one message alone." 43 u"separate xmpp messages: send one message per line instead of one "
44 u"message alone."
43 ), 45 ),
44 ) 46 )
45 self.parser.add_argument( 47 self.parser.add_argument(
46 "-n", 48 "-n",
47 "--new-line", 49 "--new-line",
147 callback=lambda: None, 149 callback=lambda: None,
148 errback=lambda ignore: ignore, 150 errback=lambda ignore: ignore,
149 ) 151 )
150 152
151 153
154 class EncryptionAlgorithms(base.CommandBase):
155
156 def __init__(self, host):
157 extra_outputs = {"default": self.default_output}
158 super(EncryptionAlgorithms, self).__init__(
159 host, "algorithms",
160 use_output=C.OUTPUT_LIST_DICT,
161 extra_outputs=extra_outputs,
162 use_profile=False,
163 help=_("show available encryption algorithms"))
164 self.need_loop = True
165
166 def add_parser_options(self):
167 pass
168
169 def encryptionPluginsGetCb(self, plugins):
170 self.output(plugins)
171 self.host.quit()
172
173 def default_output(self, plugins):
174 if not plugins:
175 self.disp(_(u"No encryption plugin registered!"))
176 self.host.quit(C.EXIT_NOT_FOUND)
177 else:
178 self.disp(_(u"Following encryption algorithms are available: {algos}").format(
179 algos=', '.join([p['name'] for p in plugins])))
180 self.host.quit()
181
182 def start(self):
183 self.host.bridge.encryptionPluginsGet(
184 callback=self.encryptionPluginsGetCb,
185 errback=partial(
186 self.errback,
187 msg=_(u"can't retrieve plugins: {}"),
188 exit_code=C.EXIT_BRIDGE_ERRBACK,
189 ),
190 )
191
192
193 class Encryption(base.CommandBase):
194 subcommands = (EncryptionAlgorithms,)
195
196 def __init__(self, host):
197 super(Encryption, self).__init__(
198 host, "encryption", use_profile=False, help=_("encryption sessions handling")
199 )
200
201
152 class Message(base.CommandBase): 202 class Message(base.CommandBase):
153 subcommands = (Send,) 203 subcommands = (Send, Encryption)
154 204
155 def __init__(self, host): 205 def __init__(self, host):
156 super(Message, self).__init__( 206 super(Message, self).__init__(
157 host, "message", use_profile=False, help=_("messages handling") 207 host, "message", use_profile=False, help=_("messages handling")
158 ) 208 )