Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions excelParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/));
Expand All @@ -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) {
Expand Down Expand Up @@ -64,4 +64,8 @@ excelParser.parse = function(options, cb) {
}
});
};

excelParser.config = function(config){
utils.config(config);
};
module.exports = excelParser;
43 changes: 31 additions & 12 deletions utils.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -119,4 +134,8 @@ utils.pickRecords = function(args, options, cb) {
});
};

exports.utils = utils;
utils.config = function(config){
_config = config
};

exports.utils = utils;