Mercurial > libervia-backend
comparison sat_frontends/quick_frontend/quick_profile_manager.py @ 4037:524856bd7b19
massive refactoring to switch from camelCase to snake_case:
historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a
pre-PEP8 code, to use the same coding style as in Twisted.
However, snake_case is more readable and it's better to follow PEP8 best practices, so it
has been decided to move on full snake_case. Because Libervia has a huge codebase, this
ended with a ugly mix of camelCase and snake_case.
To fix that, this patch does a big refactoring by renaming every function and method
(including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case.
This is a massive change, and may result in some bugs.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 08 Apr 2023 13:54:42 +0200 |
parents | be6d91572633 |
children | 4b842c1fb686 |
comparison
equal
deleted
inserted
replaced
4036:c4464d7ae97b | 4037:524856bd7b19 |
---|---|
104 # all the profiles have been validated | 104 # all the profiles have been validated |
105 self.host.plug_profiles(self._autoconnect_profiles) | 105 self.host.plug_profiles(self._autoconnect_profiles) |
106 else: | 106 else: |
107 # a profile is not validated, we go to manual mode | 107 # a profile is not validated, we go to manual mode |
108 self._autoconnect = False | 108 self._autoconnect = False |
109 self.host.actionManager(data, callback=authenticate_cb, profile=profile) | 109 self.host.action_manager(data, callback=authenticate_cb, profile=profile) |
110 | 110 |
111 def getProfileNameCb(profile): | 111 def get_profile_name_cb(profile): |
112 if not profile: | 112 if not profile: |
113 # FIXME: this method is not handling manual mode correclty anymore | 113 # FIXME: this method is not handling manual mode correclty anymore |
114 # must be thought to be handled asynchronously | 114 # must be thought to be handled asynchronously |
115 self._autoconnect = False # manual mode | 115 self._autoconnect = False # manual mode |
116 msg = _("Trying to plug an unknown profile key ({})".format(profile_key)) | 116 msg = _("Trying to plug an unknown profile key ({})".format(profile_key)) |
117 log.warning(msg) | 117 log.warning(msg) |
118 self.host.showDialog(_("Profile plugging in error"), msg, "error") | 118 self.host.show_dialog(_("Profile plugging in error"), msg, "error") |
119 else: | 119 else: |
120 self.host.launchAction( | 120 self.host.action_launch( |
121 C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=profile | 121 C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=profile |
122 ) | 122 ) |
123 | 123 |
124 def getProfileNameEb(failure): | 124 def get_profile_name_eb(failure): |
125 log.error("Can't retrieve profile name: {}".format(failure)) | 125 log.error("Can't retrieve profile name: {}".format(failure)) |
126 | 126 |
127 for profile_key in profile_keys: | 127 for profile_key in profile_keys: |
128 self.host.bridge.profileNameGet( | 128 self.host.bridge.profile_name_get( |
129 profile_key, callback=getProfileNameCb, errback=getProfileNameEb | 129 profile_key, callback=get_profile_name_cb, errback=get_profile_name_eb |
130 ) | 130 ) |
131 | 131 |
132 def getParamError(self, __): | 132 def get_param_error(self, __): |
133 self.host.showDialog(_("Error"), _("Can't get profile parameter"), "error") | 133 self.host.show_dialog(_("Error"), _("Can't get profile parameter"), "error") |
134 | 134 |
135 ## Helping methods ## | 135 ## Helping methods ## |
136 | 136 |
137 def _getErrorMessage(self, reason): | 137 def _get_error_message(self, reason): |
138 """Return an error message corresponding to profile creation error | 138 """Return an error message corresponding to profile creation error |
139 | 139 |
140 @param reason (str): reason as returned by profileCreate | 140 @param reason (str): reason as returned by profile_create |
141 @return (unicode): human readable error message | 141 @return (unicode): human readable error message |
142 """ | 142 """ |
143 if reason == "ConflictError": | 143 if reason == "ConflictError": |
144 message = _("A profile with this name already exists") | 144 message = _("A profile with this name already exists") |
145 elif reason == "CancelError": | 145 elif reason == "CancelError": |
150 ) # TODO: print a more informative message (empty name, name starting with '@') | 150 ) # TODO: print a more informative message (empty name, name starting with '@') |
151 else: | 151 else: |
152 message = _("Can't create profile ({})").format(reason) | 152 message = _("Can't create profile ({})").format(reason) |
153 return message | 153 return message |
154 | 154 |
155 def _deleteProfile(self): | 155 def _delete_profile(self): |
156 """Delete the currently selected profile""" | 156 """Delete the currently selected profile""" |
157 if self.current.profile: | 157 if self.current.profile: |
158 self.host.bridge.asyncDeleteProfile( | 158 self.host.bridge.profile_delete_async( |
159 self.current.profile, callback=self.refillProfiles | 159 self.current.profile, callback=self.refill_profiles |
160 ) | 160 ) |
161 self.resetFields() | 161 self.reset_fields() |
162 | 162 |
163 ## workflow methods (events occuring during the profiles selection) ## | 163 ## workflow methods (events occuring during the profiles selection) ## |
164 | 164 |
165 # These methods must be called by the frontend at some point | 165 # These methods must be called by the frontend at some point |
166 | 166 |
167 def _onConnectProfiles(self): | 167 def _on_connect_profiles(self): |
168 """Connect the profiles and start the main widget""" | 168 """Connect the profiles and start the main widget""" |
169 if self._autoconnect: | 169 if self._autoconnect: |
170 self.host.showDialog( | 170 self.host.show_dialog( |
171 _("Internal error"), | 171 _("Internal error"), |
172 _("You can't connect manually and automatically at the same time"), | 172 _("You can't connect manually and automatically at the same time"), |
173 "error", | 173 "error", |
174 ) | 174 ) |
175 return | 175 return |
176 self.updateConnectionParams() | 176 self.update_connection_params() |
177 profiles = self.getProfiles() | 177 profiles = self.get_profiles() |
178 if not profiles: | 178 if not profiles: |
179 self.host.showDialog( | 179 self.host.show_dialog( |
180 _("No profile selected"), | 180 _("No profile selected"), |
181 _("You need to create and select at least one profile before connecting"), | 181 _("You need to create and select at least one profile before connecting"), |
182 "error", | 182 "error", |
183 ) | 183 ) |
184 else: | 184 else: |
185 # All profiles in the list are already validated, so we can plug them directly | 185 # All profiles in the list are already validated, so we can plug them directly |
186 self.host.plug_profiles(profiles) | 186 self.host.plug_profiles(profiles) |
187 | 187 |
188 def getConnectionParams(self, profile): | 188 def get_connection_params(self, profile): |
189 """Get login and password and display them | 189 """Get login and password and display them |
190 | 190 |
191 @param profile: %(doc_profile)s | 191 @param profile: %(doc_profile)s |
192 """ | 192 """ |
193 self.host.bridge.asyncGetParamA( | 193 self.host.bridge.param_get_a_async( |
194 "JabberID", | 194 "JabberID", |
195 "Connection", | 195 "Connection", |
196 profile_key=profile, | 196 profile_key=profile, |
197 callback=self.setJID, | 197 callback=self.set_jid, |
198 errback=self.getParamError, | 198 errback=self.get_param_error, |
199 ) | 199 ) |
200 self.host.bridge.asyncGetParamA( | 200 self.host.bridge.param_get_a_async( |
201 "Password", | 201 "Password", |
202 "Connection", | 202 "Connection", |
203 profile_key=profile, | 203 profile_key=profile, |
204 callback=self.setPassword, | 204 callback=self.set_password, |
205 errback=self.getParamError, | 205 errback=self.get_param_error, |
206 ) | 206 ) |
207 | 207 |
208 def updateConnectionParams(self): | 208 def update_connection_params(self): |
209 """Check if connection parameters have changed, and update them if so""" | 209 """Check if connection parameters have changed, and update them if so""" |
210 if self.current.profile: | 210 if self.current.profile: |
211 login = self.getJID() | 211 login = self.get_jid() |
212 password = self.getPassword() | 212 password = self.getPassword() |
213 if login != self.current.login and self.current.login is not None: | 213 if login != self.current.login and self.current.login is not None: |
214 self.current.login = login | 214 self.current.login = login |
215 self.host.bridge.setParam( | 215 self.host.bridge.param_set( |
216 "JabberID", login, "Connection", profile_key=self.current.profile | 216 "JabberID", login, "Connection", profile_key=self.current.profile |
217 ) | 217 ) |
218 log.info("login updated for profile [{}]".format(self.current.profile)) | 218 log.info("login updated for profile [{}]".format(self.current.profile)) |
219 if password != self.current.password and self.current.password is not None: | 219 if password != self.current.password and self.current.password is not None: |
220 self.current.password = password | 220 self.current.password = password |
221 self.host.bridge.setParam( | 221 self.host.bridge.param_set( |
222 "Password", password, "Connection", profile_key=self.current.profile | 222 "Password", password, "Connection", profile_key=self.current.profile |
223 ) | 223 ) |
224 log.info( | 224 log.info( |
225 "password updated for profile [{}]".format(self.current.profile) | 225 "password updated for profile [{}]".format(self.current.profile) |
226 ) | 226 ) |
227 | 227 |
228 ## graphic updates (should probably be overriden in frontends) ## | 228 ## graphic updates (should probably be overriden in frontends) ## |
229 | 229 |
230 def resetFields(self): | 230 def reset_fields(self): |
231 """Set profile to None, and reset fields""" | 231 """Set profile to None, and reset fields""" |
232 self.current.profile = None | 232 self.current.profile = None |
233 self.setJID("") | 233 self.set_jid("") |
234 self.setPassword("") | 234 self.set_password("") |
235 | 235 |
236 def refillProfiles(self): | 236 def refill_profiles(self): |
237 """Rebuild the list of profiles""" | 237 """Rebuild the list of profiles""" |
238 profiles = self.host.bridge.profilesListGet() | 238 profiles = self.host.bridge.profiles_list_get() |
239 profiles.sort() | 239 profiles.sort() |
240 self.setProfiles(profiles) | 240 self.set_profiles(profiles) |
241 | 241 |
242 ## Method which must be implemented by frontends ## | 242 ## Method which must be implemented by frontends ## |
243 | 243 |
244 # get/set data | 244 # get/set data |
245 | 245 |
246 def getProfiles(self): | 246 def get_profiles(self): |
247 """Return list of selected profiles | 247 """Return list of selected profiles |
248 | 248 |
249 Must be implemented by frontends | 249 Must be implemented by frontends |
250 @return (list): list of profiles | 250 @return (list): list of profiles |
251 """ | 251 """ |
252 raise NotImplementedError | 252 raise NotImplementedError |
253 | 253 |
254 def setProfiles(self, profiles): | 254 def set_profiles(self, profiles): |
255 """Update the list of profiles""" | 255 """Update the list of profiles""" |
256 raise NotImplementedError | 256 raise NotImplementedError |
257 | 257 |
258 def getJID(self): | 258 def get_jid(self): |
259 """Get current jid | 259 """Get current jid |
260 | 260 |
261 Must be implemented by frontends | 261 Must be implemented by frontends |
262 @return (unicode): current jabber id | 262 @return (unicode): current jabber id |
263 """ | 263 """ |
269 Must be implemented by frontends | 269 Must be implemented by frontends |
270 @return (unicode): current password | 270 @return (unicode): current password |
271 """ | 271 """ |
272 raise NotImplementedError | 272 raise NotImplementedError |
273 | 273 |
274 def setJID(self, jid_): | 274 def set_jid(self, jid_): |
275 """Set current jid | 275 """Set current jid |
276 | 276 |
277 Must be implemented by frontends | 277 Must be implemented by frontends |
278 @param jid_(unicode): jabber id to set | 278 @param jid_(unicode): jabber id to set |
279 """ | 279 """ |
280 raise NotImplementedError | 280 raise NotImplementedError |
281 | 281 |
282 def setPassword(self, password): | 282 def set_password(self, password): |
283 """Set current password | 283 """Set current password |
284 | 284 |
285 Must be implemented by frontends | 285 Must be implemented by frontends |
286 """ | 286 """ |
287 raise NotImplementedError | 287 raise NotImplementedError |