[xml] Improvements.

This commit is contained in:
Jeroen van Rijn
2021-12-05 02:52:23 +01:00
parent 23baf56c87
commit 5807214406
11 changed files with 137 additions and 46 deletions
+35 -8
View File
@@ -50,10 +50,7 @@ def try_download_file(url, out_file):
print("Could not download", url)
return 1
def try_download_and_unpack_zip(suite):
url = ASSETS_BASE_URL.format(suite, "{}.zip".format(suite))
out_file = DOWNLOAD_BASE_PATH.format(suite) + "/{}.zip".format(suite)
def try_download_and_unpack_zip(url, out_file, extract_path):
print("\tDownloading {} to {}.".format(url, out_file))
if try_download_file(url, out_file) is not None:
@@ -65,7 +62,6 @@ def try_download_and_unpack_zip(suite):
with zipfile.ZipFile(out_file) as z:
for file in z.filelist:
filename = file.filename
extract_path = DOWNLOAD_BASE_PATH.format(suite)
print("\t\tExtracting: {}".format(filename))
z.extract(file, extract_path)
@@ -73,25 +69,56 @@ def try_download_and_unpack_zip(suite):
print("Could not extract ZIP file")
return 2
def download_png_assets():
suite = "PNG"
url = ASSETS_BASE_URL.format(suite, "{}.zip".format(suite))
out_file = DOWNLOAD_BASE_PATH.format(suite) + "/{}.zip".format(suite)
extract_path = DOWNLOAD_BASE_PATH.format(suite)
def main():
print("Downloading PNG assets")
# Make PNG assets path
try:
path = DOWNLOAD_BASE_PATH.format("PNG")
path = DOWNLOAD_BASE_PATH.format(suite)
os.makedirs(path)
except FileExistsError:
pass
# Try downloading and unpacking the PNG assets
r = try_download_and_unpack_zip("PNG")
r = try_download_and_unpack_zip(url, out_file, extract_path)
if r is not None:
return r
# We could fall back on downloading the PNG files individually, but it's slow
print("Done downloading PNG assets")
def download_unicode_assets():
suite = "XML"
url = "https://www.w3.org/2003/entities/2007xml/unicode.xml.zip"
out_file = DOWNLOAD_BASE_PATH.format(suite) + "/{}.zip".format(suite)
extract_path = DOWNLOAD_BASE_PATH.format(suite)
print("Downloading {}.".format(url))
# Make XML assets path
try:
path = DOWNLOAD_BASE_PATH.format(suite)
os.makedirs(path)
except FileExistsError:
pass
# Try downloading and unpacking the assets
r = try_download_and_unpack_zip(url, out_file, extract_path)
if r is not None:
return r
print("Done downloading Unicode/XML assets")
def main():
download_png_assets()
download_unicode_assets()
return 0
if __name__ == '__main__':