Mercurial > libervia-backend
comparison frontends/src/jp/cmd_profile.py @ 1864:96ba685162f6
jp: all commands now use the new start method and set need_loop in __init__ when needed
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 29 Feb 2016 16:52:51 +0100 |
parents | 3b2a236fa743 |
children | 227a4e617549 3e168cde7a7d |
comparison
equal
deleted
inserted
replaced
1863:b2ddd7f5dcdf | 1864:96ba685162f6 |
---|---|
46 super(ProfileDefault, self).__init__(host, 'default', use_profile=False, help=_('print default profile')) | 46 super(ProfileDefault, self).__init__(host, 'default', use_profile=False, help=_('print default profile')) |
47 | 47 |
48 def add_parser_options(self): | 48 def add_parser_options(self): |
49 pass | 49 pass |
50 | 50 |
51 def run(self): | 51 def start(self): |
52 print self.host.bridge.getProfileName('@DEFAULT@') | 52 print self.host.bridge.getProfileName('@DEFAULT@') |
53 | 53 |
54 | 54 |
55 class ProfileDelete(base.CommandBase): | 55 class ProfileDelete(base.CommandBase): |
56 def __init__(self, host): | 56 def __init__(self, host): |
58 | 58 |
59 def add_parser_options(self): | 59 def add_parser_options(self): |
60 self.parser.add_argument('profile', type=str, help=PROFILE_HELP) | 60 self.parser.add_argument('profile', type=str, help=PROFILE_HELP) |
61 self.parser.add_argument('-f', '--force', action='store_true', help=_(u'delete profile without confirmation')) | 61 self.parser.add_argument('-f', '--force', action='store_true', help=_(u'delete profile without confirmation')) |
62 | 62 |
63 def run(self): | 63 def start(self): |
64 super(ProfileDelete, self).run() | |
65 if self.args.profile not in self.host.bridge.getProfilesList(): | 64 if self.args.profile not in self.host.bridge.getProfilesList(): |
66 log.error("Profile %s doesn't exist." % self.args.profile) | 65 log.error("Profile %s doesn't exist." % self.args.profile) |
67 self.host.quit(1) | 66 self.host.quit(1) |
68 message = u"Are you sure to delete profile [{}] ?".format(self.args.profile) | 67 message = u"Are you sure to delete profile [{}] ?".format(self.args.profile) |
69 if not self.args.force: | 68 if not self.args.force: |
76 | 75 |
77 | 76 |
78 class ProfileInfo(base.CommandBase): | 77 class ProfileInfo(base.CommandBase): |
79 def __init__(self, host): | 78 def __init__(self, host): |
80 super(ProfileInfo, self).__init__(host, 'info', need_connect=False, help=_('get information about a profile')) | 79 super(ProfileInfo, self).__init__(host, 'info', need_connect=False, help=_('get information about a profile')) |
80 self.need_loop = True | |
81 self.to_show = [(_(u"jid"), "Connection", "JabberID"),] | 81 self.to_show = [(_(u"jid"), "Connection", "JabberID"),] |
82 self.largest = max([len(item[0]) for item in self.to_show]) | 82 self.largest = max([len(item[0]) for item in self.to_show]) |
83 | 83 |
84 | 84 |
85 def add_parser_options(self): | 85 def add_parser_options(self): |
95 self.host.quit() | 95 self.host.quit() |
96 else: | 96 else: |
97 self.host.bridge.asyncGetParamA(name, category, profile_key=self.host.profile, | 97 self.host.bridge.asyncGetParamA(name, category, profile_key=self.host.profile, |
98 callback=lambda value: self.showNextValue(label, category, value)) | 98 callback=lambda value: self.showNextValue(label, category, value)) |
99 | 99 |
100 def connected(self): | 100 def start(self): |
101 self.need_loop = True | |
102 super(ProfileInfo, self).connected() | |
103 if self.args.show_password: | 101 if self.args.show_password: |
104 self.to_show.append((_(u"XMPP password"), "Connection", "Password")) | 102 self.to_show.append((_(u"XMPP password"), "Connection", "Password")) |
105 self.showNextValue() | 103 self.showNextValue() |
106 | 104 |
107 | 105 |
110 super(ProfileList, self).__init__(host, 'list', use_profile=False, help=_('list profiles')) | 108 super(ProfileList, self).__init__(host, 'list', use_profile=False, help=_('list profiles')) |
111 | 109 |
112 def add_parser_options(self): | 110 def add_parser_options(self): |
113 pass | 111 pass |
114 | 112 |
115 def run(self): | 113 def start(self): |
116 super(ProfileList, self).run() | |
117 for profile in self.host.bridge.getProfilesList(): | 114 for profile in self.host.bridge.getProfilesList(): |
118 print profile | 115 print profile |
119 | 116 |
120 | 117 |
121 class ProfileCreate(base.CommandBase): | 118 class ProfileCreate(base.CommandBase): |
122 def __init__(self, host): | 119 def __init__(self, host): |
123 super(ProfileCreate, self).__init__(host, 'create', use_profile=False, help=_('create a new profile')) | 120 super(ProfileCreate, self).__init__(host, 'create', use_profile=False, help=_('create a new profile')) |
121 self.need_loop = True | |
124 | 122 |
125 def add_parser_options(self): | 123 def add_parser_options(self): |
126 self.parser.add_argument('profile', type=str, help=_('the name of the profile')) | 124 self.parser.add_argument('profile', type=str, help=_('the name of the profile')) |
127 self.parser.add_argument('-p', '--password', type=str, default='', help=_('the password of the profile')) | 125 self.parser.add_argument('-p', '--password', type=str, default='', help=_('the password of the profile')) |
128 self.parser.add_argument('-j', '--jid', type=str, help=_('the jid of the profile')) | 126 self.parser.add_argument('-j', '--jid', type=str, help=_('the jid of the profile')) |
138 self.host.quit() | 136 self.host.quit() |
139 | 137 |
140 def _profile_created(self): | 138 def _profile_created(self): |
141 self.host.bridge.profileStartSession(self.args.password, self.args.profile, callback=self._session_started, errback=None) | 139 self.host.bridge.profileStartSession(self.args.password, self.args.profile, callback=self._session_started, errback=None) |
142 | 140 |
143 def run(self): | 141 def start(self): |
144 """Create a new profile""" | 142 """Create a new profile""" |
145 self.need_loop = True | |
146 if self.args.profile in self.host.bridge.getProfilesList(): | 143 if self.args.profile in self.host.bridge.getProfilesList(): |
147 log.error("Profile %s already exists." % self.args.profile) | 144 log.error("Profile %s already exists." % self.args.profile) |
148 self.host.quit(1) | 145 self.host.quit(1) |
149 self.host.bridge.asyncCreateProfile(self.args.profile, self.args.password, callback=self._profile_created, errback=None) | 146 self.host.bridge.asyncCreateProfile(self.args.profile, self.args.password, callback=self._profile_created, errback=None) |
150 | 147 |
160 self.parser.add_argument('-j', '--jid', type=base.unicode_decoder, help=_('the jid of the profile')) | 157 self.parser.add_argument('-j', '--jid', type=base.unicode_decoder, help=_('the jid of the profile')) |
161 self.parser.add_argument('-x', '--xmpp-password', type=base.unicode_decoder, help=_('change the password of the XMPP account'), | 158 self.parser.add_argument('-x', '--xmpp-password', type=base.unicode_decoder, help=_('change the password of the XMPP account'), |
162 metavar='PASSWORD') | 159 metavar='PASSWORD') |
163 self.parser.add_argument('-D', '--default', action='store_true', help=_(u'set as default profile')) | 160 self.parser.add_argument('-D', '--default', action='store_true', help=_(u'set as default profile')) |
164 | 161 |
165 def connected(self): | 162 def start(self): |
166 super(ProfileModify, self).connected() | |
167 if self.args.disable_password: | 163 if self.args.disable_password: |
168 self.args.password = '' | 164 self.args.password = '' |
169 if self.args.password is not None: | 165 if self.args.password is not None: |
170 self.host.bridge.setParam("Password", self.args.password, "General", profile_key=self.host.profile) | 166 self.host.bridge.setParam("Password", self.args.password, "General", profile_key=self.host.profile) |
171 if self.args.jid is not None: | 167 if self.args.jid is not None: |