utils/Abiword: use jshint

This commit is contained in:
booo 2011-12-22 13:32:36 +01:00
parent 11568b1278
commit 2a05f2d3df

View file

@ -17,7 +17,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
var util = require('util'); var util = require('util');
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
var async = require("async"); var async = require("async");
@ -35,7 +35,7 @@ if(os.type().indexOf("Windows") > -1)
{ {
//span an abiword process to perform the conversion //span an abiword process to perform the conversion
var abiword = spawn(settings.abiword, ["--to=" + task.destFile, task.srcFile]); var abiword = spawn(settings.abiword, ["--to=" + task.destFile, task.srcFile]);
//delegate the processing of stdout to another function //delegate the processing of stdout to another function
abiword.stdout.on('data', function (data) abiword.stdout.on('data', function (data)
{ {
@ -44,7 +44,7 @@ if(os.type().indexOf("Windows") > -1)
}); });
//append error messages to the buffer //append error messages to the buffer
abiword.stderr.on('data', function (data) abiword.stderr.on('data', function (data)
{ {
stdoutBuffer += data.toString(); stdoutBuffer += data.toString();
}); });
@ -52,19 +52,19 @@ if(os.type().indexOf("Windows") > -1)
//throw exceptions if abiword is dieing //throw exceptions if abiword is dieing
abiword.on('exit', function (code) abiword.on('exit', function (code)
{ {
if(code != 0) { if(code !== 0) {
throw "Abiword died with exit code " + code; throw "Abiword died with exit code " + code;
} }
if(stdoutBuffer != "") if(stdoutBuffer !== "")
{ {
console.log(stdoutBuffer); console.log(stdoutBuffer);
} }
callback(); callback();
}); });
} };
exports.convertFile = function(srcFile, destFile, type, callback) exports.convertFile = function(srcFile, destFile, type, callback)
{ {
doConvertTask({"srcFile": srcFile, "destFile": destFile, "type": type}, callback); doConvertTask({"srcFile": srcFile, "destFile": destFile, "type": type}, callback);
@ -78,13 +78,13 @@ else
var abiword = spawn(settings.abiword, ["--plugin", "AbiCommand"]); var abiword = spawn(settings.abiword, ["--plugin", "AbiCommand"]);
//append error messages to the buffer //append error messages to the buffer
abiword.stderr.on('data', function (data) abiword.stderr.on('data', function (data)
{ {
stdoutBuffer += data.toString(); stdoutBuffer += data.toString();
}); });
//throw exceptions if abiword is dieing //throw exceptions if abiword is dieing
abiword.on('exit', function (code) abiword.on('exit', function (code)
{ {
throw "Abiword died with exit code " + code; throw "Abiword died with exit code " + code;
}); });
@ -96,49 +96,49 @@ else
var stdoutBuffer = ""; var stdoutBuffer = "";
var firstPrompt = true; var firstPrompt = true;
function onAbiwordStdout(data) var onAbiwordStdout = function onAbiwordStdout(data)
{ {
//add data to buffer //add data to buffer
stdoutBuffer+=data.toString(); stdoutBuffer+=data.toString();
//we're searching for the prompt, cause this means everything we need is in the buffer //we're searching for the prompt, cause this means everything we need is in the buffer
if(stdoutBuffer.search("AbiWord:>") != -1) if(stdoutBuffer.search("AbiWord:>") != -1)
{ {
//filter the feedback message //filter the feedback message
var err = stdoutBuffer.search("OK") != -1 ? null : stdoutBuffer; var err = stdoutBuffer.search("OK") != -1 ? null : stdoutBuffer;
//reset the buffer //reset the buffer
stdoutBuffer = ""; stdoutBuffer = "";
//call the callback with the error message //call the callback with the error message
//skip the first prompt //skip the first prompt
if(stdoutCallback != null && !firstPrompt) if(stdoutCallback && !firstPrompt)
{ {
stdoutCallback(err); stdoutCallback(err);
stdoutCallback = null; stdoutCallback = null;
} }
firstPrompt = false; firstPrompt = false;
} }
} };
doConvertTask = function(task, callback) doConvertTask = function(task, callback)
{ {
abiword.stdin.write("convert " + task.srcFile + " " + task.destFile + " " + task.type + "\n"); abiword.stdin.write("convert " + task.srcFile + " " + task.destFile + " " + task.type + "\n");
//create a callback that calls the task callback and the caller callback //create a callback that calls the task callback and the caller callback
stdoutCallback = function (err) stdoutCallback = function (err)
{ {
callback(); callback();
task.callback(err); task.callback(err);
}; };
} };
//Queue with the converts we have to do //Queue with the converts we have to do
var queue = async.queue(doConvertTask, 1); var queue = async.queue(doConvertTask, 1);
exports.convertFile = function(srcFile, destFile, type, callback) exports.convertFile = function(srcFile, destFile, type, callback)
{ {
queue.push({"srcFile": srcFile, "destFile": destFile, "type": type, "callback": callback}); queue.push({"srcFile": srcFile, "destFile": destFile, "type": type, "callback": callback});
}; };
} }