summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/configure.js61
-rw-r--r--lib/videos.js2
-rw-r--r--mongo-edu.js9
-rw-r--r--package.json20
4 files changed, 81 insertions, 11 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); }
diff --git a/mongo-edu.js b/mongo-edu.js
index f6dc0ca..5693ee5 100644
--- a/mongo-edu.js
+++ b/mongo-edu.js
@@ -9,6 +9,7 @@
var mdbvideos = require('./lib/login'),
videoHandler = require('./lib/videos'),
validate = require('./lib/validate'),
+ configure = require('./lib/configure'),
path = require('path'),
colors = require('colors'),
inquirer = require('inquirer'),
@@ -16,6 +17,7 @@ var mdbvideos = require('./lib/login'),
.usage('Usage: $0 [options]')
.describe('d', 'download path').describe('u', 'email address')
.describe('h', 'switch from videos (default) to handouts').boolean('h')
+ .describe('py', 'pass python').describe('py', 'python')
.describe('cw', 'switch from wiki\'s video lists (default) to courseware').boolean('cw')
.describe('cwd', 'same as --cw and dumps list of videos to file in -d').boolean('cwd')
.describe('cc', 'get closed captions').boolean('cc')
@@ -39,7 +41,12 @@ exports.create = function start() {
validate.init(argv, function (err, profile) {
if (err !== null) { throw err; }
- run(profile);
+
+ configure(argv, function conf(err) {
+ if (err !== null) { throw err; }
+ run(profile);
+ });
+
});
function run(profile) {
diff --git a/package.json b/package.json
index f422e38..de4e4bf 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "mongo-edu",
"preferGlobal": true,
- "version": "0.1.21",
+ "version": "0.1.22",
"author": "Przemyslaw Pluta <przemyslawplutadev@gmail.com> (http://przemyslawpluta.com)",
"description": "Select and download videos and handouts from university.mongodb.com courses",
"main": "./mongo-edu",
@@ -31,19 +31,21 @@
],
"license": "MIT",
"dependencies": {
- "request": "~2.36.0",
- "youtube-dl": "~1.3.6",
- "colors": "~0.6.2",
- "lodash": "~2.4.1",
"cheerio": "~0.17.0",
+ "colors": "~0.6.2",
+ "filesize": "~2.0.3",
"inquirer": "~0.5.1",
- "progress": "~1.1.3",
+ "lodash": "~2.4.1",
"mkdirp": "~0.5.0",
- "optimist": "~0.6.1",
"mv": "~2.0.0",
- "unzip": "~0.1.9",
+ "optimist": "~0.6.1",
+ "progress": "~1.1.3",
+ "request": "~2.36.0",
"request-progress": "~0.3.1",
- "filesize": "~2.0.3"
+ "semver": "~2.3.0",
+ "unzip": "~0.1.9",
+ "which": "~1.0.5",
+ "youtube-dl": "~1.3.6"
},
"engines": {
"node": ">= 0.8.x"