Mercurial > libervia-backend
changeset 1402:391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 06 Apr 2015 17:32:28 +0200 |
parents | 265ff2bd8d67 |
children | f913b09cd9cc |
files | frontends/src/jp/cmd_profile.py |
diffstat | 1 files changed, 22 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- 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):