-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to fetch resources from Azure
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Python script that fetches a canonical set of T-Res resources | ||
# from an Azure storage container. | ||
|
||
import os | ||
import sys | ||
import zipfile | ||
from pathlib import Path | ||
|
||
# Check azcopy is available. | ||
azcopy_check = os.system("azcopy --version") | ||
if azcopy_check != 0: | ||
sys.exit("Please install AzCopy.") | ||
print("This script will download and unzip an archive containing T-Res resources.\n") | ||
print("The archive is large (>8GB) and therefore this process may take some time.\n\n") | ||
sas_token = input("Please enter a SAS token to access the T-Res resources container:\n") | ||
|
||
# Download the zip archive. | ||
local_path = Path(os.path.dirname(os.path.abspath(__file__))) | ||
remote = f'"https://tres.blob.core.windows.net/resources/resources.zip?{sas_token}"' | ||
azcopy_command = f"azcopy copy {remote} {local_path}" | ||
print(azcopy_command) | ||
os.system(azcopy_command) | ||
|
||
resources_zip = Path(local_path, "resources.zip") | ||
if not resources_zip.is_file(): | ||
sys.exit("Failed to download resources archive.") | ||
|
||
# Unzip the archive. | ||
print("Unzipping (please be patient...)") | ||
with zipfile.ZipFile(resources_zip, 'r') as zip_ref: | ||
zip_ref.extractall(local_path) | ||
|
||
# Clean up. | ||
Path.unlink(resources_zip) |