Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_xep_0264.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 4b842c1fb686 |
children |
comparison
equal
deleted
inserted
replaced
4269:64a85ce8be70 | 4270:0d7bb4df2343 |
---|---|
122 pass | 122 pass |
123 thumbnails.append(thumbnail) | 123 thumbnails.append(thumbnail) |
124 | 124 |
125 if thumbnails: | 125 if thumbnails: |
126 # we want thumbnails ordered from smallest to biggest | 126 # we want thumbnails ordered from smallest to biggest |
127 thumbnails.sort(key=lambda t: t.get('size', (0, 0))) | 127 thumbnails.sort(key=lambda t: t.get("size", (0, 0))) |
128 file_data.setdefault("extra", {})[C.KEY_THUMBNAILS] = thumbnails | 128 file_data.setdefault("extra", {})[C.KEY_THUMBNAILS] = thumbnails |
129 return True | 129 return True |
130 | 130 |
131 ## thumbnails generation ## | 131 ## thumbnails generation ## |
132 | 132 |
139 @return (unicode): unique id for this image/size | 139 @return (unicode): unique id for this image/size |
140 """ | 140 """ |
141 return hashlib.sha256(repr((image_uid, size)).encode()).hexdigest() | 141 return hashlib.sha256(repr((image_uid, size)).encode()).hexdigest() |
142 | 142 |
143 def _blocking_gen_thumb( | 143 def _blocking_gen_thumb( |
144 self, source_path, size=None, max_age=None, image_uid=None, | 144 self, source_path, size=None, max_age=None, image_uid=None, fix_orientation=True |
145 fix_orientation=True): | 145 ): |
146 """Generate a thumbnail for image | 146 """Generate a thumbnail for image |
147 | 147 |
148 This is a blocking method and must be executed in a thread | 148 This is a blocking method and must be executed in a thread |
149 params are the same as for [generate_thumbnail] | 149 params are the same as for [generate_thumbnail] |
150 """ | 150 """ |
169 log.debug(f"fixed orientation for {f.name}") | 169 log.debug(f"fixed orientation for {f.name}") |
170 | 170 |
171 return img.size, uid | 171 return img.size, uid |
172 | 172 |
173 def generate_thumbnail( | 173 def generate_thumbnail( |
174 self, source_path, size=None, max_age=None, image_uid=None, fix_orientation=True): | 174 self, source_path, size=None, max_age=None, image_uid=None, fix_orientation=True |
175 ): | |
175 """Generate a thumbnail of image | 176 """Generate a thumbnail of image |
176 | 177 |
177 @param source_path(unicode): absolute path to source image | 178 @param source_path(unicode): absolute path to source image |
178 @param size(int, None): max size of the thumbnail | 179 @param size(int, None): max size of the thumbnail |
179 can be one of self.SIZE_* | 180 can be one of self.SIZE_* |
186 @return D(tuple[tuple[int,int], unicode]): tuple with: | 187 @return D(tuple[tuple[int,int], unicode]): tuple with: |
187 - size of the thumbnail | 188 - size of the thumbnail |
188 - unique Id of the thumbnail | 189 - unique Id of the thumbnail |
189 """ | 190 """ |
190 d = threads.deferToThread( | 191 d = threads.deferToThread( |
191 self._blocking_gen_thumb, source_path, size, max_age, image_uid=image_uid, | 192 self._blocking_gen_thumb, |
192 fix_orientation=fix_orientation | 193 source_path, |
194 size, | |
195 max_age, | |
196 image_uid=image_uid, | |
197 fix_orientation=fix_orientation, | |
193 ) | 198 ) |
194 d.addErrback( | 199 d.addErrback( |
195 lambda failure_: log.error("thumbnail generation error: {}".format(failure_)) | 200 lambda failure_: log.error("thumbnail generation error: {}".format(failure_)) |
196 ) | 201 ) |
197 return d | 202 return d |