diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/configure.js | 61 | ||||
-rw-r--r-- | lib/videos.js | 2 |
2 files changed, 62 insertions, 1 deletions
diff --git a/lib/configure.js b/lib/configure.js new file mode 100644 index 0000000..9a5696a --- /dev/null +++ b/lib/configure.js @@ -0,0 +1,61 @@ +/* + * mongo-edu + * + * Copyright (c) 2014 Przemyslaw Pluta + * Licensed under the MIT license. + * https://github.com/przemyslawpluta/mongo-edu/blob/master/LICENSE + */ + +var fs = require('fs'), + path = require('path'), + which = require('which'); + +module.exports = function configure(argv, callback) { + + 'use strict'; + + var python = argv.py || process.env.PYTHON || 'python', + isWin = /^win/.test(process.platform); + + function checkPython() { + + which(python, function whichTest(err) { + if (err !== null) { + //console.log('`which` failed', python, err); + if (isWin) { guessPython(); } else { failNoPython(); } + } else { + //console.log('`which` succeeded', python, execPath); + process.env.PYTHON = python; + callback(null); + } + }); + } + + function guessPython() { + + console.log('Could not find "' + python + '". guessing location'); + + var rootDir = process.env.SystemDrive || 'C:\\', pythonPath; + + if (rootDir[rootDir.length - 1] !== '\\') { rootDir += '\\'; } + + pythonPath = path.resolve(rootDir, 'Python27', 'python.exe'); + console.log('ensuring that file exists:', pythonPath); + + fs.stat(pythonPath, function stat(err) { + if (err !== null) { + if (err.code === 'ENOENT') { failNoPython(); } else { callback(err); } + return; + } + python = pythonPath; + process.env.PYTHON = pythonPath; + callback(null); + }); + } + + function failNoPython() { + callback(new Error('Can\'t find Python executable "' + python + '", you can set the PYTHON env variable.')); + } + + checkPython(); +}; diff --git a/lib/videos.js b/lib/videos.js index d4ce7b4..9d2328b 100644 --- a/lib/videos.js +++ b/lib/videos.js @@ -262,7 +262,7 @@ module.exports = { setOptions(argv); - if (isWin) { options = ['python', [file].concat(args)]; } + if (isWin) { options = [process.env.PYTHON, [file].concat(args)]; } execFile(options[0], options[1], function(err, stdout, stderr) { if (err !== null) { return callback(err); } |