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.
This commit is contained in:
Goffi 2023-04-08 13:54:42 +02:00
commit 6a6f15707a

View file

@ -106,38 +106,38 @@ class QuickProfileManager(object):
else:
# a profile is not validated, we go to manual mode
self._autoconnect = False
self.host.actionManager(data, callback=authenticate_cb, profile=profile)
self.host.action_manager(data, callback=authenticate_cb, profile=profile)
def getProfileNameCb(profile):
def get_profile_name_cb(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
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.show_dialog(_("Profile plugging in error"), msg, "error")
else:
self.host.launchAction(
self.host.action_launch(
C.AUTHENTICATE_PROFILE_ID, callback=authenticate_cb, profile=profile
)
def getProfileNameEb(failure):
def get_profile_name_eb(failure):
log.error("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.profile_name_get(
profile_key, callback=get_profile_name_cb, errback=get_profile_name_eb
)
def getParamError(self, __):
self.host.showDialog(_("Error"), _("Can't get profile parameter"), "error")
def get_param_error(self, __):
self.host.show_dialog(_("Error"), _("Can't get profile parameter"), "error")
## Helping methods ##
def _getErrorMessage(self, reason):
def _get_error_message(self, reason):
"""Return an error message corresponding to profile creation error
@param reason (str): reason as returned by profileCreate
@param reason (str): reason as returned by profile_create
@return (unicode): human readable error message
"""
if reason == "ConflictError":
@ -152,31 +152,31 @@ class QuickProfileManager(object):
message = _("Can't create profile ({})").format(reason)
return message
def _deleteProfile(self):
def _delete_profile(self):
"""Delete the currently selected profile"""
if self.current.profile:
self.host.bridge.asyncDeleteProfile(
self.current.profile, callback=self.refillProfiles
self.host.bridge.profile_delete_async(
self.current.profile, callback=self.refill_profiles
)
self.resetFields()
self.reset_fields()
## workflow methods (events occuring during the profiles selection) ##
# These methods must be called by the frontend at some point
def _onConnectProfiles(self):
def _on_connect_profiles(self):
"""Connect the profiles and start the main widget"""
if self._autoconnect:
self.host.showDialog(
self.host.show_dialog(
_("Internal error"),
_("You can't connect manually and automatically at the same time"),
"error",
)
return
self.updateConnectionParams()
profiles = self.getProfiles()
self.update_connection_params()
profiles = self.get_profiles()
if not profiles:
self.host.showDialog(
self.host.show_dialog(
_("No profile selected"),
_("You need to create and select at least one profile before connecting"),
"error",
@ -185,40 +185,40 @@ class QuickProfileManager(object):
# All profiles in the list are already validated, so we can plug them directly
self.host.plug_profiles(profiles)
def getConnectionParams(self, profile):
def get_connection_params(self, profile):
"""Get login and password and display them
@param profile: %(doc_profile)s
"""
self.host.bridge.asyncGetParamA(
self.host.bridge.param_get_a_async(
"JabberID",
"Connection",
profile_key=profile,
callback=self.setJID,
errback=self.getParamError,
callback=self.set_jid,
errback=self.get_param_error,
)
self.host.bridge.asyncGetParamA(
self.host.bridge.param_get_a_async(
"Password",
"Connection",
profile_key=profile,
callback=self.setPassword,
errback=self.getParamError,
callback=self.set_password,
errback=self.get_param_error,
)
def updateConnectionParams(self):
def update_connection_params(self):
"""Check if connection parameters have changed, and update them if so"""
if self.current.profile:
login = self.getJID()
login = self.get_jid()
password = self.getPassword()
if login != self.current.login and self.current.login is not None:
self.current.login = login
self.host.bridge.setParam(
self.host.bridge.param_set(
"JabberID", login, "Connection", profile_key=self.current.profile
)
log.info("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(
self.host.bridge.param_set(
"Password", password, "Connection", profile_key=self.current.profile
)
log.info(
@ -227,23 +227,23 @@ class QuickProfileManager(object):
## graphic updates (should probably be overriden in frontends) ##
def resetFields(self):
def reset_fields(self):
"""Set profile to None, and reset fields"""
self.current.profile = None
self.setJID("")
self.setPassword("")
self.set_jid("")
self.set_password("")
def refillProfiles(self):
def refill_profiles(self):
"""Rebuild the list of profiles"""
profiles = self.host.bridge.profilesListGet()
profiles = self.host.bridge.profiles_list_get()
profiles.sort()
self.setProfiles(profiles)
self.set_profiles(profiles)
## Method which must be implemented by frontends ##
# get/set data
def getProfiles(self):
def get_profiles(self):
"""Return list of selected profiles
Must be implemented by frontends
@ -251,11 +251,11 @@ class QuickProfileManager(object):
"""
raise NotImplementedError
def setProfiles(self, profiles):
def set_profiles(self, profiles):
"""Update the list of profiles"""
raise NotImplementedError
def getJID(self):
def get_jid(self):
"""Get current jid
Must be implemented by frontends
@ -271,7 +271,7 @@ class QuickProfileManager(object):
"""
raise NotImplementedError
def setJID(self, jid_):
def set_jid(self, jid_):
"""Set current jid
Must be implemented by frontends
@ -279,7 +279,7 @@ class QuickProfileManager(object):
"""
raise NotImplementedError
def setPassword(self, password):
def set_password(self, password):
"""Set current password
Must be implemented by frontends