-
Notifications
You must be signed in to change notification settings - Fork 9
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
Process preparation: Ftrack addon can ensure that is process ready #109
Merged
iLLiCiTiT
merged 16 commits into
develop
from
feature/AY-6023_Addon-ftrack-implements-addon-initialization
Aug 21, 2024
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3b24935
ftrack addon can ensure that is process ready
iLLiCiTiT 50fe3af
use username from credentials method
iLLiCiTiT 3d933cd
use add sys paths and creation flags
iLLiCiTiT 4295c16
Merge branch 'develop' into feature/AY-6023_Addon-ftrack-implements-a…
iLLiCiTiT 7fe0040
post credentials to tray if is running
iLLiCiTiT b2affb0
Merge branch 'develop' into feature/AY-6023_Addon-ftrack-implements-a…
iLLiCiTiT f4b713a
remove unused import
iLLiCiTiT 14c1101
ignore unused variable
iLLiCiTiT d9339b6
save credentials if were requested
iLLiCiTiT e6f9ab3
also import check_credentials
iLLiCiTiT a72e277
fix validate method
iLLiCiTiT d46996e
fix credentials handler
iLLiCiTiT 9dcbdd1
Merge branch 'develop' into feature/AY-6023_Addon-ftrack-implements-a…
iLLiCiTiT 4eb7af6
Merge branch 'develop' into feature/AY-6023_Addon-ftrack-implements-a…
iLLiCiTiT 947d6c1
use better messages
iLLiCiTiT c6368fb
Merge branch 'develop' into feature/AY-6023_Addon-ftrack-implements-a…
iLLiCiTiT 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,13 +1,24 @@ | ||||||||
import os | ||||||||
import tempfile | ||||||||
import json | ||||||||
|
||||||||
import requests | ||||||||
import ayon_api | ||||||||
|
||||||||
from ayon_core.addon import ( | ||||||||
AYONAddon, | ||||||||
ITrayAddon, | ||||||||
IPluginPaths, | ||||||||
) | ||||||||
from ayon_core.lib import Logger | ||||||||
from ayon_core.lib import Logger, run_ayon_launcher_process | ||||||||
from ayon_core.settings import get_project_settings, get_studio_settings | ||||||||
from ayon_core.tools.tray import get_tray_server_url | ||||||||
|
||||||||
from ayon_ftrack.lib.credentials import ( | ||||||||
save_credentials, | ||||||||
get_credentials, | ||||||||
check_credentials, | ||||||||
) | ||||||||
|
||||||||
from .version import __version__ | ||||||||
|
||||||||
|
@@ -44,6 +55,9 @@ def initialize(self, settings): | |||||||
self.timers_manager_connector = None | ||||||||
self._timers_manager_addon = None | ||||||||
|
||||||||
def webserver_initialization(self, web_manager): | ||||||||
self._tray_wrapper.webserver_initialization(web_manager) | ||||||||
|
||||||||
def get_ftrack_url(self): | ||||||||
"""Resolved ftrack url. | ||||||||
|
||||||||
|
@@ -140,8 +154,7 @@ def create_ftrack_session(self, **session_kwargs): | |||||||
api_user = os.environ.get("FTRACK_API_USER") | ||||||||
|
||||||||
if not api_key or not api_user: | ||||||||
from .lib import credentials | ||||||||
cred = credentials.get_credentials() | ||||||||
cred = get_credentials() | ||||||||
api_user = cred.get("username") | ||||||||
api_key = cred.get("api_key") | ||||||||
|
||||||||
|
@@ -178,6 +191,72 @@ def stop_timer(self): | |||||||
if self._tray_wrapper: | ||||||||
self._tray_wrapper.stop_timer_manager() | ||||||||
|
||||||||
def ensure_is_process_ready(self, context): | ||||||||
"""Ensure addon is ready for process. | ||||||||
|
||||||||
Args: | ||||||||
context (ProcessContext): Process context. | ||||||||
|
||||||||
""" | ||||||||
# Safe to support older ayon-core without 'ProcessPreparationError' | ||||||||
from ayon_core.addon import ProcessPreparationError | ||||||||
from ayon_ftrack.common import is_ftrack_enabled_in_settings | ||||||||
|
||||||||
# Do not continue if Ftrack is not enabled in settings | ||||||||
if context.project_name: | ||||||||
settings = get_project_settings(context.project_name) | ||||||||
else: | ||||||||
settings = get_studio_settings() | ||||||||
|
||||||||
if not is_ftrack_enabled_in_settings(settings): | ||||||||
return | ||||||||
|
||||||||
# Not sure if this should crash or silently continue? | ||||||||
server_url = self.get_ftrack_url() | ||||||||
if not server_url: | ||||||||
return | ||||||||
|
||||||||
username = os.getenv("FTRACK_API_USER") | ||||||||
api_key = os.getenv("FTRACK_API_KEY") | ||||||||
|
||||||||
if ( | ||||||||
username and api_key | ||||||||
and check_credentials(username, api_key, server_url) | ||||||||
): | ||||||||
self.set_credentials_to_env(username, api_key) | ||||||||
return | ||||||||
|
||||||||
username, api_key = self.get_credentials() | ||||||||
if ( | ||||||||
username and api_key | ||||||||
and check_credentials(username, api_key, server_url) | ||||||||
): | ||||||||
self.set_credentials_to_env(username, api_key) | ||||||||
return | ||||||||
|
||||||||
if context.headless: | ||||||||
raise ProcessPreparationError( | ||||||||
"Ftrack credentials are not set. Cannot handle the situation" | ||||||||
" in headless mode." | ||||||||
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.
Suggested change
|
||||||||
) | ||||||||
|
||||||||
username, api_key = self._ask_for_credentials(server_url) | ||||||||
if username and api_key: | ||||||||
self.set_credentials_to_env(username, api_key) | ||||||||
# Send the credentials to the running tray | ||||||||
save_credentials(username, api_key, self.get_ftrack_url()) | ||||||||
tray_url = get_tray_server_url() | ||||||||
if tray_url: | ||||||||
requests.post( | ||||||||
f"{tray_url}/addons/ftrack/credentials", | ||||||||
json={"username": username, "api_key": api_key}, | ||||||||
) | ||||||||
return | ||||||||
|
||||||||
raise ProcessPreparationError( | ||||||||
"Failed to log to ftrack. Cannot continue with the process." | ||||||||
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. 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.
Suggested change
|
||||||||
) | ||||||||
|
||||||||
def register_timers_manager(self, timers_manager_addon): | ||||||||
self._timers_manager_addon = timers_manager_addon | ||||||||
|
||||||||
|
@@ -212,11 +291,33 @@ def get_task_time(self, project_name, folder_path, task_name): | |||||||
def get_credentials(self): | ||||||||
# type: () -> tuple | ||||||||
"""Get local Ftrack credentials.""" | ||||||||
from .lib import credentials | ||||||||
|
||||||||
cred = credentials.get_credentials(self.ftrack_url) | ||||||||
cred = get_credentials(self.ftrack_url) | ||||||||
return cred.get("username"), cred.get("api_key") | ||||||||
|
||||||||
@staticmethod | ||||||||
def _ask_for_credentials(ftrack_url): | ||||||||
login_script = os.path.join( | ||||||||
FTRACK_ADDON_DIR, "tray", "login_dialog.py" | ||||||||
) | ||||||||
with tempfile.NamedTemporaryFile( | ||||||||
mode="w", prefix="ay_ftrack", suffix=".json", delete=False | ||||||||
) as tmp: | ||||||||
json_path = tmp.name | ||||||||
json.dump({"server_url": ftrack_url}, tmp.file) | ||||||||
|
||||||||
run_ayon_launcher_process( | ||||||||
"--skip-bootstrap", | ||||||||
login_script, json_path, | ||||||||
add_sys_paths=True, | ||||||||
creationflags=0, | ||||||||
|
||||||||
) | ||||||||
|
||||||||
with open(json_path, "r") as stream: | ||||||||
data = json.load(stream) | ||||||||
return data.get("username"), data.get("api_key") | ||||||||
|
||||||||
|
||||||||
def _check_ftrack_url(url): | ||||||||
import requests | ||||||||
|
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
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.
This needs some artist friendly message. Marking @BigRoy and @mkolar for suggestions.