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 4db4c4cc84 - Show all commits

View File

@ -19,10 +19,6 @@
# (c) 2021, Blender Foundation # (c) 2021, Blender Foundation
#TODO
# Supply Many Script Files
# Supply Many .blend Files
import argparse import argparse
import sys import sys
import os import os
@ -36,14 +32,14 @@ from typing import List
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
"path", "path",
help="Path to a file or folder on which to perform crawl", help="Path to a file(s) or folder(s) on which to perform crawl",
type=str, nargs='+'
) )
parser.add_argument( parser.add_argument(
"--script", "--script",
help="Path to blender python script to execute inside .blend files during crawl. Execution is skipped if no script is provided", help="Path to blender python script(s) to execute inside .blend files during crawl. Execution is skipped if no script is provided",
type=str, nargs='+',
) )
parser.add_argument( parser.add_argument(
"-r", "-r",
@ -130,7 +126,7 @@ def blender_crawl_file(exec: Path, path: Path, script: Path) -> int:
return p.wait() return p.wait()
def is_filepath_valid(path: Path) -> None: def is_filepath_blend(path: Path) -> None:
# Check if path is file. # Check if path is file.
if not path.is_file(): if not path.is_file():
cancel_program(f"Not a file: {path.suffix}") cancel_program(f"Not a file: {path.suffix}")
@ -161,23 +157,28 @@ def get_purge_path(purge: bool):
def run_blender_crawl(args: argparse.Namespace) -> int: def run_blender_crawl(args: argparse.Namespace) -> int:
# Parse arguments. # Parse arguments.
path = Path(args.path).absolute()
script = check_file_exists(
args.script,
"No --script was not provided as argument, printed found .blend files, exiting program.",
)
purge_path = get_purge_path(args.purge) purge_path = get_purge_path(args.purge)
recursive = args.recursive recursive = args.recursive
exec = args.exec exec = args.exec
regex = args.filter regex = args.filter
script_input = args.script
ask_for_confirmation = args.ask ask_for_confirmation = args.ask
# Collect all possible scripts into list
scripts = [script for script in [script, purge_path] if script is not None]
if not path.exists(): scripts = []
cancel_program(f"Path does not exist: {path.as_posix()}") if script_input:
for script in script_input:
script_name = check_file_exists(
script,
"No --script was not provided as argument, printed found .blend files, exiting program.",
)
scripts.append(script_name)
# Purge is optional so it can be none
if purge_path is not None:
script.append()
if not exec: if not exec:
blender_exec = find_executable() blender_exec = find_executable()
else: else:
@ -187,23 +188,27 @@ def run_blender_crawl(args: argparse.Namespace) -> int:
# Vars. # Vars.
files = [] files = []
for item in args.path:
file_path = Path(item).absolute()
if not file_path.exists():
cancel_program(f"Path does not exist: {file_path.as_posix()}")
# Collect files to crawl # Collect files to crawl
# if dir. # if dir.
if path.is_dir(): if file_path.is_dir():
if recursive: if recursive:
blend_files = [ blend_files = [
f for f in path.glob("**/*") if f.is_file() and f.suffix == ".blend" f for f in file_path.glob("**/*") if f.is_file() and f.suffix == ".blend"
] ]
else:
blend_files = [

I don't think this program should have any config file at all.

Unless the command line tool is very complex (which this one is not), then the user should always have a fresh start each time the command line tool is run.

I'll elaborate further in an other comment.

I don't think this program should have any config file at all. Unless the command line tool is very complex (which this one is not), then the user should always have a fresh start each time the command line tool is run. I'll elaborate further in an other comment.

We handled this together 9e9c60fda3 issue resolved!

We handled this together https://projects.blender.org/studio/blender-studio-pipeline/commit/9e9c60fda3035acebb0991bad4c24b9643b29b36 issue resolved!
f for f in file_path.iterdir() if f.is_file() and f.suffix == ".blend"
]
files.extend(blend_files)
# If just one file.
else: else:
blend_files = [ is_filepath_blend(file_path)
f for f in path.iterdir() if f.is_file() and f.suffix == ".blend" files.append(file_path)
]
files.extend(blend_files)
# If just one file.
else:
is_filepath_valid(path)
files.append(path)
# Apply regex. # Apply regex.
if regex: if regex: