Skip to content

Commit

Permalink
Fix some miner issues with the stable cache builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor-IX committed Jan 15, 2025
1 parent 94f3f01 commit 8d96817
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
52 changes: 32 additions & 20 deletions scripts/update_cache_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
import json
import subprocess

if sys.platform == "win32":
source_dir = os.path.join(os.getenv("LOCALAPPDATA"), "Blender Launcher")
Expand All @@ -22,25 +23,36 @@
destination_file_path = os.path.join(destination_dir, destination_file)

if os.path.exists(source_file_path):
with open(source_file_path, "r") as src_file:
source_data = json.load(src_file)

if os.path.exists(destination_file_path):
with open(destination_file_path, "r") as dest_file:
destination_data = json.load(dest_file)

version = destination_data.get("api_file_version", "1.0")
major_version = int(version.split(".")[0]) + 1
destination_data["api_file_version"] = f"{major_version}.0"

destination_data.update(source_data)
else:
destination_data = source_data
destination_data["api_file_version"] = "1.0"

with open(destination_file_path, "w") as dest_file:
json.dump(destination_data, dest_file, indent=4)

print(f"Updated {source_file_path} in {destination_dir}")
try:
with open(source_file_path, "r") as src_file:
source_data = json.load(src_file)

if os.path.exists(destination_file_path):
with open(destination_file_path, "r") as dest_file:
destination_data = json.load(dest_file)

version = destination_data.get("api_file_version", "1.0")
major_version = int(version.split(".")[0]) + 1
destination_data["api_file_version"] = f"{major_version}.0"

destination_data.update(source_data)
else:
destination_data = source_data
destination_data["api_file_version"] = "1.0"

with open(destination_file_path, "w") as dest_file:
json.dump(destination_data, dest_file, indent=4)

# Use git to check if the file has been modified (not only the file verison)
result = subprocess.run(["git", "diff", "--numstat", destination_file_path], capture_output=True, text=True)
modified_lines = sum(int(line.split()[0]) for line in result.stdout.splitlines())

if modified_lines <= 1:
subprocess.run(["git", "checkout", "--", destination_file_path])
print(f"Reverted changes in {destination_file_path}, no new vesrion.")
else:
print(f"Updated {source_file_path} in {destination_dir}")
except Exception as e:
print(f"Failed to update {destination_file_path}: {e}")
else:
print(f"{source_file_path} does not exist in the source directory")
5 changes: 4 additions & 1 deletion source/threads/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,10 @@ def scrap_stable_releases(self, platform=None):
current_data = json.load(f)
file_ver = current_data.get("api_file_version", "0.1")
major, minor = map(int, file_ver.split("."))
minor += 1
if self.build_cache:
major += 1
else:
minor += 1
new_file_ver = f"{major}.{minor}"
logger.debug(f"Updating cache file version to {new_file_ver}")
except json.JSONDecodeError:
Expand Down

0 comments on commit 8d96817

Please sign in to comment.