Merge pull request #3322 from Minnozz/fix-font-download

Fix font download
This commit is contained in:
Mouse Reeve 2024-03-23 07:36:43 -07:00 committed by GitHub
commit 20db968315
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 7 deletions

View file

@ -1,4 +1,5 @@
"""Do further startup configuration and initialization""" """Do further startup configuration and initialization"""
import os import os
import urllib import urllib
import logging import logging
@ -14,16 +15,16 @@ def download_file(url, destination):
"""Downloads a file to the given path""" """Downloads a file to the given path"""
try: try:
# Ensure our destination directory exists # Ensure our destination directory exists
os.makedirs(os.path.dirname(destination)) os.makedirs(os.path.dirname(destination), exist_ok=True)
with urllib.request.urlopen(url) as stream: with urllib.request.urlopen(url) as stream:
with open(destination, "b+w") as outfile: with open(destination, "b+w") as outfile:
outfile.write(stream.read()) outfile.write(stream.read())
except (urllib.error.HTTPError, urllib.error.URLError): except (urllib.error.HTTPError, urllib.error.URLError) as err:
logger.info("Failed to download file %s", url) logger.error("Failed to download file %s: %s", url, err)
except OSError: except OSError as err:
logger.info("Couldn't open font file %s for writing", destination) logger.error("Couldn't open font file %s for writing: %s", destination, err)
except: # pylint: disable=bare-except except Exception as err: # pylint:disable=broad-except
logger.info("Unknown error in file download") logger.error("Unknown error in file download: %s", err)
class BookwyrmConfig(AppConfig): class BookwyrmConfig(AppConfig):

View file

@ -91,6 +91,7 @@ services:
env_file: .env env_file: .env
volumes: volumes:
- .:/app - .:/app
- static_volume:/app/static
networks: networks:
- main - main
depends_on: depends_on: