From 87a12a5a71dc558d8e3b2fd03cc1f2f0d96fa780 Mon Sep 17 00:00:00 2001 From: BrOakes Date: Wed, 21 Nov 2018 20:42:39 -0500 Subject: [PATCH] portapy commands --- index.js | 15 ++++++ package-lock.json | 2 +- package.json | 6 +-- util/downloadpython.js | 102 +++++++++++++++++++------------------- util/getpythonversions.js | 16 +++--- 5 files changed, 79 insertions(+), 62 deletions(-) diff --git a/index.js b/index.js index e69de29..ab0565a 100644 --- a/index.js +++ b/index.js @@ -0,0 +1,15 @@ +#!/usr/bin/env node + +let args = process.argv.slice(2); + +if (args[0] == 'help' || args[0] == '?' || args[0] == 'h'){ + console.log("heres some help"); +} else if(args[0] == "version" || args[0] == "v") { + console.log("version number placeholder"); +} else if (args[0] == "py" || args[0] == "pyversion") { + if (args[1]){ + console.log(args[1]); + } else { + console.log("version of python"); + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 38ddae9..a7b5f47 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "portapy", - "version": "0.0.11", + "version": "0.0.13", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 00dfa20..141dac8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "portapy", - "version": "0.0.11", + "version": "0.0.13", "description": "", "main": "index.js", "scripts": { @@ -10,7 +10,8 @@ "clean": "node clean.js" }, "bin": { - "python": "bin/python.js" + "python": "bin/python.js", + "portapy": "index.js" }, "repository": { "type": "git", @@ -24,7 +25,6 @@ "dependencies": { "copy-dir": "^0.4.0", "minimist": "^1.2.0", - "python": "0.0.4", "request": "^2.88.0" }, "homepage": "https://github.com/marcus13345/portapy#readme" diff --git a/util/downloadpython.js b/util/downloadpython.js index eef4a13..85ef1b2 100644 --- a/util/downloadpython.js +++ b/util/downloadpython.js @@ -11,68 +11,68 @@ const copydir = require('copy-dir'); async function download() { - - let url = await getPythonDownloadLink(); - let filename = path.parse(url).base; - try { - fs.mkdirSync('Python-Installer'); - } catch(e) {'';} - try { - fs.mkdirSync('Python'); - } catch(e) {'';} - try { - fs.mkdirSync('Temp-Python'); - } catch(e) {'';} - try { - fs.writeFileSync('.installerLocation', filename); - } catch(e) {'';} - // let installSettings = fs.readFileSync('unattend.xml'); + + let url = await getPythonDownloadLink(); + let filename = path.parse(url).base; + try { + fs.mkdirSync('Python-Installer'); + } catch(e) {'';} + try { + fs.mkdirSync('Python'); + } catch(e) {'';} + try { + fs.mkdirSync('Temp-Python'); + } catch(e) {'';} + try { + fs.writeFileSync('.installerLocation', filename); + } catch(e) {'';} + // let installSettings = fs.readFileSync('unattend.xml'); - let out_file = `Python-Installer/${filename}` + let out_file = `Python-Installer/${filename}` - await new Promise(resolve => { - request({ - uri: url, - encoding: null - }, function (error, response, body) { - fs.writeFileSync(out_file, body, {}); - resolve(); - }); + await new Promise(resolve => { + request({ + uri: url, + encoding: null + }, function (error, response, body) { + fs.writeFileSync(out_file, body, {}); + resolve(); }); + }); - console.log('Download Complete!'); + console.log('Download Complete!'); - switch (os.platform()) - { - case 'win32': { - try { - let installerPath = path.join(__dirname, '..', 'Python-Installer/', filename); - let tempPath = path.join(__dirname, '..', 'Temp-Python/'); - let targetPath = path.join(__dirname, '..', 'Python/'); - execSync(`${installerPath} /passive DefaultJustForMeTargetDir=${tempPath}`, { - stdio: "inherit" - }); - - console.log("Creating Portable Python Directory"); + switch (os.platform()) + { + case 'win32': { + try { + let installerPath = path.join(__dirname, '..', 'Python-Installer/', filename); + let tempPath = path.join(__dirname, '..', 'Temp-Python/'); + let targetPath = path.join(__dirname, '..', 'Python/'); + execSync(`${installerPath} /passive DefaultJustForMeTargetDir=${tempPath}`, { + stdio: "inherit" + }); + + console.log("Creating Portable Python Directory"); - copydir.sync(tempPath, targetPath); - console.log("Portable Directory Created!"); + copydir.sync(tempPath, targetPath); + console.log("Portable Directory Created!"); - console.log("Uninstalling Unnecessary Python Files"); + console.log("Uninstalling Unnecessary Python Files"); - execSync(`${installerPath} /passive /uninstall`, { - stdio: 'inherit' - }); + execSync(`${installerPath} /passive /uninstall`, { + stdio: 'inherit' + }); - fs.rmdirSync(tempPath); + fs.rmdirSync(tempPath); - console.log("PordaPy Installed!"); - } catch (err) { - console.log(err); - } - break; - }[] + console.log("PordaPy Installed!"); + } catch (err) { + console.log(err); + } + break; } + } } function getPythonDownloadLink() { diff --git a/util/getpythonversions.js b/util/getpythonversions.js index f155120..baee48b 100644 --- a/util/getpythonversions.js +++ b/util/getpythonversions.js @@ -3,18 +3,20 @@ module.exports = { } const request = require('request'); -function versions() -{ - return new Promise(resolve => { +// let matches = []; + +let versions = function() { + + new Promise(resolve => { request({ uri: "https://www.python.org/ftp/python/", }, function (error, response, body) { const re = /"[0-9]{1,}\.[0-9]{1,}(\.[0-9]{1,})*\/"/g; - let matches = body.match(re) + matches = body.match(re) matches = matches.map((value) => { - return value.slice(1,-2) + return value.slice(1, -2); }); - resolve(matches); + resolve(matches); }); }) -} \ No newline at end of file +}