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