1
1
var spawn = require ( 'child_process' ) . spawn ,
2
+ ws_helper = require ( './websocket_helper' ) ,
2
3
//pty = require('pty.js'),
3
4
path = require ( 'path' ) ,
4
5
ipython , spawn_list = [ ] ;
@@ -54,12 +55,12 @@ function execute_python_trace(file_path, socket) {
54
55
} ) ;
55
56
56
57
prog . stderr . on ( 'data' , function ( data ) {
57
- socket . emit ( 'trace-program-stderr' , { output : data . toString ( ) } ) ;
58
+ ws_helper . send_message ( socket , 'trace-program-stderr' , { output : data . toString ( ) } ) ;
58
59
console . log ( data . toString ( ) ) ;
59
60
} ) ;
60
61
61
62
prog . on ( 'exit' , function ( code ) {
62
- socket . emit ( 'trace-program-exit' , { output : program_output } ) ;
63
+ ws_helper . send_message ( socket , 'trace-program-exit' , { output : program_output } ) ;
63
64
} ) ;
64
65
}
65
66
@@ -68,16 +69,16 @@ function execute_python_trace(file_path, socket) {
68
69
ipython.removeAllListeners('data');
69
70
require('../server').get_socket(file.username, function(socket) {
70
71
if (is_job) {
71
- socket.emit( 'scheduler-start', {file: file});
72
+ ws_helper.send_message(socket, 'scheduler-start', {file: file});
72
73
}
73
74
ipython.on('data', function(data) {
74
75
console.log(data);
75
76
//data = data.replace(/\[0;.*?In\s\[.*?\[0m/, '~-prompt-~');
76
77
//data = data.replace(/In\s\[.*?\]:/, '~-prompt-~');
77
78
if (is_job) {
78
- socket.emit( 'scheduler-executing', {file: file});
79
+ ws_helper.send_message(socket, 'scheduler-executing', {file: file});
79
80
} else {
80
- socket.emit( 'program-stdout', {output: data});
81
+ ws_helper.send_message(socket, 'program-stdout', {output: data});
81
82
}
82
83
});
83
84
});
@@ -117,26 +118,26 @@ function execute_program(file, type, is_job) {
117
118
118
119
function handle_output ( prog , file , is_job , socket ) {
119
120
if ( is_job ) {
120
- socket . emit ( 'scheduler-start' , { file : file } ) ;
121
+ ws_helper . send_message ( socket , 'scheduler-start' , { file : file } ) ;
121
122
}
122
123
123
124
prog . stdout . on ( 'data' , function ( data ) {
124
125
if ( is_job ) {
125
126
console . log ( data . toString ( ) ) ;
126
- socket . emit ( 'scheduler-executing' , { file : file } ) ;
127
+ ws_helper . send_message ( socket , 'scheduler-executing' , { file : file } ) ;
127
128
} else {
128
129
console . log ( data . toString ( ) ) ;
129
- socket . emit ( 'program-stdout' , { output : data . toString ( ) } ) ;
130
+ ws_helper . send_message ( socket , 'program-stdout' , { output : data . toString ( ) } ) ;
130
131
}
131
132
} ) ;
132
133
133
134
prog . stderr . on ( 'data' , function ( data ) {
134
135
if ( is_job ) {
135
136
console . log ( data . toString ( ) ) ;
136
- socket . emit ( 'scheduler-error' , { file : file , error : data } ) ;
137
+ ws_helper . send_message ( socket , 'scheduler-error' , { file : file , error : data } ) ;
137
138
} else {
138
139
console . log ( data . toString ( ) ) ;
139
- socket . emit ( 'program-stderr' , { output : data . toString ( ) } ) ;
140
+ ws_helper . send_message ( socket , 'program-stderr' , { output : data . toString ( ) } ) ;
140
141
}
141
142
} ) ;
142
143
@@ -149,9 +150,9 @@ function handle_output(prog, file, is_job, socket) {
149
150
}
150
151
151
152
if ( is_job ) {
152
- socket . emit ( 'scheduler-exit' , { code : code , file : file } ) ;
153
+ ws_helper . send_message ( socket , 'scheduler-exit' , { code : code , file : file } ) ;
153
154
} else {
154
- socket . emit ( 'program-exit' , { code : code } ) ;
155
+ ws_helper . send_message ( socket , 'program-exit' , { code : code } ) ;
155
156
}
156
157
157
158
} ) ;
0 commit comments