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

[QUAD] Deadline: Improve get_publish_plugin_paths to properly get paths for the specified host #6313

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (80 > 79 characters)

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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (92 > 79 characters)


# 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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (99 > 79 characters)

else:
self.plugin_paths[valid_plugin_type][host] = [plugin_path_resolved]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (95 > 79 characters)


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']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (93 > 79 characters)


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
Loading