save startup blend for animation tab & whatnot
This commit is contained in:
2026-04-08 12:10:18 -06:00
parent 57a652524a
commit 692e200ffe
180 changed files with 12336 additions and 3431 deletions
@@ -16,6 +16,8 @@
#
# ##### END GPL LICENSE BLOCK #####
from __future__ import annotations
import dataclasses
import logging
import os
@@ -23,7 +25,7 @@ import platform
import shutil
import subprocess
from os import path
from typing import Optional
from typing import Optional, Union
from http.client import responses as http_responses
@@ -36,6 +38,8 @@ from . import datas, global_vars, reports, utils
bk_logger = logging.getLogger(__name__)
NO_PROXIES = {"http": "", "https": ""}
TIMEOUT = (0.1, 1)
# Shorter timeout for the frequent report polling that runs on Blender's main thread.
POLL_TIMEOUT = (0.05, 0.25)
def get_address() -> str:
@@ -127,7 +131,7 @@ def reorder_ports(port: str = ""):
)
def get_reports(app_id: str):
def get_reports(app_id: int):
"""Get reports for all tasks of app_id Blender instance at once.
If few last calls failed, then try to get reports also from other than default ports.
"""
@@ -152,7 +156,7 @@ def get_reports(app_id: str):
reorder_ports(port)
return report
except Exception as e:
bk_logger.info(f"Failed to get BlenderKit-Client reports: {e}")
bk_logger.info("Failed to get BlenderKit-Client reports: %s", e)
last_exception = e
if last_exception is not None:
raise last_exception
@@ -163,7 +167,7 @@ def request_report(url: str, data: dict) -> dict:
If something goes south, this function raises requests.HTTPError or requests.JSONDecodeError.
"""
with requests.Session() as session:
resp = session.get(url, json=data, timeout=TIMEOUT, proxies=NO_PROXIES)
resp = session.get(url, json=data, timeout=POLL_TIMEOUT, proxies=NO_PROXIES)
if resp.status_code != 200:
# not using resp.raise_for_status() for better message
raise requests.HTTPError(
@@ -176,7 +180,7 @@ def request_report(url: str, data: dict) -> dict:
# SEARCH
def asset_search(search_data: datas.SearchData):
"""Search for specified asset."""
bk_logger.info(f"Starting search request: {search_data.urlquery}")
bk_logger.info("Starting search request: %s", search_data.urlquery)
search_data = ensure_minimal_data_class(search_data)
with requests.Session() as session:
@@ -184,7 +188,7 @@ def asset_search(search_data: datas.SearchData):
resp = session.post(
url, json=datas.asdict(search_data), timeout=TIMEOUT, proxies=NO_PROXIES
)
bk_logger.debug("Got search response")
bk_logger.log(5, "Got search response")
return resp.json()
@@ -219,7 +223,7 @@ def asset_upload(upload_data, export_data, upload_set):
data = ensure_minimal_data(data)
with requests.Session() as session:
url = get_base_url() + "/blender/asset_upload"
bk_logger.debug(f"making a request to: {url}")
bk_logger.debug("making a request to: %s", url)
resp = session.post(url, json=data, timeout=TIMEOUT, proxies=NO_PROXIES)
return resp
@@ -355,12 +359,15 @@ def get_rating(asset_id: str):
)
def send_rating(asset_id: str, rating_type: str, rating_value: str):
def send_rating(asset_id: str, rating_type: str, rating_value: Union[str, int]):
data = {
"asset_id": asset_id,
"rating_type": rating_type,
"rating_value": rating_value,
}
if rating_type == "bookmarks":
data["rating_value"] = int(rating_value) # type: ignore
data = ensure_minimal_data(data)
with requests.Session() as session:
return session.post(
@@ -674,7 +681,7 @@ def start_blenderkit_client():
reports.add_report(msg, type="ERROR")
raise (e)
bk_logger.info(f"BlenderKit-Client {client_version} starting on {get_address()}")
bk_logger.info("BlenderKit-Client %s starting on %s", client_version, get_address())
def decide_client_binary_name() -> str:
@@ -760,11 +767,11 @@ def ensure_client_binary_installed():
return
preinstalled_client_path = get_preinstalled_client_path()
bk_logger.info(f"Copying BlenderKit-Client binary {preinstalled_client_path}")
bk_logger.info("Copying BlenderKit-Client binary %s", preinstalled_client_path)
os.makedirs(path.dirname(client_binary_path), exist_ok=True)
shutil.copy(preinstalled_client_path, client_binary_path)
os.chmod(client_binary_path, 0o711)
bk_logger.info(f"BlenderKit-Client binary copied to {client_binary_path}")
bk_logger.info("BlenderKit-Client binary copied to %s", client_binary_path)
def get_addon_dir():