So, one of the things I’m working on that people around here might find useful, is a bridge between python and a CEP panel. I’m using https://www.npmjs.com/package/python-shell, so my CEP js has:
python_shell = require('python-shell')
$scope.helloPython = function() {
var myExtID = csInterface.getExtensionID();
var basePath = undefined;
var extensions = csInterface.getExtensions();
for (var i = 0; i<extensions.length; i++) {
if(extensions[i].id === myExtID) {
basePath = extensions[i].basePath;
}
}
console.log(basePath);
var pythonPath = node_path.join(basePath, 'python');
var options = {
mode: 'json',
// pythonPath: 'path/to/python',
// pythonOptions: ['-u'],
scriptPath: pythonPath,
args: ['value1', 'value2', 'value3']
};
myurl = node_url.parse($scope.curDoc);
mypath2 = myurl.path;
console.log(mypath2);
mypath = node_path.normalize($scope.curDoc).split(node_path.sep);
console.dir(mypath);
var pyshell = new python_shell('test_connection.py', options);
// sends a message to the Python script via stdin
pyshell.send($scope.curDoc);
pyshell.send(mypath);
pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
console.log(message);
handlePyMessage(message);
});
// end the input stream and allow the process to exit
pyshell.end(function (err) {
if (err) throw err;
console.log('finished');
});
};
This in turn calls a simple python script (included in a python folder in my extension)
import P4
p4 = P4.P4()
p4.connect()
print json.dumps(p4.run_info())
I can clean up the code and release a small demo if people are interested, but that’s the gist of the workflow