# HG changeset patch # User Goffi # Date 1534004695 -7200 # Node ID 32b5f68a23b43f7f35bb2f0e1b9285fb9328e0c3 # Parent 0bef44f8e8ca293c500b075b62c4516dd8b28091 jp (message): new encryption/algorithms command to retrieve available encryptions algorithms. diff -r 0bef44f8e8ca -r 32b5f68a23b4 sat_frontends/jp/cmd_message.py --- a/sat_frontends/jp/cmd_message.py Sat Aug 11 18:24:55 2018 +0200 +++ b/sat_frontends/jp/cmd_message.py Sat Aug 11 18:24:55 2018 +0200 @@ -18,10 +18,11 @@ # along with this program. If not, see . from sat_frontends.jp import base +from sat_frontends.jp.constants import Const as C import sys from sat.core.i18n import _ -from sat.core.constants import Const as C from sat.tools.utils import clean_ustr +from functools import partial __commands__ = ["Message"] @@ -39,7 +40,8 @@ "--separate", action="store_true", help=_( - u"separate xmpp messages: send one message per line instead of one message alone." + u"separate xmpp messages: send one message per line instead of one " + u"message alone." ), ) self.parser.add_argument( @@ -149,8 +151,56 @@ ) +class EncryptionAlgorithms(base.CommandBase): + + def __init__(self, host): + extra_outputs = {"default": self.default_output} + super(EncryptionAlgorithms, self).__init__( + host, "algorithms", + use_output=C.OUTPUT_LIST_DICT, + extra_outputs=extra_outputs, + use_profile=False, + help=_("show available encryption algorithms")) + self.need_loop = True + + def add_parser_options(self): + pass + + def encryptionPluginsGetCb(self, plugins): + self.output(plugins) + self.host.quit() + + def default_output(self, plugins): + if not plugins: + self.disp(_(u"No encryption plugin registered!")) + self.host.quit(C.EXIT_NOT_FOUND) + else: + self.disp(_(u"Following encryption algorithms are available: {algos}").format( + algos=', '.join([p['name'] for p in plugins]))) + self.host.quit() + + def start(self): + self.host.bridge.encryptionPluginsGet( + callback=self.encryptionPluginsGetCb, + errback=partial( + self.errback, + msg=_(u"can't retrieve plugins: {}"), + exit_code=C.EXIT_BRIDGE_ERRBACK, + ), + ) + + +class Encryption(base.CommandBase): + subcommands = (EncryptionAlgorithms,) + + def __init__(self, host): + super(Encryption, self).__init__( + host, "encryption", use_profile=False, help=_("encryption sessions handling") + ) + + class Message(base.CommandBase): - subcommands = (Send,) + subcommands = (Send, Encryption) def __init__(self, host): super(Message, self).__init__(