annotate sat_frontends/jp/cmd_profile.py @ 3115:3018d153a615

quick frontend (widgets): some more errors handling in getOrCreateWidget
author Goffi <goffi@goffi.org>
date Fri, 17 Jan 2020 18:47:02 +0100
parents fee60f17ebac
children 4486d72658b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1960
3e168cde7a7d jp: fixed shebang python call
Goffi <goffi@goffi.org>
parents: 1864
diff changeset
1 #!/usr/bin/env python2
815
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
2 # -*- coding: utf-8 -*-
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
3
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
4 # jp: a SAT command line tool
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2765
diff changeset
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
815
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
6
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
7 # This program is free software: you can redistribute it and/or modify
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
10 # (at your option) any later version.
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
11
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
12 # This program is distributed in the hope that it will be useful,
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
15 # GNU Affero General Public License for more details.
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
16
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
19
814
59c7bc51c323 jp: refactoring using ArgParse
Dal <kedals0@gmail.com>
parents: 811
diff changeset
20 """This module permits to manage profiles. It can list, create, delete
1199
96fb74a4714d misc: fixed some typos
Matteo Cypriani <mcy@lm7.fr>
parents: 1139
diff changeset
21 and retrieve information about a profile."""
0
goffi@necton2
parents:
diff changeset
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
63d191c05ecd jp (blog): set default template and data mapping for the new template output
Goffi <goffi@goffi.org>
parents: 2146
diff changeset
25 log = getLogger(__name__)
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 721
diff changeset
26 from sat.core.i18n import _
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
27 from sat_frontends.jp import base
402
f03688bdb858 jp: use with statement to open fifo
Goffi <goffi@goffi.org>
parents: 401
diff changeset
28
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
29 __commands__ = ["Profile"]
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
30
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
31 PROFILE_HELP = _('The name of the profile')
0
goffi@necton2
parents:
diff changeset
32
goffi@necton2
parents:
diff changeset
33
1597
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
34 class ProfileConnect(base.CommandBase):
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
35 """Dummy command to use profile_session parent, i.e. to be able to connect without doing anything else"""
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
36
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
37 def __init__(self, host):
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
38 # 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
39 # to launch just the session, so some paradoxes don't hurt
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
40 super(ProfileConnect, self).__init__(host, 'connect', need_connect=False, help=('connect a profile'))
1597
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
41
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
42 def add_parser_options(self):
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
43 pass
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
44
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
45 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
46 # connection is already managed by profile common commands
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
47 # so we just need to check arguments and quit
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
48 if not self.args.connect and not self.args.start_session:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
49 self.parser.error(_("You need to use either --connect or --start-session"))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
50 self.host.quit()
1597
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
51
2336
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
52 class ProfileDisconnect(base.CommandBase):
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
53
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
54 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
55 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
56
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
57 def add_parser_options(self):
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
58 pass
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
59
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
60 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
61 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
62 await self.host.bridge.disconnect(self.args.profile)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
63 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
64 self.disp(f"can't disconnect profile: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
65 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
66 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
67 self.host.quit()
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
68
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
69
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
70 class ProfileCreate(base.CommandBase):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
71 def __init__(self, host):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
72 super(ProfileCreate, self).__init__(host, 'create', use_profile=False, help=('create a new profile'))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
73
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
74 def add_parser_options(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
75 self.parser.add_argument('profile', type=str, help=_('the name of the profile'))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
76 self.parser.add_argument('-p', '--password', type=str, default='', help=_('the password of the profile'))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
77 self.parser.add_argument('-j', '--jid', type=str, help=_('the jid of the profile'))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
78 self.parser.add_argument('-x', '--xmpp-password', type=str, help=_('the password of the XMPP account (use profile password if not specified)'),
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
79 metavar='PASSWORD')
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
80 self.parser.add_argument('-C', '--component', default='',
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
81 help=_('set to component import name (entry point) if this is a component'))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
82
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
83 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
84 """Create a new profile"""
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
85 if self.args.profile in await self.host.bridge.profilesListGet():
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
86 self.disp(f"Profile {self.args.profile} already exists.", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
87 self.host.quit(C.EXIT_BRIDGE_ERROR)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
88 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
89 await self.host.bridge.profileCreate(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
90 self.args.profile, self.args.password, self.args.component)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
91 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
92 self.disp(f"can't create profile: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
93 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
94
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
95 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
96 await self.host.bridge.profileStartSession(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
97 self.args.password, self.args.profile)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
98 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
99 self.disp(f"can't start profile session: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
100 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
101
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
102 if self.args.jid:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
103 await self.host.bridge.setParam(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
104 "JabberID", self.args.jid, "Connection", profile_key=self.args.profile)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
105 xmpp_pwd = self.args.password or self.args.xmpp_password
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
106 if xmpp_pwd:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
107 await self.host.bridge.setParam(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
108 "Password", xmpp_pwd, "Connection", profile_key=self.args.profile)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
109
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
110 self.disp(f'profile {self.args.profile} created successfully', 1)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
111 self.host.quit()
2336
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
112
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
113
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
114 class ProfileDefault(base.CommandBase):
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
115 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
116 super(ProfileDefault, self).__init__(host, 'default', use_profile=False, help=('print default profile'))
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
117
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
118 def add_parser_options(self):
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
119 pass
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
120
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
121 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
122 print(await self.host.bridge.profileNameGet('@DEFAULT@'))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
123 self.host.quit()
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
124
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
125
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
126 class ProfileDelete(base.CommandBase):
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
127 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
128 super(ProfileDelete, self).__init__(host, 'delete', use_profile=False, help=('delete a profile'))
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
129
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
130 def add_parser_options(self):
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
131 self.parser.add_argument('profile', type=str, help=PROFILE_HELP)
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
132 self.parser.add_argument('-f', '--force', action='store_true', help=_('delete profile without confirmation'))
0
goffi@necton2
parents:
diff changeset
133
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
134 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
135 if self.args.profile not in await self.host.bridge.profilesListGet():
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
136 log.error(f"Profile {self.args.profile} doesn't exist.")
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
137 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
138 if not self.args.force:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
139 message = f"Are you sure to delete profile [{self.args.profile}] ?"
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
140 cancel_message = "Profile deletion cancelled"
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
141 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
142
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
143 await self.host.bridge.asyncDeleteProfile(self.args.profile)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
144 self.host.quit()
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
145
0
goffi@necton2
parents:
diff changeset
146
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
147 class ProfileInfo(base.CommandBase):
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
148 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
149 super(ProfileInfo, self).__init__(host, 'info', need_connect=False, help=_('get information about a profile'))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
150 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
151 self.largest = max([len(item[0]) for item in self.to_show])
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
152
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
153 def add_parser_options(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
154 self.parser.add_argument('--show-password', action='store_true', help=_('show the XMPP password IN CLEAR TEXT'))
814
59c7bc51c323 jp: refactoring using ArgParse
Dal <kedals0@gmail.com>
parents: 811
diff changeset
155
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
156 async def showNextValue(self, label=None, category=None, value=None):
1402
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
157 """Show next value from self.to_show and quit on last one"""
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
158 if label is not None:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
159 print((("{label:<"+str(self.largest+2)+"}{value}").format(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
160 label=label+": ", value=value)))
1402
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
161 try:
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
162 label, category, name = self.to_show.pop(0)
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
163 except IndexError:
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
164 self.host.quit()
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
165 else:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
166 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
167 value = await self.host.bridge.asyncGetParamA(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
168 name, category, profile_key=self.host.profile)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
169 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
170 self.disp(f"can't get {name}/{category} param: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
171 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
172 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
173 await self.showNextValue(label, category, value)
814
59c7bc51c323 jp: refactoring using ArgParse
Dal <kedals0@gmail.com>
parents: 811
diff changeset
174
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
175 async def start(self):
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
176 if self.args.show_password:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
177 self.to_show.append((_("XMPP password"), "Connection", "Password"))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
178 await self.showNextValue()
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
179
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
180
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
181 class ProfileList(base.CommandBase):
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
182 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
183 super(ProfileList, self).__init__(host, 'list', use_profile=False, use_output='list', help=('list profiles'))
657
09bbd5c00244 jp: profiles management
Dal <kedals0@gmail.com>
parents: 627
diff changeset
184
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
185 def add_parser_options(self):
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
186 group = self.parser.add_mutually_exclusive_group()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
187 group.add_argument('-c', '--clients', action='store_true', help=_('get clients profiles only'))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
188 group.add_argument('-C', '--components', action='store_true', help=('get components profiles only'))
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
189
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
190
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
191 async def start(self):
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
192 if self.args.clients:
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
193 clients, components = True, False
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
194 elif self.args.components:
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
195 clients, components = False, True
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
196 else:
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
197 clients, components = True, True
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
198 await self.output(await self.host.bridge.profilesListGet(clients, components))
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
199 self.host.quit()
657
09bbd5c00244 jp: profiles management
Dal <kedals0@gmail.com>
parents: 627
diff changeset
200
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
201
1404
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
202 class ProfileModify(base.CommandBase):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
203
1404
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
204 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
205 super(ProfileModify, self).__init__(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
206
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
207 def add_parser_options(self):
1687
de9cc4d62a4a jp (profile): fixed profile/modify command:
Goffi <goffi@goffi.org>
parents: 1597
diff changeset
208 profile_pwd_group = self.parser.add_mutually_exclusive_group()
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
209 profile_pwd_group.add_argument('-w', '--password', help=_('change the password of the profile'))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
210 profile_pwd_group.add_argument('--disable-password', action='store_true', help=_('disable profile password (dangerous!)'))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
211 self.parser.add_argument('-j', '--jid', help=_('the jid of the profile'))
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
212 self.parser.add_argument('-x', '--xmpp-password', help=_('change the password of the XMPP account'),
1404
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
213 metavar='PASSWORD')
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
214 self.parser.add_argument('-D', '--default', action='store_true', help=_('set as default profile'))
1404
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
215
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
216 async def start(self):
1687
de9cc4d62a4a jp (profile): fixed profile/modify command:
Goffi <goffi@goffi.org>
parents: 1597
diff changeset
217 if self.args.disable_password:
de9cc4d62a4a jp (profile): fixed profile/modify command:
Goffi <goffi@goffi.org>
parents: 1597
diff changeset
218 self.args.password = ''
1404
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
219 if self.args.password is not None:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
220 await self.host.bridge.setParam(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
221 "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
222 if self.args.jid is not None:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
223 await self.host.bridge.setParam(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
224 "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
225 if self.args.xmpp_password is not None:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
226 await self.host.bridge.setParam(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
227 "Password", self.args.xmpp_password, "Connection", profile_key=self.host.profile)
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
228 if self.args.default:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
229 await self.host.bridge.profileSetDefault(self.host.profile)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
230
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
231 self.host.quit()
1404
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
232
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
233
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
234 class Profile(base.CommandBase):
2336
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
235 subcommands = (ProfileConnect, ProfileDisconnect, ProfileCreate, ProfileDefault, ProfileDelete, ProfileInfo, ProfileList, ProfileModify)
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
236
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
237 def __init__(self, host):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
238 super(Profile, self).__init__(host, 'profile', use_profile=False, help=_('profile commands'))