-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathkernelApi.js
More file actions
68 lines (63 loc) · 2.43 KB
/
kernelApi.js
File metadata and controls
68 lines (63 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
define([
'require'
, 'jquery'
, 'nbextensions/visualpython/src/common/constant'
, 'nbextensions/visualpython/src/common/StringBuilder'
, 'nbextensions/visualpython/src/common/vpCommon'
], function (requirejs, $, vpConst, sb, vpCommon) {
/**
* Execute python kernel
* @param {*} command
* @param {*} callback
* @param {*} isSilent
*/
var executePython = function (command, callback, isSilent = false) {
Jupyter.notebook.kernel.execute(
command,
{
iopub: {
output: function (msg) {
if (msg.content) {
if (msg.content['name'] == 'stderr') {
;
} else {
var result = '';
var type = '';
if (msg.content['text']) {
result = String(msg.content['text']);
type = 'text';
} else if (msg.content.data) {
if (msg.content.data['text/plain']) {
result = String(msg.content.data['text/plain']);
type = 'text/plain';
} else if (msg.content.data['text/html']) {
result = String(msg.content.data['text/html']);
type = 'text/html';
}
}
callback(result, type);
}
}
}
}
},
{ silent: isSilent }
);
};
var searchVarList = function(types, callback) {
// types에 맞는 변수목록 조회하는 명령문 구성
var cmdSB = new sb.StringBuilder();
if (types && types.length > 0) {
cmdSB.appendFormat('_vp_print(_vp_get_variables_list({0}))', JSON.stringify(types));
} else {
cmdSB.appendFormat('_vp_print(_vp_get_variables_list({0}))', 'None');
}
executePython(cmdSB.toString(), function(result) {
callback(result);
});
}
return {
executePython: executePython,
searchVarList: searchVarList
}
});