generated from ynput/ayon-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editorial_pkg: publishing sequence into OTIO timeline with rendered media #132
Open
moonyuet
wants to merge
38
commits into
develop
Choose a base branch
from
feature/AY-6916_Editorial-publish-from-Unreal-to-Ayon
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+967
−6
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
72c2f1e
wip for creator, collector and extractor for editorial product type
moonyuet ef4e87d
remove collect editorial as it is not gonna use for this workflow
moonyuet 9f24405
remove otio-related workflow as it is not related to this PR
moonyuet f96b691
wip the creator and render for clip function
moonyuet bbfafef
wip the creator
moonyuet 58e46bf
wip on the creator and collector
moonyuet b6082c4
wip on the creator
moonyuet 427828e
use editorial pkg product type
moonyuet f4a6956
remove to return unnecessary function
moonyuet 4962722
wip on implementation
moonyuet ea40c2d
draft the otio_unreal_export script
moonyuet 9377c8d
draft the otio_unreal_export script
moonyuet 47dd36a
resolve conflict
moonyuet 3001478
wip creator
moonyuet 521d94b
wip creator
moonyuet 1e60e01
add intermediate renders and supports rendering for editorial package
moonyuet 4864345
add the check on the publish error in the collector if the users do n…
moonyuet 306cd6e
make sure the frame range is correct
moonyuet 6f93a9c
edit rendering py for rendering out the image in different directory
moonyuet c6afe1e
fix the enumerate value
moonyuet be237a5
update the intermediate render product type as editorial publish and …
moonyuet 2cbab6e
edit the unreal_export.py
moonyuet b146626
coverting otio logic to accompany wioth unreal in unreal_export.py
moonyuet 9291eaa
coverting otio logic to accompany wioth unreal in unreal_export.py
moonyuet 78d794e
implement unreal logic into unreal_export.py
moonyuet beb46a3
impelement the extractor for intermediate render
moonyuet fd08023
implement pre-launch hook for otio installation
moonyuet adf1d84
implement extract edidtorial package.py
moonyuet 454c941
make sure the opentimelineio is using 0.16.0
moonyuet aa662db
edit the unreal export.py for getting correct track name
moonyuet 726e169
update the extract data for the representation
moonyuet 8e5a726
add remove tags
moonyuet 90a08c9
add remove tags
moonyuet b08b410
ruff cosmetic fix
moonyuet f5a6ce1
uses get_name instead of get_sequence().get_name()
moonyuet ac16030
uses get_name instead of get_sequence().get_name()
moonyuet 403cf56
resolve conflict
moonyuet aa61db2
make sure the image sequences not being rendered per sub sequence dur…
moonyuet 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
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
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
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 |
---|---|---|
@@ -0,0 +1,237 @@ | ||
import os | ||
import subprocess | ||
from platform import system | ||
from ayon_applications import PreLaunchHook, LaunchTypes | ||
|
||
|
||
class InstallOtioToBlender(PreLaunchHook): | ||
"""Install Qt binding to Unreal's python packages. | ||
|
||
Prelaunch hook does 2 things: | ||
1.) Unreal's python packages are pushed to the beginning of PYTHONPATH. | ||
2.) Check if Unreal has installed otio and will try to install if not. | ||
|
||
For pipeline implementation is required to have Qt binding installed in | ||
Unreal's python packages. | ||
""" | ||
|
||
app_groups = {"unreal"} | ||
launch_types = {LaunchTypes.local} | ||
|
||
def execute(self): | ||
# Prelaunch hook is not crucial | ||
try: | ||
self.inner_execute() | ||
except Exception: | ||
self.log.warning( | ||
"Processing of {} crashed.".format(self.__class__.__name__), | ||
exc_info=True | ||
) | ||
|
||
def inner_execute(self): | ||
platform = system().lower() | ||
executable = self.launch_context.executable.executable_path | ||
expected_executable = "UnrealEditor" | ||
if platform == "windows": | ||
expected_executable += ".exe" | ||
|
||
if os.path.basename(executable) != expected_executable: | ||
self.log.info(( | ||
f"Executable does not lead to {expected_executable} file." | ||
"Can't determine Unreal's python to check/install" | ||
" otio binding." | ||
)) | ||
return | ||
|
||
versions_dir = self.find_parent_directory(executable) | ||
otio_binding = "opentimelineio" | ||
otio_binding_version = None | ||
|
||
python_dir = os.path.join(versions_dir, "ThirdParty", "Python3", "Win64") | ||
python_version = "python" | ||
|
||
if platform == "windows": | ||
python_executable = os.path.join(python_dir, "python.exe") | ||
else: | ||
python_executable = os.path.join(python_dir, python_version) | ||
# Check for python with enabled 'pymalloc' | ||
if not os.path.exists(python_executable): | ||
python_executable += "m" | ||
|
||
if not os.path.exists(python_executable): | ||
self.log.warning( | ||
"Couldn't find python executable for Unreal. {}".format( | ||
executable | ||
) | ||
) | ||
return | ||
|
||
# Check if otio is installed and skip if yes | ||
if self.is_otio_installed(python_executable, otio_binding): | ||
self.log.debug("Unreal has already installed otio.") | ||
return | ||
|
||
# Install otio in Unreal's python | ||
if platform == "windows": | ||
result = self.install_otio_windows( | ||
python_executable, | ||
otio_binding, | ||
otio_binding_version | ||
) | ||
else: | ||
result = self.install_otio( | ||
python_executable, | ||
otio_binding, | ||
otio_binding_version | ||
) | ||
|
||
if result: | ||
self.log.info( | ||
f"Successfully installed {otio_binding} module to Unreal." | ||
) | ||
else: | ||
self.log.warning( | ||
f"Failed to install {otio_binding} module to Unreal." | ||
) | ||
|
||
def install_otio_windows( | ||
self, | ||
python_executable, | ||
otio_binding, | ||
otio_binding_version | ||
): | ||
"""Install otio python module to Unreal's python. | ||
|
||
Installation requires administration rights that's why it is required | ||
to use "pywin32" module which can execute command's and ask for | ||
administration rights. | ||
""" | ||
try: | ||
import win32con | ||
import win32process | ||
import win32event | ||
import pywintypes | ||
from win32comext.shell.shell import ShellExecuteEx | ||
from win32comext.shell import shellcon | ||
except Exception: | ||
self.log.warning("Couldn't import \"pywin32\" modules") | ||
return | ||
|
||
|
||
otio_binding = f"{otio_binding}==0.16.0" | ||
|
||
try: | ||
# Parameters | ||
# - use "-m pip" as module pip to install otio and argument | ||
# "--ignore-installed" is to force install module to Unreal's | ||
# site-packages and make sure it is binary compatible | ||
fake_exe = "fake.exe" | ||
args = [ | ||
fake_exe, | ||
"-m", | ||
"pip", | ||
"install", | ||
"--ignore-installed", | ||
otio_binding, | ||
] | ||
|
||
parameters = ( | ||
subprocess.list2cmdline(args) | ||
.lstrip(fake_exe) | ||
.lstrip(" ") | ||
) | ||
|
||
# Execute command and ask for administrator's rights | ||
process_info = ShellExecuteEx( | ||
nShow=win32con.SW_SHOWNORMAL, | ||
fMask=shellcon.SEE_MASK_NOCLOSEPROCESS, | ||
lpVerb="runas", | ||
lpFile=python_executable, | ||
lpParameters=parameters, | ||
lpDirectory=os.path.dirname(python_executable) | ||
) | ||
process_handle = process_info["hProcess"] | ||
win32event.WaitForSingleObject(process_handle, win32event.INFINITE) | ||
returncode = win32process.GetExitCodeProcess(process_handle) | ||
return returncode == 0 | ||
except pywintypes.error: | ||
pass | ||
|
||
def install_otio( | ||
self, | ||
python_executable, | ||
otio_binding, | ||
otio_binding_version, | ||
): | ||
"""Install Qt binding python module to Unreal's python.""" | ||
if otio_binding_version: | ||
otio_binding = f"{otio_binding}=={otio_binding_version}" | ||
try: | ||
# Parameters | ||
# - use "-m pip" as module pip to install qt binding and argument | ||
# "--ignore-installed" is to force install module to Unreal's | ||
# site-packages and make sure it is binary compatible | ||
# TODO find out if Unreal 4.x on linux/darwin does install | ||
# qt binding to correct place. | ||
args = [ | ||
python_executable, | ||
"-m", | ||
"pip", | ||
"install", | ||
"--ignore-installed", | ||
otio_binding, | ||
] | ||
process = subprocess.Popen( | ||
args, stdout=subprocess.PIPE, universal_newlines=True | ||
) | ||
process.communicate() | ||
return process.returncode == 0 | ||
except PermissionError: | ||
self.log.warning( | ||
"Permission denied with command:" | ||
"\"{}\".".format(" ".join(args)) | ||
) | ||
except OSError as error: | ||
self.log.warning(f"OS error has occurred: \"{error}\".") | ||
except subprocess.SubprocessError: | ||
pass | ||
|
||
def is_otio_installed(self, python_executable, otio_binding): | ||
"""Check if OTIO module is in Unreal's pip list. | ||
|
||
Check that otio is installed directly in Unreal's site-packages. | ||
It is possible that it is installed in user's site-packages but that | ||
may be incompatible with Unreal's python. | ||
""" | ||
|
||
otio_binding_low = otio_binding.lower() | ||
# Get pip list from Unreal's python executable | ||
args = [python_executable, "-m", "pip", "list"] | ||
process = subprocess.Popen(args, stdout=subprocess.PIPE) | ||
stdout, _ = process.communicate() | ||
lines = stdout.decode().split(os.linesep) | ||
# Second line contain dashes that define maximum length of module name. | ||
# Second column of dashes define maximum length of module version. | ||
package_dashes, *_ = lines[1].split(" ") | ||
package_len = len(package_dashes) | ||
|
||
# Got through printed lines starting at line 3 | ||
for idx in range(2, len(lines)): | ||
line = lines[idx] | ||
if not line: | ||
continue | ||
package_name = line[0:package_len].strip() | ||
if package_name.lower() == otio_binding_low: | ||
return True | ||
return False | ||
|
||
def find_parent_directory(self, file_path, target_dir="Binaries"): | ||
# Split the path into components | ||
path_components = file_path.split(os.sep) | ||
|
||
# Traverse the path components to find the target directory | ||
for i in range(len(path_components) - 1, -1, -1): | ||
if path_components[i] == target_dir: | ||
# Join the components to form the target directory path | ||
return os.sep.join(path_components[:i + 1]) | ||
return 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.