diff --git a/README.md b/README.md index 60a9429..9cd92fe 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,13 @@ __Sample output__ ['1', 'cole', 'City of Industry'] ] ``` +## Notes + +If you are executing this package in non-shell based environment, you would have to pass the python path. +```javascript +excelParser.config({python: '/usr/bin/python'}) +``` + ## Running Tests diff --git a/excelParser.js b/excelParser.js index 058f2d1..a3cb4c6 100644 --- a/excelParser.js +++ b/excelParser.js @@ -13,7 +13,7 @@ excelParser.worksheets = function(options, cb) { fs.exists(options.inFile, function(exists) { if(!exists) return cb("File not found"); - args = ['-x', '"'+path.relative(__dirname, options.inFile)+'"', '-W']; + args = ['-x', path.relative(__dirname, options.inFile), '-W']; utils.execute(args, function(err, stdout) { if(err) return cb(err); worksheets = _.compact(stdout.split(/\n/)); @@ -30,7 +30,7 @@ excelParser.parse = function(options, cb) { else if(!options.inFile) return cb("File is missing in arguments"); fs.exists(options.inFile, function(exists) { if(!exists) return cb("File not found"); - args = ['-x', '"'+path.relative(__dirname, options.inFile)+'"']; + args = ['-x', path.relative(__dirname, options.inFile)]; if(!options.worksheet) { var records = []; _this.worksheets(options, function(err, worksheets) { @@ -64,4 +64,8 @@ excelParser.parse = function(options, cb) { } }); }; + +excelParser.config = function(config){ + utils.config(config); +}; module.exports = excelParser; \ No newline at end of file diff --git a/utils.js b/utils.js index 6ff1bf5..f5a37bf 100644 --- a/utils.js +++ b/utils.js @@ -1,11 +1,12 @@ var _ = require('underscore'), async = require('async'), + execFile = require('child_process').execFile, exec = require('child_process').exec, fs = require('fs'), path = require('path'), temp = require('temp'), utils = {}, - _this = this; + _config = {}; var _CRCsv = function(args, cb) { temp.mkdir('temp', function(err, dirPath) { @@ -94,16 +95,30 @@ var _searchInArray = function(records, options, cb) { }; utils.execute = function(args, cb) { - var cmd = ["python", __dirname + "/convert.py"]; - cmd = cmd.concat(args); - exec( - cmd.join(' '), - {cwd: __dirname}, - function(err, stdout, stderr) { - if(err || stderr) return cb(err.toString() + stderr.toString()); - cb(null, stdout); - } - ); + if(_config.python) { + var cmd = [__dirname + "/convert.py"]; + cmd = cmd.concat(args); + execFile( + _config.python, + cmd, + {cwd: __dirname}, + function(err, stdout, stderr) { + if(err || stderr) return cb(err.toString() + stderr.toString()); + cb(null, stdout); + } + ); + }else{ + var cmd = ["python", __dirname + "/convert.py"]; + cmd = cmd.concat(args); + exec( + cmd.join(' '), + {cwd: __dirname}, + function(err, stdout, stderr) { + if(err || stderr) return cb(err.toString() + stderr.toString()); + cb(null, stdout); + } + ); + } }; utils.pickRecords = function(args, options, cb) { @@ -119,4 +134,8 @@ utils.pickRecords = function(args, options, cb) { }); }; -exports.utils = utils; \ No newline at end of file +utils.config = function(config){ + _config = config +}; + +exports.utils = utils;