mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Merged in feature/launcher-actions-as-plugins (pull request #4)
Feature/launcher actions as plugins Approved-by: Milan Kolar <mail@mkolar.com>
This commit is contained in:
commit
47d903cfd7
3 changed files with 104 additions and 78 deletions
|
|
@ -1,86 +1,30 @@
|
|||
import os
|
||||
from avalon import api, lib, pipeline
|
||||
import sys
|
||||
|
||||
from avalon import api, pipeline
|
||||
|
||||
class FusionRenderNode(api.Action):
|
||||
|
||||
name = "fusionrendernode9"
|
||||
label = "F9 Render Node"
|
||||
icon = "object-group"
|
||||
order = 997
|
||||
|
||||
def is_compatible(self, session):
|
||||
"""Return whether the action is compatible with the session"""
|
||||
if "AVALON_PROJECT" in session:
|
||||
return False
|
||||
return True
|
||||
|
||||
def process(self, session, **kwargs):
|
||||
"""Implement the behavior for when the action is triggered
|
||||
|
||||
Args:
|
||||
session (dict): environment dictionary
|
||||
|
||||
Returns:
|
||||
Popen instance of newly spawned process
|
||||
|
||||
"""
|
||||
|
||||
# Update environment with session
|
||||
env = os.environ.copy()
|
||||
env.update(session)
|
||||
|
||||
# Get executable by name
|
||||
app = lib.get_application(self.name)
|
||||
env.update(app["environment"])
|
||||
executable = lib.which(app["executable"])
|
||||
|
||||
return lib.launch(executable=executable, args=[], environment=env)
|
||||
|
||||
|
||||
class VrayRenderSlave(api.Action):
|
||||
|
||||
name = "vrayrenderslave"
|
||||
label = "V-Ray Slave"
|
||||
icon = "object-group"
|
||||
order = 996
|
||||
|
||||
def is_compatible(self, session):
|
||||
"""Return whether the action is compatible with the session"""
|
||||
if "AVALON_PROJECT" in session:
|
||||
return False
|
||||
return True
|
||||
|
||||
def process(self, session, **kwargs):
|
||||
"""Implement the behavior for when the action is triggered
|
||||
|
||||
Args:
|
||||
session (dict): environment dictionary
|
||||
|
||||
Returns:
|
||||
Popen instance of newly spawned process
|
||||
|
||||
"""
|
||||
|
||||
# Update environment with session
|
||||
env = os.environ.copy()
|
||||
env.update(session)
|
||||
|
||||
# Get executable by name
|
||||
app = lib.get_application(self.name)
|
||||
env.update(app["environment"])
|
||||
executable = lib.which(app["executable"])
|
||||
|
||||
# Run as server
|
||||
arguments = ["-server", "-portNumber=20207"]
|
||||
|
||||
return lib.launch(executable=executable,
|
||||
args=arguments,
|
||||
environment=env)
|
||||
PACKAGE_DIR = os.path.dirname(__file__)
|
||||
PLUGINS_DIR = os.path.join(PACKAGE_DIR, "plugins", "launcher")
|
||||
ACTIONS_DIR = os.path.join(PLUGINS_DIR, "actions")
|
||||
|
||||
|
||||
def register_launcher_actions():
|
||||
"""Register specific actions which should be accessible in the launcher"""
|
||||
|
||||
pipeline.register_plugin(api.Action, FusionRenderNode)
|
||||
pipeline.register_plugin(api.Action, VrayRenderSlave)
|
||||
actions = []
|
||||
ext = ".py"
|
||||
sys.path.append(ACTIONS_DIR)
|
||||
|
||||
for f in os.listdir(ACTIONS_DIR):
|
||||
file, extention = os.path.splitext(f)
|
||||
if ext in extention:
|
||||
module = __import__(file)
|
||||
klass = getattr(module, file)
|
||||
actions.append(klass)
|
||||
|
||||
if actions is []:
|
||||
return
|
||||
|
||||
for action in actions:
|
||||
print("Using launcher action from config @ '{}'".format(action.name))
|
||||
pipeline.register_plugin(api.Action, action)
|
||||
|
|
|
|||
38
pype/plugins/launcher/actions/FusionRenderNode.py
Normal file
38
pype/plugins/launcher/actions/FusionRenderNode.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import os
|
||||
from avalon import api, lib
|
||||
|
||||
|
||||
class FusionRenderNode(api.Action):
|
||||
|
||||
name = "fusionrendernode9"
|
||||
label = "F9 Render Node"
|
||||
icon = "object-group"
|
||||
order = 997
|
||||
|
||||
def is_compatible(self, session):
|
||||
"""Return whether the action is compatible with the session"""
|
||||
if "AVALON_PROJECT" in session:
|
||||
return False
|
||||
return True
|
||||
|
||||
def process(self, session, **kwargs):
|
||||
"""Implement the behavior for when the action is triggered
|
||||
|
||||
Args:
|
||||
session (dict): environment dictionary
|
||||
|
||||
Returns:
|
||||
Popen instance of newly spawned process
|
||||
|
||||
"""
|
||||
|
||||
# Update environment with session
|
||||
env = os.environ.copy()
|
||||
env.update(session)
|
||||
|
||||
# Get executable by name
|
||||
app = lib.get_application(self.name)
|
||||
env.update(app["environment"])
|
||||
executable = lib.which(app["executable"])
|
||||
|
||||
return lib.launch(executable=executable, args=[], environment=env)
|
||||
44
pype/plugins/launcher/actions/VrayRenderSlave.py
Normal file
44
pype/plugins/launcher/actions/VrayRenderSlave.py
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import os
|
||||
|
||||
from avalon import api, lib
|
||||
|
||||
|
||||
class VrayRenderSlave(api.Action):
|
||||
|
||||
name = "vrayrenderslave"
|
||||
label = "V-Ray Slave"
|
||||
icon = "object-group"
|
||||
order = 996
|
||||
|
||||
def is_compatible(self, session):
|
||||
"""Return whether the action is compatible with the session"""
|
||||
if "AVALON_PROJECT" in session:
|
||||
return False
|
||||
return True
|
||||
|
||||
def process(self, session, **kwargs):
|
||||
"""Implement the behavior for when the action is triggered
|
||||
|
||||
Args:
|
||||
session (dict): environment dictionary
|
||||
|
||||
Returns:
|
||||
Popen instance of newly spawned process
|
||||
|
||||
"""
|
||||
|
||||
# Update environment with session
|
||||
env = os.environ.copy()
|
||||
env.update(session)
|
||||
|
||||
# Get executable by name
|
||||
app = lib.get_application(self.name)
|
||||
env.update(app["environment"])
|
||||
executable = lib.which(app["executable"])
|
||||
|
||||
# Run as server
|
||||
arguments = ["-server", "-portNumber=20207"]
|
||||
|
||||
return lib.launch(executable=executable,
|
||||
args=arguments,
|
||||
environment=env)
|
||||
Loading…
Add table
Add a link
Reference in a new issue