Asset Pipeline v2 #145
@ -202,98 +202,6 @@ def merge_task_layer(
|
||||
remove_suffix_from_hierarchy(local_col)
|
||||
|
||||
|
||||
def find_file_version(published_file: Path) -> int:
|
||||
"""Returns the version number from a published file's name
|
||||
|
||||
Args:
|
||||
file (Path): Path to a publish file, naming convention is
|
||||
asset_name.v{3-digit_version}.blend`
|
||||
|
||||
Returns:
|
||||
int: returns current version in filename as integer
|
||||
"""
|
||||
return int(published_file.name.split(".")[1].replace("v", ""))
|
||||
|
||||
|
||||
def get_next_published_file(
|
||||
current_file: Path, publish_type=constants.ACTIVE_PUBLISH_KEY
|
||||
) -> Path:
|
||||
"""Returns the path where the next published file version should be saved to
|
||||
|
||||
Args:
|
||||
current_file (Path): Current file, which must be a task file at root of asset directory
|
||||
publish_type (_type_, optional): Publish type, 'publish', 'staged', 'review'. Defaults to 'publish'.
|
||||
|
||||
Returns:
|
||||
Path: Path where the next published file should be saved to, path doesn't exist yet
|
||||
""" """"""
|
||||
last_publish = find_latest_publish(current_file, publish_type)
|
||||
base_name = current_file.name.split(".")[0]
|
||||
publish_dir = current_file.parent.joinpath(publish_type)
|
||||
if not last_publish:
|
||||
new_version_number = 1
|
||||
|
||||
else:
|
||||
new_version_number = find_file_version(last_publish) + 1
|
||||
new_version = "{0:0=3d}".format(new_version_number)
|
||||
return publish_dir.joinpath(base_name + f".v" + new_version + ".blend")
|
||||
|
||||
|
||||
def find_all_published(current_file: Path, publish_type: str) -> list[Path]:
|
||||
"""Retuns a list of published files of a given type,
|
||||
each publish type is seperated into it's own folder at the
|
||||
root of the asset's directory
|
||||
Args:
|
||||
current_file (Path): Current file, which must be a task file at root of asset directory
|
||||
publish_type (_type_, optional): Publish type, 'publish', 'staged', 'review'. Defaults to 'publish'.
|
||||
|
||||
Returns:
|
||||
list[Path]: list of published files of a given publish type
|
||||
"""
|
||||
publish_dir = current_file.parent.joinpath(publish_type)
|
||||
if not publish_dir.exists():
|
||||
return
|
||||
published_files = list(publish_dir.glob('*.blend'))
|
||||
published_files.sort(key=find_file_version)
|
||||
return published_files
|
||||
|
||||
|
||||
def find_latest_publish(
|
||||
current_file: Path, publish_type=constants.ACTIVE_PUBLISH_KEY
|
||||
) -> Path:
|
||||
"""Returns the path to the latest published file in a given folder
|
||||
|
||||
Args:
|
||||
current_file (Path): Current file, which must be a task file at root of asset directory
|
||||
publish_type (_type_, optional): Publish type, 'publish', 'staged', 'review'. Defaults to 'publish'.
|
||||
|
||||
Returns:
|
||||
Path: Path to latest publish file of a given publish type
|
||||
"""
|
||||
published_files = find_all_published(current_file, publish_type)
|
||||
if published_files:
|
||||
return published_files[-1]
|
||||
|
||||
|
||||
def find_sync_target(current_file: Path) -> Path:
|
||||
"""Returns the latest published file to use as push/pull a.k.a sync target
|
||||
this will either be the latest active publish, or the latest staged asset if
|
||||
any asset is staged
|
||||
|
||||
Args:
|
||||
current_file (Path): Current file, which must be a task file at root of asset directory
|
||||
|
||||
Returns:
|
||||
Path: Path to latest active or staged publish file
|
||||
""" """"""
|
||||
latest_staged = find_latest_publish(
|
||||
current_file, publish_type=constants.STAGED_PUBLISH_KEY
|
||||
)
|
||||
if latest_staged:
|
||||
return latest_staged
|
||||
return find_latest_publish(current_file, publish_type=constants.ACTIVE_PUBLISH_KEY)
|
||||
|
||||
|
||||
def import_data_from_lib(
|
||||
libpath: Path,
|
||||
data_category: str,
|
||||
@ -347,9 +255,6 @@ def import_data_from_lib(
|
||||
return eval(f"bpy.data.{data_category}['{data_name}']")
|
||||
|
||||
|
||||
## DRIVERS
|
||||
|
||||
|
||||
def get_other_ids(collection): # TODO find better name
|
||||
ref_map = get_id_reference_map()
|
||||
all_ids_of_coll = get_all_referenced_ids(collection, ref_map)
|
||||
|
@ -2,16 +2,18 @@ import bpy
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
from .publish import (
|
||||
find_sync_target,
|
||||
find_all_published,
|
||||
get_next_published_file,
|
||||
)
|
||||
from .core import (
|
||||
get_task_layer_col_name,
|
||||
ownership_get,
|
||||
ownership_set,
|
||||
get_invalid_objects,
|
||||
init_other_ids,
|
||||
find_sync_target,
|
||||
merge_task_layer,
|
||||
find_all_published,
|
||||
get_next_published_file,
|
||||
)
|
||||
from .transfer_data.transfer_ui import draw_transfer_data
|
||||
from . import constants
|
||||
|
94
scripts-blender/addons/asset_pipeline_2/publish.py
Normal file
94
scripts-blender/addons/asset_pipeline_2/publish.py
Normal file
@ -0,0 +1,94 @@
|
||||
from pathlib import Path
|
||||
from . import constants
|
||||
|
||||
|
||||
def find_file_version(published_file: Path) -> int:
|
||||
"""Returns the version number from a published file's name
|
||||
|
||||
Args:
|
||||
file (Path): Path to a publish file, naming convention is
|
||||
asset_name.v{3-digit_version}.blend`
|
||||
|
||||
Returns:
|
||||
int: returns current version in filename as integer
|
||||
"""
|
||||
return int(published_file.name.split(".")[1].replace("v", ""))
|
||||
|
||||
|
||||
def get_next_published_file(
|
||||
current_file: Path, publish_type=constants.ACTIVE_PUBLISH_KEY
|
||||
) -> Path:
|
||||
"""Returns the path where the next published file version should be saved to
|
||||
|
||||
Args:
|
||||
current_file (Path): Current file, which must be a task file at root of asset directory
|
||||
publish_type (_type_, optional): Publish type, 'publish', 'staged', 'review'. Defaults to 'publish'.
|
||||
|
||||
Returns:
|
||||
Path: Path where the next published file should be saved to, path doesn't exist yet
|
||||
""" """"""
|
||||
last_publish = find_latest_publish(current_file, publish_type)
|
||||
base_name = current_file.name.split(".")[0]
|
||||
publish_dir = current_file.parent.joinpath(publish_type)
|
||||
if not last_publish:
|
||||
new_version_number = 1
|
||||
|
||||
else:
|
||||
new_version_number = find_file_version(last_publish) + 1
|
||||
new_version = "{0:0=3d}".format(new_version_number)
|
||||
return publish_dir.joinpath(base_name + f".v" + new_version + ".blend")
|
||||
|
||||
|
||||
def find_all_published(current_file: Path, publish_type: str) -> list[Path]:
|
||||
"""Retuns a list of published files of a given type,
|
||||
each publish type is seperated into it's own folder at the
|
||||
root of the asset's directory
|
||||
Args:
|
||||
current_file (Path): Current file, which must be a task file at root of asset directory
|
||||
publish_type (_type_, optional): Publish type, 'publish', 'staged', 'review'. Defaults to 'publish'.
|
||||
|
||||
Returns:
|
||||
list[Path]: list of published files of a given publish type
|
||||
"""
|
||||
publish_dir = current_file.parent.joinpath(publish_type)
|
||||
if not publish_dir.exists():
|
||||
return
|
||||
published_files = list(publish_dir.glob('*.blend'))
|
||||
published_files.sort(key=find_file_version)
|
||||
return published_files
|
||||
|
||||
|
||||
def find_latest_publish(
|
||||
current_file: Path, publish_type=constants.ACTIVE_PUBLISH_KEY
|
||||
) -> Path:
|
||||
"""Returns the path to the latest published file in a given folder
|
||||
|
||||
Args:
|
||||
current_file (Path): Current file, which must be a task file at root of asset directory
|
||||
publish_type (_type_, optional): Publish type, 'publish', 'staged', 'review'. Defaults to 'publish'.
|
||||
|
||||
Returns:
|
||||
Path: Path to latest publish file of a given publish type
|
||||
"""
|
||||
published_files = find_all_published(current_file, publish_type)
|
||||
if published_files:
|
||||
return published_files[-1]
|
||||
|
||||
|
||||
def find_sync_target(current_file: Path) -> Path:
|
||||
"""Returns the latest published file to use as push/pull a.k.a sync target
|
||||
this will either be the latest active publish, or the latest staged asset if
|
||||
any asset is staged
|
||||
|
||||
Args:
|
||||
current_file (Path): Current file, which must be a task file at root of asset directory
|
||||
|
||||
Returns:
|
||||
Path: Path to latest active or staged publish file
|
||||
""" """"""
|
||||
latest_staged = find_latest_publish(
|
||||
current_file, publish_type=constants.STAGED_PUBLISH_KEY
|
||||
)
|
||||
if latest_staged:
|
||||
return latest_staged
|
||||
return find_latest_publish(current_file, publish_type=constants.ACTIVE_PUBLISH_KEY)
|
Loading…
Reference in New Issue
Block a user