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""" """Do further startup configuration and initialization"""
import os import os
import urllib import urllib
import logging import logging
@ -14,7 +15,7 @@ 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())