diff --git a/pype/launcher_actions.py b/pype/launcher_actions.py index 7d72cb2b38..cf68dfb5c1 100644 --- a/pype/launcher_actions.py +++ b/pype/launcher_actions.py @@ -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) diff --git a/pype/plugins/launcher/actions/FusionRenderNode.py b/pype/plugins/launcher/actions/FusionRenderNode.py new file mode 100644 index 0000000000..d866215fac --- /dev/null +++ b/pype/plugins/launcher/actions/FusionRenderNode.py @@ -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) diff --git a/pype/plugins/launcher/actions/VrayRenderSlave.py b/pype/plugins/launcher/actions/VrayRenderSlave.py new file mode 100644 index 0000000000..7461cfc0dd --- /dev/null +++ b/pype/plugins/launcher/actions/VrayRenderSlave.py @@ -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)