fixed output of publish json

This commit is contained in:
Ondřej Samohel 2020-04-22 18:42:54 +02:00
parent 70bb4b0a5d
commit 640d0135fd
No known key found for this signature in database
GPG key ID: 8A29C663C672C2B7
5 changed files with 57 additions and 29 deletions

View file

@ -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;

View file

@ -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();
});
// -------------------------------------------------------

View file

@ -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;
}
}

View file

@ -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):

View file

@ -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,