# HG changeset patch # User Goffi # Date 1428334348 -7200 # Node ID 391b0c21f4be8ef55787e9310fcfa996cc618e3a # Parent 265ff2bd8d67f219123c6b5809ffd4c58b3789af jp (profile): fixed "profile info" to use profile, and then manage connection. diff -r 265ff2bd8d67 -r 391b0c21f4be frontends/src/jp/cmd_profile.py --- a/frontends/src/jp/cmd_profile.py Mon Apr 06 12:11:23 2015 +0200 +++ b/frontends/src/jp/cmd_profile.py Mon Apr 06 17:32:28 2015 +0200 @@ -23,7 +23,6 @@ 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 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) - - def run(self): - super(ProfileInfo, self).run() - self.need_loop = True - - def getPassword(password): - print "pwd: %s" % password - self.host.quit() + pass - def getJID(jid): - print "jid: %s" % jid - self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=self.args.profile, callback=getPassword) + 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)) - 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):