1 | module.exports = function(hitler) {
|
2 | hitler.registerTask('copy', copy);
|
3 | hitler.registerTask('execute', execute);
|
4 | hitler.registerTask('executeScript', executeScript);
|
5 | }
|
6 |
|
7 | function copy(session, options, callback) {
|
8 | if(options.vars) {
|
9 | session.copy(options.src, options.dest, options.vars, sendCallback(callback));
|
10 | } else {
|
11 | session.copy(options.src, options.dest, sendCallback(callback));
|
12 | }
|
13 | }
|
14 |
|
15 | function execute(session, options, callback) {
|
16 | session.execute(options.command, sendCallback(callback));
|
17 | }
|
18 |
|
19 | function executeScript(session, options, callback) {
|
20 | session.executeScript(options.script, options.vars || {}, sendCallback(callback));
|
21 | }
|
22 |
|
23 | function sendCallback(callback) {
|
24 | return function(err, code, logs) {
|
25 | if (err) {
|
26 | callback(err);
|
27 | } else if(code !== 0) {
|
28 |
|
29 | var errorMessage = '\n-----------------------------------STDERR-----------------------------------\n';
|
30 | errorMessage += tail(logs.stderr);
|
31 | errorMessage += (errorMessage[errorMessage.length-1] != '\n')? '\n' : "";
|
32 | errorMessage += '-----------------------------------STDOUT-----------------------------------\n';
|
33 | errorMessage += tail(logs.stdout);
|
34 | errorMessage += (errorMessage[errorMessage.length-1] != '\n')? '\n' : "";
|
35 | errorMessage += '----------------------------------------------------------------------------';
|
36 |
|
37 | callback(new Error(errorMessage));
|
38 | } else {
|
39 | callback();
|
40 | }
|
41 | };
|
42 |
|
43 | function tail(str) {
|
44 | if(str) {
|
45 | return str.substring(str.length-1000);
|
46 | } else {
|
47 | return "";
|
48 | }
|
49 | }
|
50 | } |
\ | No newline at end of file |