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

@ -121,7 +121,7 @@ class Logger:
'levelname': level,
}
try:
if not self.filter_name.dictFilter(record):
if not self.filter_name.dict_filter(record):
raise Filtered
except (AttributeError, TypeError): # XXX: TypeError is here because of a pyjamas bug which need to be fixed (TypeError is raised instead of AttributeError)
if self.filter_name is not None:
@ -133,7 +133,7 @@ class Logger:
except KeyError as e:
if e.args[0] == 'profile':
# XXX: %(profile)s use some magic with introspection, for debugging purpose only *DO NOT* use in production
record['profile'] = configure_cls[backend].getProfile()
record['profile'] = configure_cls[backend].get_profile()
return self.fmt % record
else:
raise e
@ -174,7 +174,7 @@ class FilterName(object):
return 1
return 0
def dictFilter(self, dict_record):
def dict_filter(self, dict_record):
"""Filter using a dictionary record
@param dict_record: dictionary with at list a key "name" with logger name
@ -208,26 +208,26 @@ class ConfigureBase:
@param force_colors: if True ANSI colors are used even if stdout is not a tty
"""
self.backend_data = backend_data
self.preTreatment()
self.configureLevel(level)
self.configureFormat(fmt)
self.configureOutput(output)
self.configureLogger(logger)
self.configureColors(colors, force_colors, levels_taints_dict)
self.postTreatment()
self.updateCurrentLogger()
self.pre_treatment()
self.configure_level(level)
self.configure_format(fmt)
self.configure_output(output)
self.configure_logger(logger)
self.configure_colors(colors, force_colors, levels_taints_dict)
self.post_treatment()
self.update_current_logger()
def updateCurrentLogger(self):
def update_current_logger(self):
"""update existing logger to the class needed for this backend"""
if self.LOGGER_CLASS is None:
return
for name, logger in list(_loggers.items()):
_loggers[name] = self.LOGGER_CLASS(logger)
def preTreatment(self):
def pre_treatment(self):
pass
def configureLevel(self, level):
def configure_level(self, level):
if level is not None:
# we deactivate methods below level
level_idx = C.LOG_LEVELS.index(level)
@ -236,7 +236,7 @@ class ConfigureBase:
for _level in C.LOG_LEVELS[:level_idx]:
setattr(Logger, _level.lower(), dev_null)
def configureFormat(self, fmt):
def configure_format(self, fmt):
if fmt is not None:
if fmt != '%(message)s': # %(message)s is the same as None
Logger.fmt = fmt
@ -246,17 +246,17 @@ class ConfigureBase:
# color_start not followed by an end, we add it
Logger.fmt += COLOR_END
def configureOutput(self, output):
def configure_output(self, output):
if output is not None:
if output != C.LOG_OPT_OUTPUT_SEP + C.LOG_OPT_OUTPUT_DEFAULT:
# TODO: manage other outputs
raise NotImplementedError("Basic backend only manage default output yet")
def configureLogger(self, logger):
def configure_logger(self, logger):
if logger:
Logger.filter_name = FilterName(logger)
def configureColors(self, colors, force_colors, levels_taints_dict):
def configure_colors(self, colors, force_colors, levels_taints_dict):
if colors:
# if color are used, we need to handle levels_taints_dict
for level in list(levels_taints_dict.keys()):
@ -280,10 +280,10 @@ class ConfigureBase:
ansi_list.append(ansi)
taints[level] = ''.join(ansi_list)
def postTreatment(self):
def post_treatment(self):
pass
def manageOutputs(self, outputs_raw):
def manage_outputs(self, outputs_raw):
""" Parse output option in a backend agnostic way, and fill handlers consequently
@param outputs_raw: output option as enterred in environment variable or in configuration
@ -330,7 +330,7 @@ class ConfigureBase:
raise ValueError("options [{options}] are not supported for {handler} output".format(options=options, handler=output))
@staticmethod
def memoryGet(size=None):
def memory_get(size=None):
"""Return buffered logs
@param size: number of logs to return
@ -338,7 +338,7 @@ class ConfigureBase:
raise NotImplementedError
@classmethod
def ansiColors(cls, level, message):
def ansi_colors(cls, level, message):
"""Colorise message depending on level for terminals
@param level: one of C.LOG_LEVELS
@ -358,7 +358,7 @@ class ConfigureBase:
return '%s%s%s' % (start, message, A.RESET)
@staticmethod
def getProfile():
def get_profile():
"""Try to find profile value using introspection"""
raise NotImplementedError
@ -396,10 +396,10 @@ def configure(backend_, **options):
else:
configure_class(**options)
def memoryGet(size=None):
def memory_get(size=None):
if not C.LOG_OPT_OUTPUT_MEMORY in handlers:
raise ValueError('memory output is not used')
return configure_cls[backend].memoryGet(size)
return configure_cls[backend].memory_get(size)
def getLogger(name=C.LOG_BASE_LOGGER) -> Logger:
try: