mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
feat(fusion): adding utility scripts
This commit is contained in:
parent
161700f2be
commit
9943f94f64
6 changed files with 163 additions and 0 deletions
7
pype/hosts/fusion/utility_scripts/creator.py
Normal file
7
pype/hosts/fusion/utility_scripts/creator.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import avalon.api
|
||||||
|
import avalon.fusion
|
||||||
|
import avalon.tools.creator as tool
|
||||||
|
|
||||||
|
|
||||||
|
avalon.api.install(avalon.fusion)
|
||||||
|
tool.show()
|
||||||
7
pype/hosts/fusion/utility_scripts/loader.py
Normal file
7
pype/hosts/fusion/utility_scripts/loader.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import avalon.api
|
||||||
|
import avalon.fusion
|
||||||
|
import avalon.tools.loader as tool
|
||||||
|
|
||||||
|
|
||||||
|
avalon.api.install(avalon.fusion)
|
||||||
|
tool.show(use_context=True)
|
||||||
7
pype/hosts/fusion/utility_scripts/manager.py
Normal file
7
pype/hosts/fusion/utility_scripts/manager.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import avalon.api
|
||||||
|
import avalon.fusion
|
||||||
|
import avalon.tools.sceneinventory as tool
|
||||||
|
|
||||||
|
|
||||||
|
avalon.api.install(avalon.fusion)
|
||||||
|
tool.show()
|
||||||
62
pype/hosts/fusion/utility_scripts/publish.py
Normal file
62
pype/hosts/fusion/utility_scripts/publish.py
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import avalon.api
|
||||||
|
import avalon.fusion
|
||||||
|
|
||||||
|
import pyblish_qml
|
||||||
|
|
||||||
|
|
||||||
|
def _install_fusion():
|
||||||
|
|
||||||
|
from pyblish_qml import settings
|
||||||
|
|
||||||
|
sys.stdout.write("Setting up Pyblish QML in Fusion\n")
|
||||||
|
|
||||||
|
if settings.ContextLabel == settings.ContextLabelDefault:
|
||||||
|
settings.ContextLabel = "Fusion"
|
||||||
|
if settings.WindowTitle == settings.WindowTitleDefault:
|
||||||
|
settings.WindowTitle = "Pyblish (Fusion)"
|
||||||
|
|
||||||
|
|
||||||
|
def _set_current_working_dir():
|
||||||
|
# Set current working directory next to comp
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Provided by Fusion
|
||||||
|
comp
|
||||||
|
except NameError:
|
||||||
|
comp = None
|
||||||
|
|
||||||
|
if comp is None:
|
||||||
|
raise RuntimeError("Fusion 'comp' variable not set. "
|
||||||
|
"Are you running this as Comp script?")
|
||||||
|
|
||||||
|
filename = comp.MapPath(comp.GetAttrs()["COMPS_FileName"])
|
||||||
|
if filename and os.path.exists(filename):
|
||||||
|
cwd = os.path.dirname(filename)
|
||||||
|
else:
|
||||||
|
# Fallback to Avalon projects root
|
||||||
|
# for unsaved files.
|
||||||
|
cwd = os.environ["AVALON_PROJECTS"]
|
||||||
|
|
||||||
|
os.chdir(cwd)
|
||||||
|
|
||||||
|
|
||||||
|
print("Starting Pyblish setup..")
|
||||||
|
|
||||||
|
# Install avalon
|
||||||
|
avalon.api.install(avalon.fusion)
|
||||||
|
|
||||||
|
# force current working directory to NON FUSION path
|
||||||
|
# os.getcwd will return the binary folder of Fusion in this case
|
||||||
|
_set_current_working_dir()
|
||||||
|
|
||||||
|
# install fusion title
|
||||||
|
_install_fusion()
|
||||||
|
|
||||||
|
# Run QML in modal mode so it keeps listening to the
|
||||||
|
# server in the main thread and keeps this process
|
||||||
|
# open until QML finishes.
|
||||||
|
print("Running publish_qml.show(modal=True)..")
|
||||||
|
pyblish_qml.show(modal=True)
|
||||||
7
pype/hosts/fusion/utility_scripts/workfiles.py
Normal file
7
pype/hosts/fusion/utility_scripts/workfiles.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import avalon.api
|
||||||
|
import avalon.fusion
|
||||||
|
import avalon.tools.workfiles as tool
|
||||||
|
|
||||||
|
|
||||||
|
avalon.api.install(avalon.fusion)
|
||||||
|
tool.show()
|
||||||
73
pype/hosts/fusion/utils.py
Normal file
73
pype/hosts/fusion/utils.py
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
#! python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
Resolve's tools for setting environment
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
from pypeapp import Logger
|
||||||
|
|
||||||
|
log = Logger().get_logger(__name__, "resolve")
|
||||||
|
|
||||||
|
|
||||||
|
def _sync_utility_scripts(env=None):
|
||||||
|
""" Synchronizing basic utlility scripts for resolve.
|
||||||
|
|
||||||
|
To be able to run scripts from inside `Resolve/Workspace/Scripts` menu
|
||||||
|
all scripts has to be accessible from defined folder.
|
||||||
|
"""
|
||||||
|
if not env:
|
||||||
|
env = os.environ
|
||||||
|
|
||||||
|
# initiate inputs
|
||||||
|
scripts = {}
|
||||||
|
us_env = env.get("FUSION_UTILITY_SCRIPTS_SOURCE_DIR")
|
||||||
|
us_dir = env.get("FUSION_UTILITY_SCRIPTS_DIR", "")
|
||||||
|
us_paths = [os.path.join(
|
||||||
|
os.path.dirname(__file__),
|
||||||
|
"utility_scripts"
|
||||||
|
)]
|
||||||
|
|
||||||
|
# collect script dirs
|
||||||
|
if us_env:
|
||||||
|
log.info(f"Utility Scripts Env: `{us_env}`")
|
||||||
|
us_paths = us_env.split(
|
||||||
|
os.pathsep) + us_paths
|
||||||
|
|
||||||
|
# collect scripts from dirs
|
||||||
|
for path in us_paths:
|
||||||
|
scripts.update({path: os.listdir(path)})
|
||||||
|
|
||||||
|
log.info(f"Utility Scripts Dir: `{us_paths}`")
|
||||||
|
log.info(f"Utility Scripts: `{scripts}`")
|
||||||
|
|
||||||
|
# make sure no script file is in folder
|
||||||
|
if next((s for s in os.listdir(us_dir)), None):
|
||||||
|
for s in os.listdir(us_dir):
|
||||||
|
path = os.path.join(us_dir, s)
|
||||||
|
log.info(f"Removing `{path}`...")
|
||||||
|
os.remove(path)
|
||||||
|
|
||||||
|
# copy scripts into Resolve's utility scripts dir
|
||||||
|
for d, sl in scripts.items():
|
||||||
|
# directory and scripts list
|
||||||
|
for s in sl:
|
||||||
|
# script in script list
|
||||||
|
src = os.path.join(d, s)
|
||||||
|
dst = os.path.join(us_dir, s)
|
||||||
|
log.info(f"Copying `{src}` to `{dst}`...")
|
||||||
|
shutil.copy2(src, dst)
|
||||||
|
|
||||||
|
|
||||||
|
def setup(env=None):
|
||||||
|
""" Wrapper installer started from pype.hooks.resolve.ResolvePrelaunch()
|
||||||
|
"""
|
||||||
|
if not env:
|
||||||
|
env = os.environ
|
||||||
|
|
||||||
|
# synchronize resolve utility scripts
|
||||||
|
_sync_utility_scripts(env)
|
||||||
|
|
||||||
|
log.info("Resolve Pype wrapper has been installed")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue