Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_profile.py @ 3366:e09cb08166a3
plugin XEP-0329, core(xmpp): moved `_compParseJids` to `SatXMPPComponent`:
This method to retrieve owner and peer JID from an element is generally useful for
components, thus it has been moved. The part to retrieve owner JID from local JID has been
splitted in its own `getOwnerFromJid` method.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 20 Sep 2020 14:04:11 +0200 |
parents | 559a625a236b |
children | be6d91572633 |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
815 | 3 |
4 # jp: a SAT command line tool | |
3136 | 5 # Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org) |
815 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
814 | 20 """This module permits to manage profiles. It can list, create, delete |
1199 | 21 and retrieve information about a profile.""" |
0 | 22 |
2492
fcf0ae8102b8
jp (profile/create): errback handling
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
23 from sat_frontends.jp.constants import Const as C |
2164
63d191c05ecd
jp (blog): set default template and data mapping for the new template output
Goffi <goffi@goffi.org>
parents:
2146
diff
changeset
|
24 from sat.core.log import getLogger |
771 | 25 from sat.core.i18n import _ |
817 | 26 from sat_frontends.jp import base |
402
f03688bdb858
jp: use with statement to open fifo
Goffi <goffi@goffi.org>
parents:
401
diff
changeset
|
27 |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
28 log = getLogger(__name__) |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
29 |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
30 |
817 | 31 __commands__ = ["Profile"] |
32 | |
33 PROFILE_HELP = _('The name of the profile') | |
0 | 34 |
35 | |
1597 | 36 class ProfileConnect(base.CommandBase): |
37 """Dummy command to use profile_session parent, i.e. to be able to connect without doing anything else""" | |
38 | |
39 def __init__(self, host): | |
40 # it's weird to have a command named "connect" with need_connect=False, but it can be handy to be able | |
2336
a7438fe4e24d
jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
41 # to launch just the session, so some paradoxes don't hurt |
3028 | 42 super(ProfileConnect, self).__init__(host, 'connect', need_connect=False, help=('connect a profile')) |
1597 | 43 |
44 def add_parser_options(self): | |
45 pass | |
46 | |
3040 | 47 async def start(self): |
48 # connection is already managed by profile common commands | |
49 # so we just need to check arguments and quit | |
50 if not self.args.connect and not self.args.start_session: | |
51 self.parser.error(_("You need to use either --connect or --start-session")) | |
52 self.host.quit() | |
1597 | 53 |
2336
a7438fe4e24d
jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
54 class ProfileDisconnect(base.CommandBase): |
a7438fe4e24d
jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
55 |
a7438fe4e24d
jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
56 def __init__(self, host): |
3028 | 57 super(ProfileDisconnect, self).__init__(host, 'disconnect', need_connect=False, help=('disconnect a profile')) |
2336
a7438fe4e24d
jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
58 |
a7438fe4e24d
jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
59 def add_parser_options(self): |
a7438fe4e24d
jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
60 pass |
a7438fe4e24d
jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
61 |
3040 | 62 async def start(self): |
63 try: | |
64 await self.host.bridge.disconnect(self.args.profile) | |
65 except Exception as e: | |
66 self.disp(f"can't disconnect profile: {e}", error=True) | |
67 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
68 else: | |
69 self.host.quit() | |
70 | |
71 | |
72 class ProfileCreate(base.CommandBase): | |
73 def __init__(self, host): | |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
74 super(ProfileCreate, self).__init__( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
75 host, 'create', use_profile=False, help=('create a new profile')) |
3040 | 76 |
77 def add_parser_options(self): | |
78 self.parser.add_argument('profile', type=str, help=_('the name of the profile')) | |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
79 self.parser.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
80 '-p', '--password', type=str, default='', |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
81 help=_('the password of the profile')) |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
82 self.parser.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
83 '-j', '--jid', type=str, help=_('the jid of the profile')) |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
84 self.parser.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
85 '-x', '--xmpp-password', type=str, |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
86 help=_( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
87 'the password of the XMPP account (use profile password if not specified)' |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
88 ), |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
89 metavar='PASSWORD') |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
90 self.parser.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
91 '-A', '--autoconnect', choices=[C.BOOL_TRUE, C.BOOL_FALSE], nargs='?', |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
92 const=C.BOOL_TRUE, |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
93 help=_('connect this profile automatically when backend starts') |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
94 ) |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
95 self.parser.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
96 '-C', '--component', default='', |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
97 help=_('set to component import name (entry point) if this is a component')) |
3040 | 98 |
99 async def start(self): | |
100 """Create a new profile""" | |
101 if self.args.profile in await self.host.bridge.profilesListGet(): | |
102 self.disp(f"Profile {self.args.profile} already exists.", error=True) | |
103 self.host.quit(C.EXIT_BRIDGE_ERROR) | |
104 try: | |
105 await self.host.bridge.profileCreate( | |
106 self.args.profile, self.args.password, self.args.component) | |
107 except Exception as e: | |
108 self.disp(f"can't create profile: {e}", error=True) | |
109 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
110 | |
111 try: | |
112 await self.host.bridge.profileStartSession( | |
113 self.args.password, self.args.profile) | |
114 except Exception as e: | |
115 self.disp(f"can't start profile session: {e}", error=True) | |
116 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
117 | |
118 if self.args.jid: | |
119 await self.host.bridge.setParam( | |
120 "JabberID", self.args.jid, "Connection", profile_key=self.args.profile) | |
121 xmpp_pwd = self.args.password or self.args.xmpp_password | |
122 if xmpp_pwd: | |
123 await self.host.bridge.setParam( | |
124 "Password", xmpp_pwd, "Connection", profile_key=self.args.profile) | |
125 | |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
126 if self.args.autoconnect is not None: |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
127 await self.host.bridge.setParam( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
128 "autoconnect_backend", self.args.autoconnect, "Connection", |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
129 profile_key=self.args.profile) |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
130 |
3040 | 131 self.disp(f'profile {self.args.profile} created successfully', 1) |
132 self.host.quit() | |
2336
a7438fe4e24d
jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
133 |
a7438fe4e24d
jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
134 |
1596 | 135 class ProfileDefault(base.CommandBase): |
136 def __init__(self, host): | |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
137 super(ProfileDefault, self).__init__( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
138 host, 'default', use_profile=False, help=('print default profile')) |
1596 | 139 |
140 def add_parser_options(self): | |
141 pass | |
142 | |
3040 | 143 async def start(self): |
144 print(await self.host.bridge.profileNameGet('@DEFAULT@')) | |
145 self.host.quit() | |
1596 | 146 |
147 | |
817 | 148 class ProfileDelete(base.CommandBase): |
149 def __init__(self, host): | |
3028 | 150 super(ProfileDelete, self).__init__(host, 'delete', use_profile=False, help=('delete a profile')) |
817 | 151 |
152 def add_parser_options(self): | |
153 self.parser.add_argument('profile', type=str, help=PROFILE_HELP) | |
3028 | 154 self.parser.add_argument('-f', '--force', action='store_true', help=_('delete profile without confirmation')) |
0 | 155 |
3040 | 156 async def start(self): |
157 if self.args.profile not in await self.host.bridge.profilesListGet(): | |
158 log.error(f"Profile {self.args.profile} doesn't exist.") | |
159 self.host.quit(C.EXIT_NOT_FOUND) | |
1861
3b2a236fa743
jp (profile): added confirmation and --force arguement to profile/delete
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
160 if not self.args.force: |
3040 | 161 message = f"Are you sure to delete profile [{self.args.profile}] ?" |
162 cancel_message = "Profile deletion cancelled" | |
163 await self.host.confirmOrQuit(message, cancel_message) | |
1861
3b2a236fa743
jp (profile): added confirmation and --force arguement to profile/delete
Goffi <goffi@goffi.org>
parents:
1766
diff
changeset
|
164 |
3040 | 165 await self.host.bridge.asyncDeleteProfile(self.args.profile) |
166 self.host.quit() | |
817 | 167 |
0 | 168 |
817 | 169 class ProfileInfo(base.CommandBase): |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
170 |
817 | 171 def __init__(self, host): |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
172 super(ProfileInfo, self).__init__( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
173 host, 'info', need_connect=False, use_output=C.OUTPUT_DICT, |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
174 help=_('get information about a profile')) |
3028 | 175 self.to_show = [(_("jid"), "Connection", "JabberID"),] |
1402
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
176 |
817 | 177 def add_parser_options(self): |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
178 self.parser.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
179 '--show-password', action='store_true', |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
180 help=_('show the XMPP password IN CLEAR TEXT')) |
814 | 181 |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
182 async def start(self): |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
183 if self.args.show_password: |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
184 self.to_show.append((_("XMPP password"), "Connection", "Password")) |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
185 self.to_show.append((_("autoconnect (backend)"), "Connection", |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
186 "autoconnect_backend")) |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
187 data = {} |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
188 for label, category, name in self.to_show: |
3040 | 189 try: |
190 value = await self.host.bridge.asyncGetParamA( | |
191 name, category, profile_key=self.host.profile) | |
192 except Exception as e: | |
193 self.disp(f"can't get {name}/{category} param: {e}", error=True) | |
194 else: | |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
195 data[label] = value |
814 | 196 |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
197 await self.output(data) |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
198 self.host.quit() |
817 | 199 |
200 | |
201 class ProfileList(base.CommandBase): | |
202 def __init__(self, host): | |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
203 super(ProfileList, self).__init__( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
204 host, 'list', use_profile=False, use_output='list', help=('list profiles')) |
657 | 205 |
817 | 206 def add_parser_options(self): |
2146
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
207 group = self.parser.add_mutually_exclusive_group() |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
208 group.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
209 '-c', '--clients', action='store_true', help=_('get clients profiles only')) |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
210 group.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
211 '-C', '--components', action='store_true', |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
212 help=('get components profiles only')) |
817 | 213 |
3040 | 214 async def start(self): |
2146
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
215 if self.args.clients: |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
216 clients, components = True, False |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
217 elif self.args.components: |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
218 clients, components = False, True |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
219 else: |
1bb9bf1b4150
core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents:
2144
diff
changeset
|
220 clients, components = True, True |
3040 | 221 await self.output(await self.host.bridge.profilesListGet(clients, components)) |
817 | 222 self.host.quit() |
657 | 223 |
817 | 224 |
1404
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
225 class ProfileModify(base.CommandBase): |
3040 | 226 |
1404
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
227 def __init__(self, host): |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
228 super(ProfileModify, self).__init__( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
229 host, 'modify', need_connect=False, help=_('modify an existing profile')) |
1404
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
230 |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
231 def add_parser_options(self): |
1687
de9cc4d62a4a
jp (profile): fixed profile/modify command:
Goffi <goffi@goffi.org>
parents:
1597
diff
changeset
|
232 profile_pwd_group = self.parser.add_mutually_exclusive_group() |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
233 profile_pwd_group.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
234 '-w', '--password', help=_('change the password of the profile')) |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
235 profile_pwd_group.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
236 '--disable-password', action='store_true', |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
237 help=_('disable profile password (dangerous!)')) |
3028 | 238 self.parser.add_argument('-j', '--jid', help=_('the jid of the profile')) |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
239 self.parser.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
240 '-x', '--xmpp-password', help=_('change the password of the XMPP account'), |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
241 metavar='PASSWORD') |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
242 self.parser.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
243 '-D', '--default', action='store_true', help=_('set as default profile')) |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
244 self.parser.add_argument( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
245 '-A', '--autoconnect', choices=[C.BOOL_TRUE, C.BOOL_FALSE], nargs='?', |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
246 const=C.BOOL_TRUE, |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
247 help=_('connect this profile automatically when backend starts') |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
248 ) |
1404
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
249 |
3040 | 250 async def start(self): |
1687
de9cc4d62a4a
jp (profile): fixed profile/modify command:
Goffi <goffi@goffi.org>
parents:
1597
diff
changeset
|
251 if self.args.disable_password: |
de9cc4d62a4a
jp (profile): fixed profile/modify command:
Goffi <goffi@goffi.org>
parents:
1597
diff
changeset
|
252 self.args.password = '' |
1404
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
253 if self.args.password is not None: |
3040 | 254 await self.host.bridge.setParam( |
255 "Password", self.args.password, "General", profile_key=self.host.profile) | |
1404
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
256 if self.args.jid is not None: |
3040 | 257 await self.host.bridge.setParam( |
258 "JabberID", self.args.jid, "Connection", profile_key=self.host.profile) | |
1404
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
259 if self.args.xmpp_password is not None: |
3040 | 260 await self.host.bridge.setParam( |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
261 "Password", self.args.xmpp_password, "Connection", |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
262 profile_key=self.host.profile) |
1596 | 263 if self.args.default: |
3040 | 264 await self.host.bridge.profileSetDefault(self.host.profile) |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
265 if self.args.autoconnect is not None: |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
266 await self.host.bridge.setParam( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
267 "autoconnect_backend", self.args.autoconnect, "Connection", |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
268 profile_key=self.host.profile) |
3040 | 269 |
270 self.host.quit() | |
1404
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
271 |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
272 |
817 | 273 class Profile(base.CommandBase): |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
274 subcommands = ( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
275 ProfileConnect, ProfileDisconnect, ProfileCreate, ProfileDefault, ProfileDelete, |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
276 ProfileInfo, ProfileList, ProfileModify) |
817 | 277 |
278 def __init__(self, host): | |
3122
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
279 super(Profile, self).__init__( |
4486d72658b9
jp (profile): added --autoconnect argument in `modify` and `create` + use output in `info`
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
280 host, 'profile', use_profile=False, help=_('profile commands')) |