Add project-tools #142
61
scripts/project-helper-tools/update_blender.py
Normal file
61
scripts/project-helper-tools/update_blender.py
Normal file
@ -0,0 +1,61 @@
|
||||
import pathlib
|
||||
import os
|
||||
import requests
|
||||
import re
|
||||
import shutil
|
||||
import hashlib
|
||||
|
||||
HOMEPAGE = "https://builder.blender.org/download/"
|
||||
|
||||
BLENDER_BRANCH = "main"
|
||||
DOWNLOAD_DIR = "../../shared/artifacts/blender"
|
||||
|
||||
current_file_folder_path = pathlib.Path(__file__).parent
|
||||
download_folder_path = (current_file_folder_path / DOWNLOAD_DIR).resolve()
|
||||
backup_folder_path = download_folder_path / "previous/current_snapshot"
|
||||
|
||||
os.makedirs(download_folder_path, exist_ok=True)
|
||||
|
||||
# Backup the old files
|
||||
os.makedirs(backup_folder_path, exist_ok=True)
|
||||
|
||||
for f in os.listdir(download_folder_path):
|
||||
if os.path.isfile(f):
|
||||
path_to_file = f / download_folder_path
|
||||
shutil.copy(path_to_file, backup_folder_path)
|
||||
|
||||
# Get all urls for the blender builds
|
||||
platforms_to_download = {
|
||||
"windows": "zip",
|
||||
"darwin.x86_64": "dmg",
|
||||
"darwin.arm64": "dmg",
|
||||
"linux": "tar.xz",
|
||||
}
|
||||
|
||||
files_to_download = []
|
||||
branch_string = "+" + BLENDER_BRANCH
|
||||
reqs = requests.get(HOMEPAGE)
|
||||
for match in re.findall('<a href=[' "'" '"][^"' "'" ']*[' "'" '"]', reqs.text):
|
||||
if branch_string in match:
|
||||
# Strip href and quotes around the url
|
||||
download_url = match[9:-1]
|
||||
for platform in platforms_to_download:
|
||||
file_extension = platforms_to_download[platform]
|
||||
if re.search(platform + ".*" + file_extension + "$", download_url):
|
||||
files_to_download.append(download_url)
|
||||
|
||||
# Download new builds if the shasums doesn't match
|
||||
for url in files_to_download:
|
||||
url_sha = url + ".sha256"
|
||||
sha = requests.get(url_sha).text
|
||||
|
||||
current_file = download_folder_path / url.split("/")[-1]
|
||||
if os.path.exists(current_file):
|
||||
with open(current_file, "rb") as f:
|
||||
digest = hashlib.file_digest(f, "sha256")
|
||||
if digest.hexdigest() == sha:
|
||||
# We already have the current file
|
||||
continue
|
||||
|
||||
downloaded_file = wget.download(url, out=download_folder_path)
|
||||
|
Loading…
Reference in New Issue
Block a user