[TIC-UI] fix the output image path
[archive/20170607/tools/tic.git] / server / fs / mic.js
1 'use strict';
2 /**
3  * using websocket
4  */
5
6 var fs = require('fs');
7 var path = require('path');
8 var exec = require('child_process').exec;
9 var util = require('util');
10
11 var Mic = {};
12
13 Mic.subprocess = function (processname, cb) {
14     var p = exec(processname);
15     p.on('exit', cb.exit);
16     p.stdout.on('data', cb.stdout || function (out) {
17         process.stdout.write(out);
18     });
19     p.stderr.on('data', cb.stderr || function (err) {
20         process.stdout.write(err);
21     });
22 };
23
24 Mic.create = function (paramObj, client) {
25     console.log('Mic.create called');
26
27     var stdoutPath = 'ws/fs/image/add/to';
28     var exitPath = 'ws/fs/image/add/finished';
29     var micProcess = 'sudo mic cr loop ' + paramObj.pathKsFile + util.format(' -A %s', 'x86_64') + util.format(' -o %s', paramObj.pathOutput);
30
31     function sendMsg(path, msg) {
32         client.emit(path, msg);
33     }
34
35     Mic.subprocess(micProcess, {
36         stdout: function (out) {
37             console.log(out);
38             sendMsg(stdoutPath, out);
39         },
40         stderr: function (out) {
41             console.error(out);
42             sendMsg(stdoutPath, out);
43         },
44         exit: function (out) {
45             console.log(out);
46             sendMsg(exitPath, out);
47         }
48     });
49 };
50
51 module.exports = Mic;