Mercurial > libervia-backend
comparison sat_frontends/jp/cmd_account.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 003b8b4b56a7 |
children | fee60f17ebac |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
35 super(AccountCreate, self).__init__( | 35 super(AccountCreate, self).__init__( |
36 host, | 36 host, |
37 "create", | 37 "create", |
38 use_profile=False, | 38 use_profile=False, |
39 use_verbose=True, | 39 use_verbose=True, |
40 help=_(u"create a XMPP account"), | 40 help=_("create a XMPP account"), |
41 ) | 41 ) |
42 self.need_loop = True | 42 self.need_loop = True |
43 | 43 |
44 def add_parser_options(self): | 44 def add_parser_options(self): |
45 self.parser.add_argument( | 45 self.parser.add_argument( |
46 "jid", type=base.unicode_decoder, help=_(u"jid to create") | 46 "jid", help=_("jid to create") |
47 ) | 47 ) |
48 self.parser.add_argument( | 48 self.parser.add_argument( |
49 "password", type=base.unicode_decoder, help=_(u"password of the account") | 49 "password", help=_("password of the account") |
50 ) | 50 ) |
51 self.parser.add_argument( | 51 self.parser.add_argument( |
52 "-p", | 52 "-p", |
53 "--profile", | 53 "--profile", |
54 type=base.unicode_decoder, | |
55 help=_( | 54 help=_( |
56 u"create a profile to use this account (default: don't create profile)" | 55 "create a profile to use this account (default: don't create profile)" |
57 ), | 56 ), |
58 ) | 57 ) |
59 self.parser.add_argument( | 58 self.parser.add_argument( |
60 "-e", | 59 "-e", |
61 "--email", | 60 "--email", |
62 type=base.unicode_decoder, | |
63 default="", | 61 default="", |
64 help=_(u"email (usage depends of XMPP server)"), | 62 help=_("email (usage depends of XMPP server)"), |
65 ) | 63 ) |
66 self.parser.add_argument( | 64 self.parser.add_argument( |
67 "-H", | 65 "-H", |
68 "--host", | 66 "--host", |
69 type=base.unicode_decoder, | |
70 default="", | 67 default="", |
71 help=_(u"server host (IP address or domain, default: use localhost)"), | 68 help=_("server host (IP address or domain, default: use localhost)"), |
72 ) | 69 ) |
73 self.parser.add_argument( | 70 self.parser.add_argument( |
74 "-P", | 71 "-P", |
75 "--port", | 72 "--port", |
76 type=int, | 73 type=int, |
77 default=0, | 74 default=0, |
78 help=_(u"server port (IP address or domain, default: use localhost)"), | 75 help=_("server port (IP address or domain, default: use localhost)"), |
79 ) | 76 ) |
80 | 77 |
81 def _setParamCb(self): | 78 def _setParamCb(self): |
82 self.host.bridge.setParam( | 79 self.host.bridge.setParam( |
83 "Password", | 80 "Password", |
97 callback=self._setParamCb, | 94 callback=self._setParamCb, |
98 errback=self.errback, | 95 errback=self.errback, |
99 ) | 96 ) |
100 | 97 |
101 def _profileCreateCb(self): | 98 def _profileCreateCb(self): |
102 self.disp(_(u"profile created"), 1) | 99 self.disp(_("profile created"), 1) |
103 self.host.bridge.profileStartSession( | 100 self.host.bridge.profileStartSession( |
104 self.args.password, | 101 self.args.password, |
105 self.args.profile, | 102 self.args.profile, |
106 callback=self._session_started, | 103 callback=self._session_started, |
107 errback=self.errback, | 104 errback=self.errback, |
108 ) | 105 ) |
109 | 106 |
110 def _profileCreateEb(self, failure_): | 107 def _profileCreateEb(self, failure_): |
111 self.disp( | 108 self.disp( |
112 _( | 109 _( |
113 u"Can't create profile {profile} to associate with jid {jid}: {msg}" | 110 "Can't create profile {profile} to associate with jid {jid}: {msg}" |
114 ).format(profile=self.args.profile, jid=self.args.jid, msg=failure_), | 111 ).format(profile=self.args.profile, jid=self.args.jid, msg=failure_), |
115 error=True, | 112 error=True, |
116 ) | 113 ) |
117 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 114 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
118 | 115 |
119 def accountNewCb(self): | 116 def accountNewCb(self): |
120 self.disp(_(u"XMPP account created"), 1) | 117 self.disp(_("XMPP account created"), 1) |
121 if self.args.profile is not None: | 118 if self.args.profile is not None: |
122 self.disp(_(u"creating profile"), 2) | 119 self.disp(_("creating profile"), 2) |
123 self.host.bridge.profileCreate( | 120 self.host.bridge.profileCreate( |
124 self.args.profile, | 121 self.args.profile, |
125 self.args.password, | 122 self.args.password, |
126 "", | 123 "", |
127 callback=self._profileCreateCb, | 124 callback=self._profileCreateCb, |
130 else: | 127 else: |
131 self.host.quit() | 128 self.host.quit() |
132 | 129 |
133 def accountNewEb(self, failure_): | 130 def accountNewEb(self, failure_): |
134 self.disp( | 131 self.disp( |
135 _(u"Can't create new account on server {host} with jid {jid}: {msg}").format( | 132 _("Can't create new account on server {host} with jid {jid}: {msg}").format( |
136 host=self.args.host or u"localhost", jid=self.args.jid, msg=failure_ | 133 host=self.args.host or "localhost", jid=self.args.jid, msg=failure_ |
137 ), | 134 ), |
138 error=True, | 135 error=True, |
139 ) | 136 ) |
140 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | 137 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
141 | 138 |
152 | 149 |
153 | 150 |
154 class AccountModify(base.CommandBase): | 151 class AccountModify(base.CommandBase): |
155 def __init__(self, host): | 152 def __init__(self, host): |
156 super(AccountModify, self).__init__( | 153 super(AccountModify, self).__init__( |
157 host, "modify", help=_(u"change password for XMPP account") | 154 host, "modify", help=_("change password for XMPP account") |
158 ) | 155 ) |
159 self.need_loop = True | 156 self.need_loop = True |
160 | 157 |
161 def add_parser_options(self): | 158 def add_parser_options(self): |
162 self.parser.add_argument( | 159 self.parser.add_argument( |
163 "password", type=base.unicode_decoder, help=_(u"new XMPP password") | 160 "password", help=_("new XMPP password") |
164 ) | 161 ) |
165 | 162 |
166 def start(self): | 163 def start(self): |
167 self.host.bridge.inBandPasswordChange( | 164 self.host.bridge.inBandPasswordChange( |
168 self.args.password, | 165 self.args.password, |
173 | 170 |
174 | 171 |
175 class AccountDelete(base.CommandBase): | 172 class AccountDelete(base.CommandBase): |
176 def __init__(self, host): | 173 def __init__(self, host): |
177 super(AccountDelete, self).__init__( | 174 super(AccountDelete, self).__init__( |
178 host, "delete", help=_(u"delete a XMPP account") | 175 host, "delete", help=_("delete a XMPP account") |
179 ) | 176 ) |
180 self.need_loop = True | 177 self.need_loop = True |
181 | 178 |
182 def add_parser_options(self): | 179 def add_parser_options(self): |
183 self.parser.add_argument( | 180 self.parser.add_argument( |
184 "-f", | 181 "-f", |
185 "--force", | 182 "--force", |
186 action="store_true", | 183 action="store_true", |
187 help=_(u"delete account without confirmation"), | 184 help=_("delete account without confirmation"), |
188 ) | 185 ) |
189 | 186 |
190 def _got_jid(self, jid_str): | 187 def _got_jid(self, jid_str): |
191 jid_ = jid.JID(jid_str) | 188 jid_ = jid.JID(jid_str) |
192 if not self.args.force: | 189 if not self.args.force: |
193 message = ( | 190 message = ( |
194 u"You are about to delete the XMPP account with jid {jid_}\n" | 191 "You are about to delete the XMPP account with jid {jid_}\n" |
195 u'This is the XMPP account of profile "{profile}"\n' | 192 'This is the XMPP account of profile "{profile}"\n' |
196 u"Are you sure that you want to delete this account ?".format( | 193 "Are you sure that you want to delete this account ?".format( |
197 jid_=jid_, profile=self.profile | 194 jid_=jid_, profile=self.profile |
198 ) | 195 ) |
199 ) | 196 ) |
200 res = raw_input("{} (y/N)? ".format(message)) | 197 res = input("{} (y/N)? ".format(message)) |
201 if res not in ("y", "Y"): | 198 if res not in ("y", "Y"): |
202 self.disp(_(u"Account deletion cancelled")) | 199 self.disp(_("Account deletion cancelled")) |
203 self.host.quit(2) | 200 self.host.quit(2) |
204 self.host.bridge.inBandUnregister( | 201 self.host.bridge.inBandUnregister( |
205 jid_.domain, self.args.profile, callback=self.host.quit, errback=self.errback | 202 jid_.domain, self.args.profile, callback=self.host.quit, errback=self.errback |
206 ) | 203 ) |
207 | 204 |
218 class Account(base.CommandBase): | 215 class Account(base.CommandBase): |
219 subcommands = (AccountCreate, AccountModify, AccountDelete) | 216 subcommands = (AccountCreate, AccountModify, AccountDelete) |
220 | 217 |
221 def __init__(self, host): | 218 def __init__(self, host): |
222 super(Account, self).__init__( | 219 super(Account, self).__init__( |
223 host, "account", use_profile=False, help=(u"XMPP account management") | 220 host, "account", use_profile=False, help=("XMPP account management") |
224 ) | 221 ) |