From 19667cdfdd9f237d0e7bb16922d96f3ea0b97556 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 19 Jan 2022 14:23:22 +0100 Subject: [PATCH] OP-2403 - added storing user email into env var collect_published_files is not triggered for studio processing in a host, must be passed through differently. --- .../plugins/publish/collect_username.py | 33 ++++++++----- openpype/pype_commands.py | 48 ++++++++++++------- 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/openpype/modules/default_modules/ftrack/plugins/publish/collect_username.py b/openpype/modules/default_modules/ftrack/plugins/publish/collect_username.py index 7ea1c1f323..d7d874f0a7 100644 --- a/openpype/modules/default_modules/ftrack/plugins/publish/collect_username.py +++ b/openpype/modules/default_modules/ftrack/plugins/publish/collect_username.py @@ -37,16 +37,27 @@ class CollectUsername(pyblish.api.ContextPlugin): os.environ["FTRACK_API_USER"] = os.environ["FTRACK_BOT_API_USER"] os.environ["FTRACK_API_KEY"] = os.environ["FTRACK_BOT_API_KEY"] - for instance in context: - email = instance.data["user_email"] - self.log.info("email:: {}".format(email)) - session = ftrack_api.Session(auto_connect_event_hub=False) - user = session.query("User where email like '{}'".format( - email)) + # for publishes with studio processing + user_email = os.environ.get("USER_EMAIL") + self.log.debug("Email from env:: {}".format(user_email)) + if not user_email: + # for basic webpublishes + for instance in context: + email = instance.data["user_email"] + self.log.debug("Email from instance:: {}".format(email)) + break - if not user: - raise ValueError( - "Couldnt find user with {} email".format(email)) + if not user_email: + self.log.info("No email found") + return - os.environ["FTRACK_API_USER"] = user[0].get("username") - break + session = ftrack_api.Session(auto_connect_event_hub=False) + user = session.query("User where email like '{}'".format(user_email)) + + if not user: + raise ValueError( + "Couldn't find user with {} email".format(user_email)) + + username = user[0].get("username") + self.log.debug("Resolved ftrack username:: {}".format(username)) + os.environ["FTRACK_API_USER"] = username diff --git a/openpype/pype_commands.py b/openpype/pype_commands.py index e25b56744e..c9612d8915 100644 --- a/openpype/pype_commands.py +++ b/openpype/pype_commands.py @@ -161,21 +161,32 @@ class PypeCommands: log.info("Publish finished.") @staticmethod - def remotepublishfromapp(project, batch_dir, host_name, - user, targets=None): + def remotepublishfromapp(project, batch_path, host_name, + user_email, targets=None): """Opens installed variant of 'host' and run remote publish there. - Currently implemented and tested for Photoshop where customer - wants to process uploaded .psd file and publish collected layers - from there. + Currently implemented and tested for Photoshop where customer + wants to process uploaded .psd file and publish collected layers + from there. - Checks if no other batches are running (status =='in_progress). If - so, it sleeps for SLEEP (this is separate process), - waits for WAIT_FOR seconds altogether. + Checks if no other batches are running (status =='in_progress). If + so, it sleeps for SLEEP (this is separate process), + waits for WAIT_FOR seconds altogether. - Requires installed host application on the machine. + Requires installed host application on the machine. - Runs publish process as user would, in automatic fashion. + Runs publish process as user would, in automatic fashion. + + Args: + project (str): project to publish (only single context is expected + per call of remotepublish + batch_path (str): Path batch folder. Contains subfolders with + resources (workfile, another subfolder 'renders' etc.) + host_name (str): 'photoshop' + user_email (string): email address for webpublisher - used to + find Ftrack user with same email + targets (list): Pyblish targets + (to choose validator for example) """ import pyblish.api from openpype.api import Logger @@ -185,9 +196,9 @@ class PypeCommands: log.info("remotepublishphotoshop command") - task_data = get_task_data(batch_dir) + task_data = get_task_data(batch_path) - workfile_path = os.path.join(batch_dir, + workfile_path = os.path.join(batch_path, task_data["task"], task_data["files"][0]) @@ -196,7 +207,7 @@ class PypeCommands: batch_id = task_data["batch"] dbcon = get_webpublish_conn() # safer to start logging here, launch might be broken altogether - _id = start_webpublish_log(dbcon, batch_id, user) + _id = start_webpublish_log(dbcon, batch_id, user_email) batches_in_progress = list(dbcon.find({"status": "in_progress"})) if len(batches_in_progress) > 1: @@ -219,10 +230,11 @@ class PypeCommands: print("env:: {}".format(env)) os.environ.update(env) - os.environ["OPENPYPE_PUBLISH_DATA"] = batch_dir + os.environ["OPENPYPE_PUBLISH_DATA"] = batch_path # must pass identifier to update log lines for a batch os.environ["BATCH_LOG_ID"] = str(_id) os.environ["HEADLESS_PUBLISH"] = 'true' # to use in app lib + os.environ["USER_EMAIL"] = user_email pyblish.api.register_host(host_name) if targets: @@ -247,7 +259,7 @@ class PypeCommands: time.sleep(0.5) @staticmethod - def remotepublish(project, batch_path, user, targets=None): + def remotepublish(project, batch_path, user_email, targets=None): """Start headless publishing. Used to publish rendered assets, workfiles etc. @@ -259,7 +271,8 @@ class PypeCommands: per call of remotepublish batch_path (str): Path batch folder. Contains subfolders with resources (workfile, another subfolder 'renders' etc.) - user (string): email address for webpublisher + user_email (string): email address for webpublisher - used to + find Ftrack user with same email targets (list): Pyblish targets (to choose validator for example) @@ -283,6 +296,7 @@ class PypeCommands: os.environ["OPENPYPE_PUBLISH_DATA"] = batch_path os.environ["AVALON_PROJECT"] = project os.environ["AVALON_APP"] = host_name + os.environ["USER_EMAIL"] = user_email pyblish.api.register_host(host_name) @@ -298,7 +312,7 @@ class PypeCommands: _, batch_id = os.path.split(batch_path) dbcon = get_webpublish_conn() - _id = start_webpublish_log(dbcon, batch_id, user) + _id = start_webpublish_log(dbcon, batch_id, user_email) publish_and_log(dbcon, _id, log)