From 640d0135fdf256953d0aa13bb019bdd141a2ad5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Samohel?= Date: Wed, 22 Apr 2020 18:42:54 +0200 Subject: [PATCH] fixed output of publish json --- .../premiere/extensions/com.pype/jsx/pype.jsx | 26 +++++------ pype/premiere/ppro/js/pype.js | 43 +++++++++++++------ pype/premiere/ppro/js/pype_restapi_client.js | 4 +- .../adobe_communicator/lib/rest_api.py | 4 +- pype/services/rest_api/lib/handler.py | 9 +++- 5 files changed, 57 insertions(+), 29 deletions(-) diff --git a/pype/premiere/extensions/com.pype/jsx/pype.jsx b/pype/premiere/extensions/com.pype/jsx/pype.jsx index 353342c677..43c791ea75 100644 --- a/pype/premiere/extensions/com.pype/jsx/pype.jsx +++ b/pype/premiere/extensions/com.pype/jsx/pype.jsx @@ -919,7 +919,7 @@ $.pype = { $.pype.log('__ representations: ' + representations); instances[i].files = []; for (var key in representations) { - + $.pype.log('representation: ' + key); // send render jobs to encoder var exclude = ['projectfile', 'thumbnail']; if (!include(exclude, key)) { @@ -955,14 +955,13 @@ $.pype = { } // test if expected job list is empty. If so, emit event for JS - /* - if (len($.pype.expectedJobs) == 0) { + if ($.pype.expectedJobs.length == 0) { + $.pype.log("encoding jobs finished."); var eventObj = new CSXSEvent(); eventObj.type = 'pype.EncoderJobsComplete'; eventObj.data = {"jobID": jobID, "outputFilePath": outputFilePath}; eventObj.dispatch(); } - */ }, render: function (outputPath, family, representation, clipName, version, inPoint, outPoint) { @@ -972,8 +971,8 @@ $.pype = { ]).join($._PPP_.getSep()); app.enableQE(); - var activeSequence = qe.project.getActiveSequence(); // we use a QE DOM function, to determine the output extension. - $.pype.log("launching encoder ..."); + var activeSequence = $.pype.getActiveSequence(); + $.pype.log("launching encoder ... " + family + " " + clipName); if (activeSequence) { app.encoder.launchEncoder(); // This can take a while; let's get the ball rolling. @@ -999,19 +998,22 @@ $.pype = { } } - app.encoder.bind('onEncoderJobComplete', $._PPP_.onEncoderJobComplete); - // app.encoder.bind('onEncoderJobComplete', $.pype.onEncoderJobComplete); - app.encoder.bind('onEncoderJobError', $._PPP_.onEncoderJobError); - app.encoder.bind('onEncoderJobProgress', $._PPP_.onEncoderJobProgress); - app.encoder.bind('onEncoderJobQueued', $._PPP_.onEncoderJobQueued); - app.encoder.bind('onEncoderJobCanceled', $._PPP_.onEncoderJobCanceled); + $.pype.log("binding events ..."); + // app.encoder.bind('onEncoderJobComplete', $._PPP_.onEncoderJobComplete); + app.encoder.bind('onEncoderJobComplete', $.pype.onEncoderJobComplete); + // app.encoder.bind('onEncoderJobError', $._PPP_.onEncoderJobError); + // app.encoder.bind('onEncoderJobProgress', $._PPP_.onEncoderJobProgress); + // app.encoder.bind('onEncoderJobQueued', $._PPP_.onEncoderJobQueued); + // app.encoder.bind('onEncoderJobCanceled', $._PPP_.onEncoderJobCanceled); // use these 0 or 1 settings to disable some/all metadata creation. app.encoder.setSidecarXMPEnabled(0); app.encoder.setEmbeddedXMPEnabled(0); + $.pype.log("adding job to encoder"); var jobID = app.encoder.encodeSequence(app.project.activeSequence, fullPathToFile, outPreset.fsName, app.encoder.ENCODE_IN_TO_OUT, 1); // Remove from queue upon successful completion? $.pype.expectedJobs.push(jobID); + $.pype.log("job queue length: " + $.pype.expectedJobs.length); $._PPP_.updateEventPanel('jobID = ' + jobID); outPreset.close(); return file; diff --git a/pype/premiere/ppro/js/pype.js b/pype/premiere/ppro/js/pype.js index 202d0b3398..d671b437c4 100644 --- a/pype/premiere/ppro/js/pype.js +++ b/pype/premiere/ppro/js/pype.js @@ -140,6 +140,13 @@ class Pype { if (result == "EvalScript error.") { reject(result); } + console.log("encoding submitted ..."); + const jsonfile = require('jsonfile'); + let jsonContent = JSON.parse(result); + if (self.publishUI.jsonSendPath == "") { + self.publishUI.jsonSendPath = self.stagingDir + "\\publish.json"; + } + jsonfile.writeFile(self.publishUI.jsonSendPath, jsonContent); resolve(result); }); }); @@ -183,6 +190,7 @@ class Pype { }, error => { console.error(`failed to publish: ${error}`); }); + console.log("waiting for result"); }); } else { // load request @@ -205,36 +213,43 @@ class Pype { } _encodingDone(event) { + // this will be global in this context + console.log("Event recieved ..."); var dataToPublish = { - "adobePublishJsonPathSend": this.publishUI.jsonSendPath, - "adobePublishJsonPathGet": this.publishUI.jsonGetPath, + "adobePublishJsonPathSend": this.pype.publishUI.jsonSendPath, + "adobePublishJsonPathGet": this.pype.publishUI.jsonGetPath, "gui": true, - "publishPath": Pype.convertPathString(this.env.PUBLISH_PATH), - "project": this.env.AVALON_PROJECT, - "asset": this.env.AVALON_ASSET, - "task": this.env.AVALON_TASK, - "workdir": Pype.convertPathString(this.env.ENV.AVALON_WORKDIR), - "host": this.env.ENV.AVALON_APP + // "publishPath": Pype.convertPathString(this.pype.env.PUBLISH_PATH), + "project": this.pype.env.AVALON_PROJECT, + "asset": this.pype.env.AVALON_ASSET, + "task": this.pype.env.AVALON_TASK, + "workdir": Pype.convertPathString(this.pype.env.AVALON_WORKDIR), + "host": this.pype.env.AVALON_APP } - this.pras.publish(dataToPublish) + console.log("Preparing publish ..."); + this.pype.pras.publish(JSON.stringify(dataToPublish)) .then((result) => { const fs = require('fs'); if (fs.existsSync(result.return_data_path)) { - if (this.publishUI.versionUp) { + if (this.pype.publishUI.versionUp) { console.log('Saving new version of the project file'); - this.csi.evalScript('$.pype.versionUpWorkFile();'); + this.pype.csi.evalScript('$.pype.versionUpWorkFile();'); } + console.log("Publishing done."); } else { console.error("Publish has not finished correctly") throw "Publish has not finished correctly"; } + }, (error) => { + console.error("Invalid response from server"); + console.error(error); }); } } - -$(document).ready(function() { - new Pype(); +$(function() { + global.pype = new Pype(); }); + // ------------------------------------------------------- diff --git a/pype/premiere/ppro/js/pype_restapi_client.js b/pype/premiere/ppro/js/pype_restapi_client.js index eb03e28cdf..fdd06685b5 100644 --- a/pype/premiere/ppro/js/pype_restapi_client.js +++ b/pype/premiere/ppro/js/pype_restapi_client.js @@ -59,9 +59,11 @@ class PypeRestApiClient { let headers = { "Content-Type": "application/json" } - + console.log("connecting ..."); let response = await this.getResponseFromRestApiServer( url, {method: 'POST', headers: headers, body: data}); + console.log("got response:"); + console.log(response.data); return response.data; } } diff --git a/pype/services/adobe_communicator/lib/rest_api.py b/pype/services/adobe_communicator/lib/rest_api.py index d6562f1b12..4611ca39dc 100644 --- a/pype/services/adobe_communicator/lib/rest_api.py +++ b/pype/services/adobe_communicator/lib/rest_api.py @@ -1,4 +1,5 @@ import os +import sys import copy from pype.services.rest_api import RestApi, route, abort, CallbackResult from .io_nonsingleton import DbConnector @@ -57,7 +58,8 @@ class AdobeRestApi(RestApi): try: # Trigger subprocess # QUESTION should we check returncode? - returncode = execute(PUBLISH_SCRIPT_PATH, env=publish_env) + returncode = execute( + [sys.executable, PUBLISH_SCRIPT_PATH], env=publish_env) # Check if output file exists if returncode != 0 or not os.path.exists(output_data_path): diff --git a/pype/services/rest_api/lib/handler.py b/pype/services/rest_api/lib/handler.py index 732061c005..dc94808237 100644 --- a/pype/services/rest_api/lib/handler.py +++ b/pype/services/rest_api/lib/handler.py @@ -252,7 +252,14 @@ class Handler(http.server.SimpleHTTPRequestHandler): content_length = int(cont_len) in_data_str = self.rfile.read(content_length) if in_data_str: - in_data = json.loads(in_data_str) + try: + in_data = json.loads(in_data_str) + except Exception as e: + log.error("Invalid JSON recieved:") + log.error("-" * 80) + log.error(in_data_str) + log.error("-" * 80) + raise Exception("Invalid JSON recieved") from e request_info = RequestInfo( url_data=url_data,