jp (message): new encryption/algorithms command to retrieve available encryptions algorithms.

This commit is contained in:
Goffi 2018-08-11 18:24:55 +02:00
commit 3fc6de121a

View file

@ -18,10 +18,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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 @@ class Send(base.CommandBase):
"--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 Send(base.CommandBase):
)
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__(