This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
[QUAD] Deadline: Improve get_publish_plugin_paths to properly get paths for the specified host #6313
Closed
BenSouchet
wants to merge
1
commit into
ynput:develop
from
quadproduction:enhancement/deadline-load-correct-plugins
Closed
[QUAD] Deadline: Improve get_publish_plugin_paths to properly get paths for the specified host #6313
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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): | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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)