Add project-tools #142
@ -109,18 +109,23 @@ def compare_checksum(file1, file2):
|
|||||||
return hash1 == hash2
|
return hash1 == hash2
|
||||||
|
|
||||||
|
|
||||||
def update_addons():
|
def update_addon(addon_zip_name, path_in_zip_to_extract=''):
|
||||||
|
addon_zip_sha = addon_zip_name + '.sha256'
|
||||||
|
# This is the file that records all toplevel folders/files installed by this addon
|
||||||
|
# It is used to cleanup old files and folders when updating or removing addons
|
||||||
|
addon_zip_files = addon_zip_name + '.files'
|
||||||
|
|
||||||
# Check if we have the latest add-ons from shared
|
# Check if we have the latest add-ons from shared
|
||||||
studio_pipeline_artifacts = PATH_ARTIFACTS / 'blender-studio-pipeline'
|
addon_artifacts_folder = PATH_ARTIFACTS / 'addons'
|
||||||
artifact_checksum = studio_pipeline_artifacts / 'main.zip.sha256'
|
artifact_archive = addon_artifacts_folder / addon_zip_name
|
||||||
artifact_archive = artifact_checksum.with_suffix('')
|
artifact_checksum = addon_artifacts_folder / addon_zip_sha
|
||||||
|
|
||||||
if not artifact_checksum.exists():
|
if not artifact_checksum.exists():
|
||||||
logger.error("Missing file %s" % artifact_checksum)
|
logger.error("Missing file %s" % artifact_checksum)
|
||||||
logger.error("Could not update add-ons")
|
logger.error("Could not update add-ons")
|
||||||
return
|
return
|
||||||
|
|
||||||
local_checksum = PATH_LOCAL / 'main.zip.sha256'
|
local_checksum = PATH_LOCAL / addon_zip_sha
|
||||||
|
|
||||||
if local_checksum.exists():
|
if local_checksum.exists():
|
||||||
if compare_checksum(local_checksum, artifact_checksum):
|
if compare_checksum(local_checksum, artifact_checksum):
|
||||||
@ -136,20 +141,20 @@ def update_addons():
|
|||||||
tmp_dir = Path(tempfile.mkdtemp())
|
tmp_dir = Path(tempfile.mkdtemp())
|
||||||
|
|
||||||
# Extract the zip file to the temporary directory
|
# Extract the zip file to the temporary directory
|
||||||
with zipfile.ZipFile(studio_pipeline_artifacts / 'main.zip', 'r') as zip_ref:
|
with zipfile.ZipFile(artifact_archive, 'r') as zip_ref:
|
||||||
zip_ref.extractall(tmp_dir)
|
zip_ref.extractall(tmp_dir)
|
||||||
|
|
||||||
# Get the path of the folder to copy
|
# Get the path of the folder to copy
|
||||||
src_path_base = tmp_dir / 'blender-studio-pipeline' / 'scripts-blender' / 'addons'
|
src_path_base = tmp_dir / path_in_zip_to_extract
|
||||||
dst_path_base = PATH_LOCAL / 'scripts' / 'addons'
|
dst_path_base = PATH_LOCAL / 'scripts' / 'addons'
|
||||||
|
|
||||||
# Remove all files previously installed by the archive
|
# Remove all files previously installed by the archive
|
||||||
local_installed_files = PATH_LOCAL / 'main.zip.files'
|
local_installed_files = PATH_LOCAL / addon_zip_files
|
||||||
if local_installed_files.exists():
|
if local_installed_files.exists():
|
||||||
with open(local_installed_files) as file:
|
with open(local_installed_files) as file:
|
||||||
lines = [line.rstrip() for line in file]
|
lines = [line.rstrip() for line in file]
|
||||||
for folder in lines:
|
for folder in lines:
|
||||||
shutil.rmtree(PATH_LOCAL / folder)
|
shutil.rmtree(dst_path_base / folder)
|
||||||
|
|
||||||
# Get a list of directories inside the given directory
|
# Get a list of directories inside the given directory
|
||||||
addons = [subdir.name for subdir in src_path_base.iterdir() if subdir.is_dir()]
|
addons = [subdir.name for subdir in src_path_base.iterdir() if subdir.is_dir()]
|
||||||
@ -177,15 +182,16 @@ def update_blender():
|
|||||||
|
|
||||||
# Check if we have the latest blender archive from shared
|
# Check if we have the latest blender archive from shared
|
||||||
artifacts_path = PATH_ARTIFACTS / 'blender'
|
artifacts_path = PATH_ARTIFACTS / 'blender'
|
||||||
|
archive_name_pattern = "blender*" + system_name + "." + architecture + "*.sha256"
|
||||||
|
|
||||||
# Look for the appropriate Blender archive for this system
|
# Look for the appropriate Blender archive for this system
|
||||||
matched_archives = glob.glob("blender*" + system_name + "." + architecture + "*.sha256")
|
matched_archives = glob.glob(str(artifacts_path / archive_name_pattern))
|
||||||
|
|
||||||
# Check if we found any files
|
# Check if we found any files
|
||||||
if len(matched_archives) != 1:
|
if len(matched_archives) != 1:
|
||||||
if len(matched_archives) == 0:
|
if len(matched_archives) == 0:
|
||||||
logger.error("No Blender archives found for this system!")
|
logger.error("No Blender archives found for this system!")
|
||||||
logger.error("System is: %s %s" % system_name, architecture)
|
logger.error("System is: %s %s" % (system_name, architecture))
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
logger.error(
|
logger.error(
|
||||||
@ -241,10 +247,15 @@ def launch_blender():
|
|||||||
subprocess.run([blender_path])
|
subprocess.run([blender_path])
|
||||||
|
|
||||||
|
|
||||||
|
def update_addons():
|
||||||
|
path_in_zip_to_extract = Path('blender-studio-pipeline/scripts-blender/addons')
|
||||||
|
update_addon('blender-studio-pipeline-main.zip', path_in_zip_to_extract)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
logger.info('Update Add-ons')
|
logger.info('Updating Add-ons')
|
||||||
update_addons()
|
update_addons()
|
||||||
logger.info('Update Blender')
|
logger.info('Updating Blender')
|
||||||
update_blender()
|
update_blender()
|
||||||
logger.info('Launch Blender')
|
logger.info('Launching Blender')
|
||||||
launch_blender()
|
launch_blender()
|
||||||
|
@ -23,7 +23,4 @@ download_addon() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# download_addon <url to addon zip> <output name zip>
|
# download_addon <url to addon zip> <output name zip>
|
||||||
|
|
||||||
# Special download dir for monorepo with addons
|
|
||||||
DOWNLOAD_DIR=../../shared/artifacts/blender-studio-pipeline/
|
|
||||||
download_addon https://projects.blender.org/studio/blender-studio-pipeline/archive/main.zip blender-studio-pipeline-main.zip
|
download_addon https://projects.blender.org/studio/blender-studio-pipeline/archive/main.zip blender-studio-pipeline-main.zip
|
||||||
|
Loading…
Reference in New Issue
Block a user