TEMP: Add script to download 3.6.8 #285

Closed
Nick Alberelli wants to merge 2 commits from TinyNick/blender-studio-pipeline:feature/download-3-6-8-script into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.

View File

@ -0,0 +1,107 @@
#!/usr/bin/env python3
import email.utils
import glob
import hashlib
import os
import pathlib
import requests
import shutil
import json
def download_file(url, out_folder):
print("Downloading: " + url)
local_filename = out_folder / url.split('/')[-1]
# NOTE the stream=True parameter below
with requests.get(url, stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=None):
if chunk:
f.write(chunk)
return local_filename
def shasum_matches(file, sha_sum):
with open(file, "rb") as f:
digest = hashlib.file_digest(f, "sha256")
return digest.hexdigest() == sha_sum
current_file_folder_path = pathlib.Path(__file__).parent
download_folder_path = (
current_file_folder_path / "../../shared/artifacts/blender"
).resolve()
os.makedirs(download_folder_path, exist_ok=True)
# Get all urls for the blender builds
backup_folder_path = download_folder_path / "previous/current_snapshot"
# This can happen if someone has run the rollback script, so we need to check for it.
backup_exists = (download_folder_path / "previous/00").exists()
os.makedirs(download_folder_path, exist_ok=True)
if not backup_exists:
# Backup the old files
os.makedirs(backup_folder_path, exist_ok=True)
for f in os.listdir(download_folder_path):
path_to_file = download_folder_path / f
if path_to_file.is_file():
shutil.copy(path_to_file, backup_folder_path)
updated_current_files = False
for file in download_folder_path.iterdir():
if file.is_file():
os.remove(file)
updated_current_files = True
files_to_download = [
"https://builder.blender.org/download/daily/archive/blender-3.6.8-stable+v36.c331462fc870-darwin.arm64-release.dmg",
"https://builder.blender.org/download/daily/archive/blender-3.6.8-stable+v36.c331462fc870-darwin.arm64-release.dmg.sha256",
"https://builder.blender.org/download/daily/archive/blender-3.6.8-stable+v36.c331462fc870-darwin.x86_64-release.dmg",
"https://builder.blender.org/download/daily/archive/blender-3.6.8-stable+v36.c331462fc870-darwin.x86_64-release.dmg.sha256",
"https://builder.blender.org/download/daily/archive/blender-3.6.8-stable+v36.c331462fc870-linux.x86_64-release.tar.xz",
"https://builder.blender.org/download/daily/archive/blender-3.6.8-stable+v36.c331462fc870-linux.x86_64-release.tar.xz.sha256",
"https://builder.blender.org/download/daily/archive/blender-3.6.8-stable+v36.c331462fc870-windows.amd64-release.zip",
"https://builder.blender.org/download/daily/archive/blender-3.6.8-stable+v36.c331462fc870-windows.amd64-release.zip.sha256",
]
for link in files_to_download:
download_file(url=link, out_folder=download_folder_path)
# Save download date for use in the rollback script
with open(download_folder_path / "download_date", "w") as date_file:
date_file.write(email.utils.formatdate(localtime=True))
print("Updated to the latest files")
if updated_current_files:
backup_path = download_folder_path / "previous"
if not backup_exists:
# Put the current backup first in the directory listing
os.rename(backup_folder_path, backup_path / "00")
backup_dirs = os.listdir(backup_path)
backup_dirs.sort(reverse=True)
# Remove older backup folders if there are more than 10
folders_to_remove = len(backup_dirs) - 10
if folders_to_remove > 0:
for dir in backup_dirs[:folders_to_remove]:
shutil.rmtree(backup_path / dir)
backup_dirs = backup_dirs[folders_to_remove:]
# Bump all folder names
# Assign a number to each file, reverse the processing order to not overwrite any files.
folder_number = len(backup_dirs)
for dir in backup_dirs:
old_dir = backup_path / dir
os.rename(old_dir, backup_path / str(folder_number).zfill(2))
folder_number -= 1
else:
if not backup_exists:
shutil.rmtree(backup_folder_path)