Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Deadline: Improve get_publish_plugin_paths to properly get paths for …
Browse files Browse the repository at this point in the history
…the specified host
  • Loading branch information
BenSouchet committed Sep 11, 2024
1 parent d9731d0 commit 2705866
Showing 1 changed file with 65 additions and 4 deletions.
69 changes: 65 additions & 4 deletions openpype/modules/deadline/deadline_module.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import ast
import re
import os
import requests
import six
import sys
from pathlib import Path

from openpype.lib import requests_get, Logger
from openpype.modules import OpenPypeModule, IPluginPaths
Expand All @@ -15,9 +18,17 @@ class DeadlineWebserviceError(Exception):

class DeadlineModule(OpenPypeModule, IPluginPaths):
name = "deadline"
_valid_plugin_types = ["publish"]

def __init__(self, manager, settings):
self.deadline_urls = {}

self.plugin_paths = {}
for valid_plugin_type in self._valid_plugin_types:
self.plugin_paths[valid_plugin_type] = {
'all': []
}

super(DeadlineModule, self).__init__(manager, settings)

def initialize(self, modules_settings):
Expand All @@ -36,12 +47,62 @@ def initialize(self, modules_settings):
"not specified. Disabling module."))
return

# Retrieve plugin paths and properly sort them
hosts_regex = re.compile(r'hosts = (?P<hosts>\[[^\]]+\])')
plugin_dir = Path(__file__).joinpath("plugins").resolve()

for valid_plugin_type in self._valid_plugin_types:
search_dir = plugin_dir.joinpath(valid_plugin_type)

if not search_dir.exists():
continue

dir_plugin_paths = list(search_dir.glob('*.py'))

for plugin_path_str in dir_plugin_paths:
plugin_path = Path(plugin_path_str).resolve()
plugin_path_resolved = str(plugin_path)

# Opening the file, reading the content and extracting
# the list of hosts for the plugin path
with open(plugin_path) as f:
content = f.read()
match = hosts_regex.search(content)

if not match or not match.lastgroup:
# The regex didn't match, maybe an __init__.py file
continue

hosts_str = re.sub(r'\s+', '', match.group(match.lastgroup))
hosts_list = ast.literal_eval(hosts_str)

# Adding the plugin path to the "all" array
self.plugin_paths[valid_plugin_type]['all'].append(plugin_path_resolved)

# Adding the plugin path to the correct host array(s)
for host in hosts_list:
if host in self.plugin_paths[valid_plugin_type]:
self.plugin_paths[valid_plugin_type][host].append(plugin_path_resolved)
else:
self.plugin_paths[valid_plugin_type][host] = [plugin_path_resolved]

def get_plugin_paths(self):
"""Deadline plugin paths."""
current_dir = os.path.dirname(os.path.abspath(__file__))
return {
"publish": [os.path.join(current_dir, "plugins", "publish")]
}
all_plugin_paths = {}

for valid_plugin_type in self._valid_plugin_types:
all_plugin_paths[valid_plugin_type] = self.plugin_paths[valid_plugin_type]['all']

return all_plugin_paths

def get_publish_plugin_paths(self, host_name):
"""Only get the plugin paths related to the host specified"""
if not host_name or host_name not in self.plugin_paths['publish']:
# If we cannot determine the host, or it's not specified,
# then we will return all the registered plugin paths
host_name = "all"

return self.plugin_paths['publish'][host_name]

@staticmethod
def get_deadline_pools(webservice, log=None):
Expand Down

0 comments on commit 2705866

Please sign in to comment.