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

@ -81,15 +81,15 @@ class XEP_0264(object):
def __init__(self, host):
log.info(_("Plugin XEP_0264 initialization"))
self.host = host
host.trigger.add("XEP-0234_buildFileElement", self._addFileThumbnails)
host.trigger.add("XEP-0234_parseFileElement", self._getFileThumbnails)
host.trigger.add("XEP-0234_buildFileElement", self._add_file_thumbnails)
host.trigger.add("XEP-0234_parseFileElement", self._get_file_thumbnails)
def getHandler(self, client):
def get_handler(self, client):
return XEP_0264_handler()
## triggers ##
def _addFileThumbnails(self, client, file_elt, extra_args):
def _add_file_thumbnails(self, client, file_elt, extra_args):
try:
thumbnails = extra_args["extra"][C.KEY_THUMBNAILS]
except KeyError:
@ -103,7 +103,7 @@ class XEP_0264(object):
thumbnail_elt["height"] = str(height)
return True
def _getFileThumbnails(self, client, file_elt, file_data):
def _get_file_thumbnails(self, client, file_elt, file_data):
thumbnails = []
for thumbnail_elt in file_elt.elements(NS_THUMBS, "thumbnail"):
uri = thumbnail_elt["uri"]
@ -130,7 +130,7 @@ class XEP_0264(object):
## thumbnails generation ##
def getThumbId(self, image_uid, size):
def get_thumb_id(self, image_uid, size):
"""return an ID unique for image/size combination
@param image_uid(unicode): unique id of the image
@ -140,13 +140,13 @@ class XEP_0264(object):
"""
return hashlib.sha256(repr((image_uid, size)).encode()).hexdigest()
def _blockingGenThumb(
def _blocking_gen_thumb(
self, source_path, size=None, max_age=None, image_uid=None,
fix_orientation=True):
"""Generate a thumbnail for image
This is a blocking method and must be executed in a thread
params are the same as for [generateThumbnail]
params are the same as for [generate_thumbnail]
"""
if size is None:
size = self.SIZE_SMALL
@ -159,9 +159,9 @@ class XEP_0264(object):
if fix_orientation:
img = ImageOps.exif_transpose(img)
uid = self.getThumbId(image_uid or source_path, size)
uid = self.get_thumb_id(image_uid or source_path, size)
with self.host.common_cache.cacheData(
with self.host.common_cache.cache_data(
PLUGIN_INFO[C.PI_IMPORT_NAME], uid, MIME_TYPE, max_age
) as f:
img.save(f, SAVE_FORMAT)
@ -170,7 +170,7 @@ class XEP_0264(object):
return img.size, uid
def generateThumbnail(
def generate_thumbnail(
self, source_path, size=None, max_age=None, image_uid=None, fix_orientation=True):
"""Generate a thumbnail of image
@ -178,7 +178,7 @@ class XEP_0264(object):
@param size(int, None): max size of the thumbnail
can be one of self.SIZE_*
None to use default value (i.e. self.SIZE_SMALL)
@param max_age(int, None): same as for [memory.cache.Cache.cacheData])
@param max_age(int, None): same as for [memory.cache.Cache.cache_data])
@param image_uid(unicode, None): unique ID to identify the image
use hash whenever possible
if None, source_path will be used
@ -188,7 +188,7 @@ class XEP_0264(object):
- unique Id of the thumbnail
"""
d = threads.deferToThread(
self._blockingGenThumb, source_path, size, max_age, image_uid=image_uid,
self._blocking_gen_thumb, source_path, size, max_age, image_uid=image_uid,
fix_orientation=fix_orientation
)
d.addErrback(