jp (profile): fixed "profile info" to use profile, and then manage connection.

This commit is contained in:
Goffi 2015-04-06 17:32:28 +02:00
commit 1bbe4c6921

View file

@ -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):