Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50659 views
1
//----------------------------------------------------------------------------
2
// Copyright (C) 2013 The IPython Development Team
3
//
4
// Distributed under the terms of the BSD License. The full license is in
5
// the file COPYING, distributed as part of this software.
6
//----------------------------------------------------------------------------
7
8
//============================================================================
9
// Notebook
10
//============================================================================
11
12
var IPython = (function (IPython) {
13
"use strict";
14
15
var utils = IPython.utils;
16
17
var Session = function(notebook, options){
18
this.kernel = null;
19
this.id = null;
20
this.notebook = notebook;
21
this.name = notebook.notebook_name;
22
this.path = notebook.notebook_path;
23
this.base_url = notebook.base_url;
24
};
25
26
Session.prototype.start = function(callback) {
27
var that = this;
28
var model = {
29
notebook : {
30
name : this.name,
31
path : this.path
32
}
33
};
34
var settings = {
35
processData : false,
36
cache : false,
37
type : "POST",
38
data: JSON.stringify(model),
39
dataType : "json",
40
success : function (data, status, xhr) {
41
that._handle_start_success(data);
42
if (callback) {
43
callback(data, status, xhr);
44
}
45
},
46
error : utils.log_ajax_error,
47
};
48
var url = utils.url_join_encode(this.base_url, 'api/sessions');
49
$.ajax(url, settings);
50
};
51
52
Session.prototype.rename_notebook = function (name, path) {
53
this.name = name;
54
this.path = path;
55
var model = {
56
notebook : {
57
name : this.name,
58
path : this.path
59
}
60
};
61
var settings = {
62
processData : false,
63
cache : false,
64
type : "PATCH",
65
data: JSON.stringify(model),
66
dataType : "json",
67
error : utils.log_ajax_error,
68
};
69
var url = utils.url_join_encode(this.base_url, 'api/sessions', this.id);
70
$.ajax(url, settings);
71
};
72
73
Session.prototype.delete = function() {
74
var settings = {
75
processData : false,
76
cache : false,
77
type : "DELETE",
78
dataType : "json",
79
error : utils.log_ajax_error,
80
};
81
this.kernel.running = false;
82
var url = utils.url_join_encode(this.base_url, 'api/sessions', this.id);
83
$.ajax(url, settings);
84
};
85
86
// Kernel related things
87
/**
88
* Create the Kernel object associated with this Session.
89
*
90
* @method _handle_start_success
91
*/
92
Session.prototype._handle_start_success = function (data, status, xhr) {
93
this.id = data.id;
94
var kernel_service_url = utils.url_path_join(this.base_url, "api/kernels");
95
this.kernel = new IPython.Kernel(kernel_service_url);
96
this.kernel._kernel_started(data.kernel);
97
};
98
99
/**
100
* Prompt the user to restart the IPython kernel.
101
*
102
* @method restart_kernel
103
*/
104
Session.prototype.restart_kernel = function () {
105
this.kernel.restart();
106
};
107
108
Session.prototype.interrupt_kernel = function() {
109
this.kernel.interrupt();
110
};
111
112
113
Session.prototype.kill_kernel = function() {
114
this.kernel.kill();
115
};
116
117
IPython.Session = Session;
118
119
return IPython;
120
121
}(IPython));
122
123