From 1bbe4c69215775d5036938022886f21a9ab7e0e8 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 6 Apr 2015 17:32:28 +0200 Subject: [PATCH] jp (profile): fixed "profile info" to use profile, and then manage connection. --- frontends/src/jp/cmd_profile.py | 39 ++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/frontends/src/jp/cmd_profile.py b/frontends/src/jp/cmd_profile.py index c06d4290..0baec3a7 100644 --- a/frontends/src/jp/cmd_profile.py +++ b/frontends/src/jp/cmd_profile.py @@ -23,7 +23,6 @@ and retrieve information about a profile.""" from logging import debug, info, error, warning from sat.core.i18n import _ from sat_frontends.jp import base -from sat_frontends.tools.jid import JID __commands__ = ["Profile"] @@ -47,28 +46,32 @@ class ProfileDelete(base.CommandBase): class ProfileInfo(base.CommandBase): def __init__(self, host): - super(ProfileInfo, self).__init__(host, 'info', use_profile=False, help=_('Get information about a profile')) + super(ProfileInfo, self).__init__(host, 'info', help=_('Get information about a profile')) + self.to_show = [(_(u"jid"), "Connection", "JabberID"), + (_(u"XMPP password"), "Connection", "Password"), + ] + self.largest = max([len(item[0]) for item in self.to_show]) + def add_parser_options(self): - self.parser.add_argument('profile', type=str, help=PROFILE_HELP) + pass - def run(self): - super(ProfileInfo, self).run() - self.need_loop = True - - def getPassword(password): - print "pwd: %s" % password + def showNextValue(self, label=None, category=None, value=None): + """Show next value from self.to_show and quit on last one""" + if label is not None: + print((u"{label:<"+unicode(self.largest+2)+"}{value}").format(label=label+": ", value=value)) + try: + label, category, name = self.to_show.pop(0) + except IndexError: self.host.quit() + else: + self.host.bridge.asyncGetParamA(name, category, profile_key=self.host.profile, + callback=lambda value: self.showNextValue(label, category, value)) - def getJID(jid): - print "jid: %s" % jid - self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=self.args.profile, callback=getPassword) - - if self.args.profile not in self.host.bridge.getProfilesList(): - error("Profile %s doesn't exist." % self.args.profile) - self.host.quit(1) - - self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=self.args.profile, callback=getJID) + def connected(self): + self.need_loop = True + super(ProfileInfo, self).connected() + self.showNextValue() class ProfileList(base.CommandBase):