Mercurial > libervia-backend
diff sat_frontends/quick_frontend/quick_profile_manager.py @ 2624:56f94936df1e
code style reformatting using black
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 27 Jun 2018 20:14:46 +0200 |
parents | 26edcf3a30eb |
children | 378188abe941 |
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_profile_manager.py Wed Jun 27 07:51:29 2018 +0200 +++ b/sat_frontends/quick_frontend/quick_profile_manager.py Wed Jun 27 20:14:46 2018 +0200 @@ -19,6 +19,7 @@ from sat.core.i18n import _ from sat.core import log as logging + log = logging.getLogger(__name__) from sat_frontends.primitivus.constants import Const as C @@ -85,10 +86,9 @@ log.warning("No profile given to autoconnect") return self._autoconnect = True - self._autoconnect_profiles=[] + self._autoconnect_profiles = [] self._do_autoconnect(profile_keys) - def _do_autoconnect(self, profile_keys): """Connect automatically given profiles @@ -98,36 +98,39 @@ def authenticate_cb(data, cb_id, profile): - if C.bool(data.pop('validated', C.BOOL_FALSE)): + if C.bool(data.pop("validated", C.BOOL_FALSE)): self._autoconnect_profiles.append(profile) if len(self._autoconnect_profiles) == len(profile_keys): # all the profiles have been validated self.host.plug_profiles(self._autoconnect_profiles) else: # a profile is not validated, we go to manual mode - self._autoconnect=False + self._autoconnect = False self.host.actionManager(data, callback=authenticate_cb, profile=profile) def getProfileNameCb(profile): if not profile: # FIXME: this method is not handling manual mode correclty anymore # must be thought to be handled asynchronously - self._autoconnect = False # manual mode + self._autoconnect = False # manual mode msg = _("Trying to plug an unknown profile key ({})".format(profile_key)) log.warning(msg) - self.host.showDialog(_("Profile plugging in error"), msg, 'error') + self.host.showDialog(_("Profile plugging in error"), msg, "error") else: - self.host.launchAction(C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=profile) + self.host.launchAction( + C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=profile + ) def getProfileNameEb(failure): log.error(u"Can't retrieve profile name: {}".format(failure)) for profile_key in profile_keys: - self.host.bridge.profileNameGet(profile_key, callback=getProfileNameCb, errback=getProfileNameEb) - + self.host.bridge.profileNameGet( + profile_key, callback=getProfileNameCb, errback=getProfileNameEb + ) def getParamError(self, dummy): - self.host.showDialog(_(u"Error"), _("Can't get profile parameter"), 'error') + self.host.showDialog(_(u"Error"), _("Can't get profile parameter"), "error") ## Helping methods ## @@ -142,7 +145,9 @@ elif reason == "CancelError": message = _("Profile creation cancelled by backend") elif reason == "ValueError": - message = _("You profile name is not valid") # TODO: print a more informative message (empty name, name starting with '@') + message = _( + "You profile name is not valid" + ) # TODO: print a more informative message (empty name, name starting with '@') else: message = _("Can't create profile ({})").format(reason) return message @@ -150,7 +155,9 @@ def _deleteProfile(self): """Delete the currently selected profile""" if self.current.profile: - self.host.bridge.asyncDeleteProfile(self.current.profile, callback=self.refillProfiles) + self.host.bridge.asyncDeleteProfile( + self.current.profile, callback=self.refillProfiles + ) self.resetFields() ## workflow methods (events occuring during the profiles selection) ## @@ -160,12 +167,20 @@ def _onConnectProfiles(self): """Connect the profiles and start the main widget""" if self._autoconnect: - self.host.showDialog(_('Internal error'), _("You can't connect manually and automatically at the same time"), 'error') + self.host.showDialog( + _("Internal error"), + _("You can't connect manually and automatically at the same time"), + "error", + ) return self.updateConnectionParams() profiles = self.getProfiles() if not profiles: - self.host.showDialog(_('No profile selected'), _('You need to create and select at least one profile before connecting'), 'error') + self.host.showDialog( + _("No profile selected"), + _("You need to create and select at least one profile before connecting"), + "error", + ) else: # All profiles in the list are already validated, so we can plug them directly self.host.plug_profiles(profiles) @@ -175,8 +190,20 @@ @param profile: %(doc_profile)s """ - self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=profile, callback=self.setJID, errback=self.getParamError) - self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=profile, callback=self.setPassword, errback=self.getParamError) + self.host.bridge.asyncGetParamA( + "JabberID", + "Connection", + profile_key=profile, + callback=self.setJID, + errback=self.getParamError, + ) + self.host.bridge.asyncGetParamA( + "Password", + "Connection", + profile_key=profile, + callback=self.setPassword, + errback=self.getParamError, + ) def updateConnectionParams(self): """Check if connection parameters have changed, and update them if so""" @@ -185,18 +212,24 @@ password = self.getPassword() if login != self.current.login and self.current.login is not None: self.current.login = login - self.host.bridge.setParam("JabberID", login, "Connection", profile_key=self.current.profile) + self.host.bridge.setParam( + "JabberID", login, "Connection", profile_key=self.current.profile + ) log.info(u"login updated for profile [{}]".format(self.current.profile)) if password != self.current.password and self.current.password is not None: self.current.password = password - self.host.bridge.setParam("Password", password, "Connection", profile_key=self.current.profile) - log.info(u"password updated for profile [{}]".format(self.current.profile)) + self.host.bridge.setParam( + "Password", password, "Connection", profile_key=self.current.profile + ) + log.info( + u"password updated for profile [{}]".format(self.current.profile) + ) ## graphic updates (should probably be overriden in frontends) ## def resetFields(self): """Set profile to None, and reset fields""" - self.current.profile=None + self.current.profile = None self.setJID("") self.setPassword("") @@ -222,7 +255,6 @@ """Update the list of profiles""" raise NotImplementedError - def getJID(self): """Get current jid