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 3939faff79 - Show all commits

View File

@ -61,8 +61,15 @@ parser.add_argument(
action="store_true", action="store_true",
) )
parser.add_argument(
"--exec",
help="If --exec user must provide blender executable path, OS default blender will not be used if found.",
action="store_true",
)
# MAIN LOGIC # MAIN LOGIC
PURGE_PATH = Path(os.path.abspath(__file__)).parent.joinpath("purge.py")
PURGE_AMOUNT = 2 PURGE_AMOUNT = 2
@ -89,6 +96,12 @@ def cancel_program() -> None:
print("# Exiting blender-purge") print("# Exiting blender-purge")
sys.exit(0) sys.exit(0)
def find_default_blender():
output = subprocess.check_output(['whereis', 'blender'])
default_blender_str = f'/{str(output).split(" /")[1]}'
default_blender_binary = Path(default_blender_str)
if default_blender_binary.exists():
return default_blender_binary
def get_blender_path() -> Path: def get_blender_path() -> Path:
config_path = get_config_path() config_path = get_config_path()
@ -213,18 +226,21 @@ def input_filepath(question: str) -> Path:
def setup_config() -> None: def setup_config() -> None:
config_path = get_config_path() config_path = get_config_path()
config_path.parent.mkdir(parents=True, exist_ok=True) config_path.parent.mkdir(parents=True, exist_ok=True)
default_blender_path = find_default_blender()
if default_blender_path:
blender_path = default_blender_path
else:
blender_path = input_filepath("# Path to Blender binary: ") blender_path = input_filepath("# Path to Blender binary: ")
project_root = input_path("# Path to SVN project root: ")
obj = { obj = {
"blender_path": blender_path.as_posix(), "blender_path": blender_path.as_posix(),
"project_root": project_root.as_posix(),
} }
save_to_json(obj, config_path) save_to_json(obj, config_path)
print("Updatet config at: %s", config_path.as_posix()) print("Updatet config at: %s", config_path.as_posix())
def is_config_valid() -> bool: def is_config_valid() -> bool:
keys = ["blender_path", "project_root"] keys = ["blender_path",]
config_path = get_config_path() config_path = get_config_path()
json_obj = load_json(config_path) json_obj = load_json(config_path)
for key in keys: for key in keys:
@ -248,6 +264,7 @@ def run_blender_purge(args: argparse.Namespace) -> int:
path = Path(args.path).absolute() path = Path(args.path).absolute()
script = get_default_scipt(args.script) script = get_default_scipt(args.script)
recursive = args.recursive recursive = args.recursive
find_blender_exec = args.exec
config_path = get_config_path() config_path = get_config_path()
regex = args.regex regex = args.regex
yes = args.yes yes = args.yes
@ -256,12 +273,12 @@ def run_blender_purge(args: argparse.Namespace) -> int:
if not config_path.exists(): if not config_path.exists():
print("# Seems like you are starting blender-purge for the first time!") print("# Seems like you are starting blender-purge for the first time!")
print("# Some things needs to be configured") print("# Some things needs to be configured")
setup_config() setup_config(find_blender_exec)
else: else:
if not is_config_valid(): if not is_config_valid():
print("# Config file at: %s is not valid", config_path.as_posix()) print("# Config file at: %s is not valid", config_path.as_posix())
print("# Please set it up again") print("# Please set it up again")
setup_config() setup_config(find_blender_exec)
# Check user input. # Check user input.
if not path: if not path: