mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-30 05:21:08 +00:00
Merge pull request #3057 from hughrun/user-migrate
once more into the linting breach!
This commit is contained in:
commit
d05cf8e59b
3 changed files with 7 additions and 5 deletions
|
@ -94,7 +94,8 @@ def json_export(user): # pylint: disable=too-many-locals, too-many-statements
|
||||||
# reading goals
|
# reading goals
|
||||||
reading_goals = models.AnnualGoal.objects.filter(user=user).distinct()
|
reading_goals = models.AnnualGoal.objects.filter(user=user).distinct()
|
||||||
goals_list = []
|
goals_list = []
|
||||||
# TODO: either error checking should be more sophisticated or maybe we don't need this try/except
|
# TODO: either error checking should be more sophisticated
|
||||||
|
# or maybe we don't need this try/except
|
||||||
try:
|
try:
|
||||||
for goal in reading_goals:
|
for goal in reading_goals:
|
||||||
goals_list.append(
|
goals_list.append(
|
||||||
|
|
|
@ -10,6 +10,7 @@ def read_tar():
|
||||||
yield tar
|
yield tar
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
def write_tar():
|
def write_tar():
|
||||||
archive_path = "/tmp/test.tar.gz"
|
archive_path = "/tmp/test.tar.gz"
|
||||||
with open(archive_path, "wb") as archive_file:
|
with open(archive_path, "wb") as archive_file:
|
||||||
|
|
|
@ -8,14 +8,14 @@ from django.core.files import File
|
||||||
class BookwyrmTarFile(tarfile.TarFile):
|
class BookwyrmTarFile(tarfile.TarFile):
|
||||||
"""Create tar files for user exports"""
|
"""Create tar files for user exports"""
|
||||||
|
|
||||||
def write_bytes(self, data: bytes):
|
def write_bytes(self, data: bytes) -> None:
|
||||||
"""Add a file containing bytes to the archive"""
|
"""Add a file containing bytes to the archive"""
|
||||||
buffer = io.BytesIO(data)
|
buffer = io.BytesIO(data)
|
||||||
info = tarfile.TarInfo("archive.json")
|
info = tarfile.TarInfo("archive.json")
|
||||||
info.size = len(data)
|
info.size = len(data)
|
||||||
self.addfile(info, fileobj=buffer)
|
self.addfile(info, fileobj=buffer)
|
||||||
|
|
||||||
def add_image(self, image, filename=None, directory=""):
|
def add_image(self, image: Any, filename: str = None, directory: Any = "") -> None:
|
||||||
"""
|
"""
|
||||||
Add an image to the tar archive
|
Add an image to the tar archive
|
||||||
:param str filename: overrides the file name set by image
|
:param str filename: overrides the file name set by image
|
||||||
|
@ -32,12 +32,12 @@ class BookwyrmTarFile(tarfile.TarFile):
|
||||||
|
|
||||||
self.addfile(info, fileobj=image)
|
self.addfile(info, fileobj=image)
|
||||||
|
|
||||||
def read(self, filename):
|
def read(self, filename: str) -> Any:
|
||||||
"""read data from the tar"""
|
"""read data from the tar"""
|
||||||
with self.extractfile(filename) as reader:
|
with self.extractfile(filename) as reader:
|
||||||
return reader.read()
|
return reader.read()
|
||||||
|
|
||||||
def write_image_to_file(self, filename, file_field):
|
def write_image_to_file(self, filename: str, file_field: Any) -> None:
|
||||||
"""add an image to the tar"""
|
"""add an image to the tar"""
|
||||||
extension = filename.rsplit(".")[-1]
|
extension = filename.rsplit(".")[-1]
|
||||||
with self.extractfile(filename) as reader:
|
with self.extractfile(filename) as reader:
|
||||||
|
|
Loading…
Reference in a new issue