Font download: destination dir is allowed to exist

Without this argument, an existing directory (but not the file) causes an error.
This commit is contained in:
Bart Schuurmans 2024-03-18 20:23:26 +01:00
parent 748418590f
commit 3367b20965

View file

@ -1,4 +1,5 @@
"""Do further startup configuration and initialization"""
import os
import urllib
import logging
@ -14,7 +15,7 @@ def download_file(url, destination):
"""Downloads a file to the given path"""
try:
# 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 open(destination, "b+w") as outfile:
outfile.write(stream.read())