Scripts: Re-Sync Blend Files #240

Merged
Sebastian Parborg merged 8 commits from TinyNick/blender-studio-pipeline:feature/resync_all_files into main 2024-02-22 16:21:03 +01:00
Showing only changes of commit 9ac3996f2c - Show all commits

View File

@ -37,6 +37,14 @@ parser.add_argument(
help="Path folder on which to perform crawl.", help="Path folder on which to perform crawl.",
) )
parser.add_argument(
"-e",
"--exec",
help="user must provide blender executable path.",
type=str,
required=True,
)
def get_bbatch_script_path() -> str: def get_bbatch_script_path() -> str:
"""Returns path to script that runs with bbatch""" """Returns path to script that runs with bbatch"""
@ -44,29 +52,6 @@ def get_bbatch_script_path() -> str:
return str(dir.joinpath("resync_blend_file.py")) return str(dir.joinpath("resync_blend_file.py"))
def get_blender_path(project_path: Path) -> str:
"""Get the path to a project's blender executable
Args:
project_path (Path): Path Object, containing project's root path
Returns:
str: Path to blender executable as a string
"""
local_blender_path = project_path.joinpath('local').joinpath('blender')
if not local_blender_path.exists():
return
system_name = platform.system().lower()
blender_path_base = local_blender_path / system_name
if system_name == 'linux':
blender_path = blender_path_base / 'blender'
elif system_name == 'darwin':
blender_path = blender_path_base / 'Blender.app' / 'Contents' / 'MacOS' / 'Blender'
elif system_name == 'windows':
blender_path = blender_path_base / 'blender.exe'
return str(blender_path.absolute())
def get_files_to_crawl(project_path: str): # -> returns list of strings def get_files_to_crawl(project_path: str): # -> returns list of strings
blend_files = [ blend_files = [
@ -91,11 +76,14 @@ def main():
project_path = Path(args.path) project_path = Path(args.path)
if not project_path.exists(): if not project_path.exists():
cancel_program("Provided Path does not exist") cancel_program("Provided Path does not exist")
exec_path = Path(args.exec)
if not exec_path.exists():
cancel_program("Provided Executable path does not exist")
script_path = get_bbatch_script_path() script_path = get_bbatch_script_path()
files_to_craw = get_files_to_crawl(project_path) files_to_craw = get_files_to_crawl(project_path)
if len(files_to_craw) < 1: if len(files_to_craw) < 1:
cancel_program("No Files to resync") cancel_program("No Files to resync")
project_blender = get_blender_path(project_path)
os.chdir("../bbatch") os.chdir("../bbatch")
print("Resyncing Files...") print("Resyncing Files...")
cmd_list = [ cmd_list = [
@ -106,19 +94,15 @@ def main():
"--recursive", "--recursive",
'--script', '--script',
script_path, script_path,
'--exec',
exec_path,
] ]
for item in files_to_craw: for item in files_to_craw:
cmd_list.insert(3, item) cmd_list.insert(3, item)
if project_blender:
cmd_list.append('--exec')
cmd_list.append(project_blender)
with open('/tmp/resync_log.txt', 'w') as log: with open('/tmp/resync_log.txt', 'w') as log:
# TODO Debug why logging isn't working as expected process = subprocess.Popen(cmd_list, stdout=log, stderr=log, shell=False)
process = subprocess.Popen(cmd_list, stdout=log, shell=False) # stderr=log,
# process = subprocess.Popen(cmd_list, shell=False)
if process.wait() != 0: if process.wait() != 0:
cancel_program(f"Resync Failed!") cancel_program(f"Resync Failed!")
print("Resync Completed Successfully") print("Resync Completed Successfully")