Mercurial > libervia-backend
comparison sat_frontends/jp/cmd_account.py @ 3435:df775db4c49b
jp (account): better exit code handling
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 04 Dec 2020 12:32:56 +0100 |
parents | 559a625a236b |
children | be6d91572633 |
comparison
equal
deleted
inserted
replaced
3434:c84c54c6b046 | 3435:df775db4c49b |
---|---|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 """This module permits to manage XMPP accounts using in-band registration (XEP-0077)""" | 20 """This module permits to manage XMPP accounts using in-band registration (XEP-0077)""" |
21 | 21 |
22 from sat_frontends.jp.constants import Const as C | 22 from sat_frontends.jp.constants import Const as C |
23 from sat_frontends.bridge.bridge_frontend import BridgeException | |
23 from sat.core.log import getLogger | 24 from sat.core.log import getLogger |
24 | |
25 log = getLogger(__name__) | |
26 from sat.core.i18n import _ | 25 from sat.core.i18n import _ |
27 from sat_frontends.jp import base | 26 from sat_frontends.jp import base |
28 from sat_frontends.tools import jid | 27 from sat_frontends.tools import jid |
28 | |
29 | |
30 log = getLogger(__name__) | |
29 | 31 |
30 __commands__ = ["Account"] | 32 __commands__ = ["Account"] |
31 | 33 |
32 | 34 |
33 class AccountCreate(base.CommandBase): | 35 class AccountCreate(base.CommandBase): |
81 self.args.password, | 83 self.args.password, |
82 self.args.email, | 84 self.args.email, |
83 self.args.host, | 85 self.args.host, |
84 self.args.port, | 86 self.args.port, |
85 ) | 87 ) |
86 except Exception as e: | 88 |
87 self.disp( | 89 except BridgeException as e: |
88 f"can't create account on {self.args.host or 'localhost'!r} with jid " | 90 if e.condition == 'conflict': |
89 f"{self.args.jid!r} using In-Band Registration: {e}", error=True) | 91 self.disp( |
90 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 92 f"The account {self.args.jid} already exists", |
93 error=True | |
94 ) | |
95 self.host.quit(C.EXIT_CONFLICT) | |
96 else: | |
97 self.disp( | |
98 f"can't create account on {self.args.host or 'localhost'!r} with jid " | |
99 f"{self.args.jid!r} using In-Band Registration: {e}", error=True) | |
100 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
101 except Exception as e: | |
102 self.disp(f"Internal error: {e}", error=True) | |
103 self.host.quit(C.EXIT_INTERNAL_ERROR) | |
91 | 104 |
92 self.disp(_("XMPP account created"), 1) | 105 self.disp(_("XMPP account created"), 1) |
93 | 106 |
94 if self.args.profile is None: | 107 if self.args.profile is None: |
95 self.host.quit() | 108 self.host.quit() |
100 await self.host.bridge.profileCreate( | 113 await self.host.bridge.profileCreate( |
101 self.args.profile, | 114 self.args.profile, |
102 self.args.password, | 115 self.args.password, |
103 "", | 116 "", |
104 ) | 117 ) |
105 except Exception as e: | 118 except BridgeException as e: |
106 self.disp( | 119 if e.condition == 'conflict': |
107 _(f"Can't create profile {self.args.profile} to associate with jid " | 120 self.disp( |
108 f"{self.args.jid}: {e}"), | 121 f"The profile {self.args.profile} already exists", |
109 error=True, | 122 error=True |
110 ) | 123 ) |
111 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 124 self.host.quit(C.EXIT_CONFLICT) |
125 else: | |
126 self.disp( | |
127 _(f"Can't create profile {self.args.profile} to associate with jid " | |
128 f"{self.args.jid}: {e}"), | |
129 error=True, | |
130 ) | |
131 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
132 except Exception as e: | |
133 self.disp(f"Internal error: {e}", error=True) | |
134 self.host.quit(C.EXIT_INTERNAL_ERROR) | |
112 | 135 |
113 self.disp(_("profile created"), 1) | 136 self.disp(_("profile created"), 1) |
114 try: | 137 try: |
115 await self.host.bridge.profileStartSession( | 138 await self.host.bridge.profileStartSession( |
116 self.args.password, | 139 self.args.password, |