Mercurial > libervia-backend
comparison frontends/src/jp/cmd_profile.py @ 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 | 069ad98b360d |
children | f913b09cd9cc |
comparison
equal
deleted
inserted
replaced
1401:265ff2bd8d67 | 1402:391b0c21f4be |
---|---|
21 and retrieve information about a profile.""" | 21 and retrieve information about a profile.""" |
22 | 22 |
23 from logging import debug, info, error, warning | 23 from logging import debug, info, error, warning |
24 from sat.core.i18n import _ | 24 from sat.core.i18n import _ |
25 from sat_frontends.jp import base | 25 from sat_frontends.jp import base |
26 from sat_frontends.tools.jid import JID | |
27 | 26 |
28 __commands__ = ["Profile"] | 27 __commands__ = ["Profile"] |
29 | 28 |
30 PROFILE_HELP = _('The name of the profile') | 29 PROFILE_HELP = _('The name of the profile') |
31 | 30 |
45 self.host.bridge.asyncDeleteProfile(self.args.profile, callback=lambda dummy: None) | 44 self.host.bridge.asyncDeleteProfile(self.args.profile, callback=lambda dummy: None) |
46 | 45 |
47 | 46 |
48 class ProfileInfo(base.CommandBase): | 47 class ProfileInfo(base.CommandBase): |
49 def __init__(self, host): | 48 def __init__(self, host): |
50 super(ProfileInfo, self).__init__(host, 'info', use_profile=False, help=_('Get information about a profile')) | 49 super(ProfileInfo, self).__init__(host, 'info', help=_('Get information about a profile')) |
50 self.to_show = [(_(u"jid"), "Connection", "JabberID"), | |
51 (_(u"XMPP password"), "Connection", "Password"), | |
52 ] | |
53 self.largest = max([len(item[0]) for item in self.to_show]) | |
54 | |
51 | 55 |
52 def add_parser_options(self): | 56 def add_parser_options(self): |
53 self.parser.add_argument('profile', type=str, help=PROFILE_HELP) | 57 pass |
54 | 58 |
55 def run(self): | 59 def showNextValue(self, label=None, category=None, value=None): |
56 super(ProfileInfo, self).run() | 60 """Show next value from self.to_show and quit on last one""" |
61 if label is not None: | |
62 print((u"{label:<"+unicode(self.largest+2)+"}{value}").format(label=label+": ", value=value)) | |
63 try: | |
64 label, category, name = self.to_show.pop(0) | |
65 except IndexError: | |
66 self.host.quit() | |
67 else: | |
68 self.host.bridge.asyncGetParamA(name, category, profile_key=self.host.profile, | |
69 callback=lambda value: self.showNextValue(label, category, value)) | |
70 | |
71 def connected(self): | |
57 self.need_loop = True | 72 self.need_loop = True |
58 | 73 super(ProfileInfo, self).connected() |
59 def getPassword(password): | 74 self.showNextValue() |
60 print "pwd: %s" % password | |
61 self.host.quit() | |
62 | |
63 def getJID(jid): | |
64 print "jid: %s" % jid | |
65 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=self.args.profile, callback=getPassword) | |
66 | |
67 if self.args.profile not in self.host.bridge.getProfilesList(): | |
68 error("Profile %s doesn't exist." % self.args.profile) | |
69 self.host.quit(1) | |
70 | |
71 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=self.args.profile, callback=getJID) | |
72 | 75 |
73 | 76 |
74 class ProfileList(base.CommandBase): | 77 class ProfileList(base.CommandBase): |
75 def __init__(self, host): | 78 def __init__(self, host): |
76 super(ProfileList, self).__init__(host, 'list', use_profile=False, help=_('List profiles')) | 79 super(ProfileList, self).__init__(host, 'list', use_profile=False, help=_('List profiles')) |