Convert Blender-Purge to a more generic Blender-Crawl Tool #42

Merged
Nick Alberelli merged 34 commits from feature/blender-crawl into main 2023-05-17 15:38:47 +02:00
Showing only changes of commit 2d131afb47 - Show all commits

View File

@ -75,12 +75,6 @@ parser.add_argument(
)
# MAIN LOGIC
def main():
args = parser.parse_args()
run_blender_crawl(args)
def cancel_program(message: str):
print(message)
sys.exit(0)
@ -112,20 +106,6 @@ def prompt_confirm(list_length: int):
return True
def blender_crawl_file(exec: Path, path: Path, script: Path) -> int:
# Get cmd list.
cmd_list = (
exec.as_posix(),
path.as_posix(),
"-b",
"-P",
script,
"--factory-startup",
)
p = subprocess.Popen(cmd_list, shell=False)
return p.wait()
def is_filepath_blend(path: Path) -> None:
# Check if path is file.
if not path.is_file():
@ -156,8 +136,10 @@ def get_purge_path(purge: bool):
return check_file_exists(str(purge_script), "no purge found")
def run_blender_crawl(args: argparse.Namespace) -> int:
# Parse arguments.
def main() -> int:
"""Crawl blender files in a directory and run a provided scripts"""
# Parse arguments.
args = parser.parse_args()
purge_path = get_purge_path(args.purge)
recursive = args.recursive
exec = args.exec
@ -165,7 +147,6 @@ def run_blender_crawl(args: argparse.Namespace) -> int:
script_input = args.script
ask_for_confirmation = args.ask
scripts = []
if script_input:
for script in script_input:
@ -245,11 +226,18 @@ def run_blender_crawl(args: argparse.Namespace) -> int:
# crawl each file two times.
for blend_file in files:
for script in scripts:
return_code = blender_crawl_file(blender_exec, blend_file, script)
if return_code != 0:
cmd_list = (
blender_exec.as_posix(),
blend_file.as_posix(),
"-b",
"-P",
script,
"--factory-startup",
)
process = subprocess.Popen(cmd_list, shell=False)
if process.wait() != 0:
cancel_program(f"Blender Crashed on file: {blend_file.as_posix()}")
return 0
if __name__ == "__main__":
main()