From ddec2dbaa98b6f3a9a8fedeacefeb40508aa5ab2 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 23 Oct 2023 20:43:49 +1100 Subject: [PATCH] fix tar types notification docstring --- bookwyrm/models/notification.py | 2 +- bookwyrm/utils/tar.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bookwyrm/models/notification.py b/bookwyrm/models/notification.py index 98d20a3cb..d62043845 100644 --- a/bookwyrm/models/notification.py +++ b/bookwyrm/models/notification.py @@ -255,7 +255,7 @@ def notify_user_on_user_import_complete( def notify_user_on_user_export_complete( sender, instance, *args, update_fields=None, **kwargs ): - """we imported your user details! aren't you proud of us""" + """we exported your user details! aren't you proud of us""" update_fields = update_fields or [] if not instance.complete or "complete" not in update_fields: print("RETURNING", instance.status) diff --git a/bookwyrm/utils/tar.py b/bookwyrm/utils/tar.py index 6aec88b42..044a47404 100644 --- a/bookwyrm/utils/tar.py +++ b/bookwyrm/utils/tar.py @@ -1,7 +1,7 @@ """manage tar files for user exports""" import io import tarfile -from typing import Any +from typing import Any, Optional from uuid import uuid4 from django.core.files import File @@ -16,7 +16,9 @@ class BookwyrmTarFile(tarfile.TarFile): info.size = len(data) self.addfile(info, fileobj=buffer) - def add_image(self, image: Any, filename: str = None, directory: Any = "") -> None: + def add_image( + self, image: Any, filename: Optional[str] = None, directory: Any = "" + ) -> None: """ Add an image to the tar archive :param str filename: overrides the file name set by image @@ -35,12 +37,12 @@ class BookwyrmTarFile(tarfile.TarFile): def read(self, filename: str) -> Any: """read data from the tar""" - with self.extractfile(filename) as reader: + if reader := self.extractfile(filename): return reader.read() def write_image_to_file(self, filename: str, file_field: Any) -> None: """add an image to the tar""" extension = filename.rsplit(".")[-1] - with self.extractfile(filename) as reader: + if buf := self.extractfile(filename): filename = f"{str(uuid4())}.{extension}" - file_field.save(filename, File(reader)) + file_field.save(filename, File(buf))