Clean up houdini scripts
This commit is contained in:
parent
f0255f5ed4
commit
6bd3f2c325
@ -1,13 +0,0 @@
|
|||||||
from pathlib import Path
|
|
||||||
|
|
||||||
DCC_DATA_BASE_DIR = Path.home() / "Videos" / "DCC"
|
|
||||||
"""The base directory for storing data across DCCs"""
|
|
||||||
|
|
||||||
HOUDINI_BASE_DIR = DCC_DATA_BASE_DIR / "Houdini"
|
|
||||||
"""The base directory for storing Houdini data"""
|
|
||||||
|
|
||||||
HOUDINI_PROJECTS_DIR = HOUDINI_BASE_DIR / "Projects"
|
|
||||||
"""The base directory for storing Houdini projects"""
|
|
||||||
|
|
||||||
BLENDER_BASE_DIR = DCC_DATA_BASE_DIR / "Blender"
|
|
||||||
"""The base directory for storing Blender data"""
|
|
@ -1,31 +0,0 @@
|
|||||||
import os
|
|
||||||
from typing import Dict
|
|
||||||
|
|
||||||
|
|
||||||
def diff_environments(env_1: Dict[str, str], env_2: Dict[str, str]) -> Dict[str, str]:
|
|
||||||
"""Diff two environments.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
env_1 (Dict[str,str]): First environment
|
|
||||||
env_2 (Dict[str,str]): Second environment
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Dict[str,str]: Difference between the two environments
|
|
||||||
"""
|
|
||||||
return {
|
|
||||||
key: value
|
|
||||||
for key, value in env_1.items()
|
|
||||||
if key not in env_2 or env_2[key] != value
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def diff_from_current_env(new_env: Dict[str, str]) -> Dict[str, str]:
|
|
||||||
"""Diff the current environment from the given environment.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
new_env (Dict[str, str]): New environment
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
Dict[str, str]: Difference between the current environment and the given environment
|
|
||||||
"""
|
|
||||||
return diff_environments(os.environ, new_env) # type: ignore
|
|
@ -1,8 +0,0 @@
|
|||||||
import logging
|
|
||||||
|
|
||||||
|
|
||||||
def configure_logging(verbose: bool = False):
|
|
||||||
logging.basicConfig(
|
|
||||||
level=logging.DEBUG if verbose else logging.INFO,
|
|
||||||
format="%(levelname)s:\t%(message)s",
|
|
||||||
)
|
|
@ -1,11 +0,0 @@
|
|||||||
from pathlib import Path
|
|
||||||
|
|
||||||
|
|
||||||
def prepend_if_relative(prefix: Path, possibly_abs_path: Path) -> Path:
|
|
||||||
|
|
||||||
# If absolute, no prepend needed
|
|
||||||
if possibly_abs_path.is_absolute():
|
|
||||||
return possibly_abs_path
|
|
||||||
|
|
||||||
# Otherwise prepend
|
|
||||||
return prefix / possibly_abs_path
|
|
@ -1,50 +0,0 @@
|
|||||||
from typing import List
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
HOU_EDITIONS = ["core", "fx", "indie", "apprentice"]
|
|
||||||
"""All possible Houdini editions."""
|
|
||||||
|
|
||||||
|
|
||||||
def get_binary_name_for_edition(edition: str) -> str:
|
|
||||||
"""Get the appropriate binary name for the given Houdini edition.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
edition (str): Hooudini edition
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: Binary name
|
|
||||||
"""
|
|
||||||
|
|
||||||
if edition in ["core", "fx"]:
|
|
||||||
return f"houdini{edition}"
|
|
||||||
else:
|
|
||||||
return "houdini"
|
|
||||||
|
|
||||||
|
|
||||||
def get_houdini_edition_args(edition: str) -> List[str]:
|
|
||||||
"""Get the appropriate arguments to launch a given Houdini edition.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
edition (str): Houdini edition
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
List[str]: Arguments
|
|
||||||
"""
|
|
||||||
|
|
||||||
if edition in ["indie", "apprentice"]:
|
|
||||||
return [f"-{edition}"]
|
|
||||||
else:
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
def noncomercialize_path(input_path: Path) -> Path:
|
|
||||||
# Figure out the noncomercial version of the path
|
|
||||||
path_suffix = input_path.suffix
|
|
||||||
noncomercial_path = input_path.with_suffix(f".{path_suffix}nc")
|
|
||||||
|
|
||||||
# If the NC version exists, use it
|
|
||||||
if noncomercial_path.exists():
|
|
||||||
return noncomercial_path
|
|
||||||
|
|
||||||
# All other cases, use the input directly
|
|
||||||
return input_path
|
|
@ -1,37 +0,0 @@
|
|||||||
from dataclasses import dataclass, field, fields
|
|
||||||
from typing import Dict, Optional
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class HoudiniEnvironment:
|
|
||||||
script_debug: bool = field(default=True, metadata={"key": "HOUDINI_SCRIPT_DEBUG"})
|
|
||||||
"""If set, errors will be printed when loading dialog scripts and scripted operators."""
|
|
||||||
|
|
||||||
show_py_panel_errors_in_console: bool = field(
|
|
||||||
default=True, metadata={"key": "HOUDINI_CONSOLE_PYTHON_PANEL_ERROR"}
|
|
||||||
)
|
|
||||||
"""Errors when starting python panels will also be sent to the console, instead of just displaying them within the panel."""
|
|
||||||
|
|
||||||
pdg_node_debug_level: int = field(
|
|
||||||
default=3, metadata={"key": "HOUDINI_PDG_NODE_DEBUG"}
|
|
||||||
)
|
|
||||||
"""Determines if PDG should print out node status information during the cook.
|
|
||||||
|
|
||||||
1: Enable a status print out message each time a node finishes cooking
|
|
||||||
2: 1 + node error messages
|
|
||||||
3: Print node generation/cook status, errors and node warnings
|
|
||||||
4: 3 + print a message for each node callback invocation
|
|
||||||
"""
|
|
||||||
|
|
||||||
splash_message: Optional[str] = field(
|
|
||||||
default=None, metadata={"key": "HOUDINI_SPLASH_MESSAGE"}
|
|
||||||
)
|
|
||||||
"""Message shown on the splash screen"""
|
|
||||||
|
|
||||||
def to_dict(self) -> Dict[str, str]:
|
|
||||||
output: Dict[str, str] = {}
|
|
||||||
for obj_field in fields(self):
|
|
||||||
field_value = self.__dict__[obj_field.name]
|
|
||||||
if field_value:
|
|
||||||
output[obj_field.metadata["key"]] = str()
|
|
||||||
return output
|
|
14
python_modules/ewpipe/houdini/installations.py → scripts/houdini-path
Normal file → Executable file
14
python_modules/ewpipe/houdini/installations.py → scripts/houdini-path
Normal file → Executable file
@ -1,3 +1,4 @@
|
|||||||
|
#! /usr/bin/env python3
|
||||||
import logging
|
import logging
|
||||||
import platform
|
import platform
|
||||||
import argparse
|
import argparse
|
||||||
@ -110,17 +111,20 @@ def get_houdini_installation_path(
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
ap = argparse.ArgumentParser()
|
ap = argparse.ArgumentParser(
|
||||||
|
prog="houdini-path",
|
||||||
|
description="Gets the appropriate path to a specified Houdini installation",
|
||||||
|
)
|
||||||
ap.add_argument("--version", "-v", help="Houdini version", type=str)
|
ap.add_argument("--version", "-v", help="Houdini version", type=str)
|
||||||
ap.add_argument("--base-path", "-b", help="Houdini base path", type=str)
|
ap.add_argument("--base-path", "-b", help="Houdini base path", type=str)
|
||||||
ap.add_argument("--not-exists-ok", help="Allow bad paths", action="store_true")
|
ap.add_argument("--not-exists-ok", help="Allow bad paths", action="store_true")
|
||||||
args = ap.parse_args()
|
args = ap.parse_args()
|
||||||
|
|
||||||
result = get_houdini_installation_path(
|
result = get_houdini_installation_path(
|
||||||
version=args.version,
|
version=args.version,
|
||||||
base_path=Path(args.base_path) if args.base_path else None,
|
base_path=Path(args.base_path) if args.base_path else None,
|
||||||
not_exists_ok=args.not_exists_ok,
|
not_exists_ok=args.not_exists_ok,
|
||||||
)
|
)
|
||||||
if not result:
|
if not result:
|
||||||
print("Could not find Houdini", file=sys.stderr)
|
print("Could not find Houdini", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
@ -1,137 +0,0 @@
|
|||||||
#! /usr/bin/env python3
|
|
||||||
|
|
||||||
# fmt:off
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
from pathlib import Path
|
|
||||||
sys.path.append((Path(os.environ["EWCONFIG_ROOT"]) / "python_modules").as_posix())
|
|
||||||
# fmt:on
|
|
||||||
|
|
||||||
import argparse
|
|
||||||
import subprocess
|
|
||||||
import logging
|
|
||||||
from ewpipe.common.dirs import HOUDINI_PROJECTS_DIR
|
|
||||||
from ewpipe.common.utils.path import prepend_if_relative
|
|
||||||
from ewpipe.houdini.editions import (
|
|
||||||
get_binary_name_for_edition,
|
|
||||||
get_houdini_edition_args,
|
|
||||||
HOU_EDITIONS,
|
|
||||||
noncomercialize_path,
|
|
||||||
)
|
|
||||||
from ewpipe.houdini.installations import get_houdini_installation_path
|
|
||||||
from ewpipe.common.logging import configure_logging
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
|
||||||
# Handle program arguments
|
|
||||||
ap = argparse.ArgumentParser(
|
|
||||||
prog="houdini-tool",
|
|
||||||
description="Evan's tool for launching and managing Houdini",
|
|
||||||
)
|
|
||||||
ap.add_argument(
|
|
||||||
"--type",
|
|
||||||
"-t",
|
|
||||||
help="Houdini type",
|
|
||||||
choices=HOU_EDITIONS,
|
|
||||||
default="apprentice",
|
|
||||||
)
|
|
||||||
ap.add_argument(
|
|
||||||
"--project",
|
|
||||||
"-p",
|
|
||||||
help="Name of the project to open or create. May also be a direct path",
|
|
||||||
type=str,
|
|
||||||
required=True,
|
|
||||||
)
|
|
||||||
ap.add_argument(
|
|
||||||
"--sub-project",
|
|
||||||
"--sp",
|
|
||||||
help="Name of the sub-project to open",
|
|
||||||
type=str,
|
|
||||||
default=None,
|
|
||||||
)
|
|
||||||
ap.add_argument(
|
|
||||||
"--hou-version",
|
|
||||||
help="Houdini version to use. Defaults to latest",
|
|
||||||
type=str,
|
|
||||||
default=None,
|
|
||||||
)
|
|
||||||
ap.add_argument(
|
|
||||||
"--no-project-env", help="Disables setting $HIP and $JOB", action="store_true"
|
|
||||||
)
|
|
||||||
ap.add_argument("--cpu", help="Use CPU compute for OpenCL", action="store_true")
|
|
||||||
ap.add_argument(
|
|
||||||
"--dump-core", help="Forces Houdini to dump its core", action="store_true"
|
|
||||||
)
|
|
||||||
ap.add_argument("--verbose", "-v", help="Verbose output", action="store_true")
|
|
||||||
args = ap.parse_args()
|
|
||||||
|
|
||||||
# Set up verbose logging if requested
|
|
||||||
configure_logging(verbose=args.verbose)
|
|
||||||
|
|
||||||
# Get the houdini path
|
|
||||||
hou_path = get_houdini_installation_path(version=args.hou_version)
|
|
||||||
if not hou_path:
|
|
||||||
logger.error("Could not find Houdini installation")
|
|
||||||
return 1
|
|
||||||
logger.info(f"Selected Houdini {hou_path.name[3:]} from {hou_path}")
|
|
||||||
|
|
||||||
# Determine the project path
|
|
||||||
project_path = prepend_if_relative(HOUDINI_PROJECTS_DIR, Path(args.project))
|
|
||||||
project_save_file = project_path / (
|
|
||||||
f"{args.sub_project}.hip" if args.sub_project else f"{project_path.name}.hip"
|
|
||||||
)
|
|
||||||
logger.info(f"Opening project from: {project_path}")
|
|
||||||
|
|
||||||
# If the directory does not exist, create
|
|
||||||
project_path.mkdir(parents=True, exist_ok=True)
|
|
||||||
(project_path / "render").mkdir(parents=True, exist_ok=True)
|
|
||||||
|
|
||||||
# If allowed, set up env vars
|
|
||||||
hou_env_settings = {}
|
|
||||||
hou_env_settings["HOUDINI_SCRIPT_DEBUG"] = "1"
|
|
||||||
hou_env_settings["HOUDINI_SPLASH_MESSAGE"] = "Loading with custom scripts"
|
|
||||||
hou_env_settings["HOUDINI_CONSOLE_PYTHON_PANEL_ERROR"] = "1"
|
|
||||||
hou_env_settings["HOUDINI_PDG_NODE_DEBUG"] = "3"
|
|
||||||
if args.cpu:
|
|
||||||
hou_env_settings["HOUDINI_OCL_DEVICETYPE"] = "CPU"
|
|
||||||
hou_env_settings["HOUDINI_USE_HFS_OCL"] = "1"
|
|
||||||
if args.dump_core:
|
|
||||||
hou_env_settings["HOUDINI_COREDUMP"] = "1"
|
|
||||||
if not args.no_project_env:
|
|
||||||
# environment_vars["HIP"] = str(project_path)
|
|
||||||
hou_env_settings["JOB"] = str(project_path)
|
|
||||||
hou_env_settings["HOUDINI_HIP_DEFAULT_NAME"] = project_save_file.name
|
|
||||||
|
|
||||||
# Figure out what has changed in the environment and print the changes
|
|
||||||
if hou_env_settings:
|
|
||||||
logger.info("Environment changes:")
|
|
||||||
for key, value in hou_env_settings.items():
|
|
||||||
logger.info(f" ${key}: {value}")
|
|
||||||
|
|
||||||
# Combine the current environment with
|
|
||||||
cmd_env = dict(os.environ)
|
|
||||||
cmd_env.update(hou_env_settings)
|
|
||||||
|
|
||||||
# Build command to launch houdini
|
|
||||||
cmd = [
|
|
||||||
str(hou_path / "bin" / get_binary_name_for_edition(args.type)),
|
|
||||||
"-foreground",
|
|
||||||
] + get_houdini_edition_args(args.type)
|
|
||||||
|
|
||||||
# If the expected project file exists already
|
|
||||||
# (aka, user already saved in a previous session),
|
|
||||||
# then conveniently open the project automatically
|
|
||||||
proj_file = noncomercialize_path(project_save_file)
|
|
||||||
if proj_file.exists():
|
|
||||||
cmd.append(str(proj_file))
|
|
||||||
|
|
||||||
# Run houdini
|
|
||||||
logger.info(f"Running: {' '.join(cmd)}")
|
|
||||||
status = subprocess.run(cmd, env=cmd_env, cwd=project_path).returncode
|
|
||||||
return status
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
sys.exit(main())
|
|
@ -1,9 +1,5 @@
|
|||||||
#! /bin/bash
|
#! /bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Find hython
|
|
||||||
HOUDINI_PATH=`python3 ~/.config/ewconfig/python_modules/ewpipe/houdini/installations.py`
|
|
||||||
HYTHON_PATH=$HOUDINI_PATH/bin/hython
|
|
||||||
|
|
||||||
# Execute hython, passing through all arguments
|
# Execute hython, passing through all arguments
|
||||||
$HYTHON_PATH $@
|
$(houdini-path)/bin/hython $@
|
||||||
|
Loading…
x
Reference in New Issue
Block a user