it works just breaks with msi varients because comands are differnet from cli

downloader-work
BrOakes 2020-01-05 14:17:33 -05:00
parent 2e032f95a3
commit 94cba09fbb
2 changed files with 81 additions and 63 deletions

View File

@ -12,7 +12,7 @@ const pyversion = require('./getpythonversions.js');
async function download(ver) { async function download(ver) {
let url = ""; let url = "-";
let version = ""; let version = "";
if (ver === undefined) { if (ver === undefined) {
@ -28,73 +28,74 @@ async function download(ver) {
if (version !== "") { if (version !== "") {
console.log(version); console.log(version);
pyversion.getDownloadLink(version).then(value => { await pyversion.getDownloadLink(version).then(value => {
console.log(value); url = value;
console.log(url);
}); });
} }
// console.log(url); // console.log(url);
// let url = await getPythonDownloadLink(); // // let url = await getPythonDownloadLink();
// let filename = path.parse(url).base; let filename = path.parse(url).base;
// try { try {
// fs.mkdirSync('Python-Installer'); fs.mkdirSync('Python-Installer');
// } catch(e) {'';} } catch(e) {'';}
// try { try {
// fs.mkdirSync('Python'); fs.mkdirSync('Python');
// } catch(e) {'';} } catch(e) {'';}
// try { try {
// fs.mkdirSync('Temp-Python'); fs.mkdirSync('Temp-Python');
// } catch(e) {'';} } catch(e) {'';}
// try { try {
// fs.writeFileSync('.installerLocation', filename); fs.writeFileSync('.installerLocation', filename);
// } catch(e) {'';} } catch(e) {'';}
// // let installSettings = fs.readFileSync('unattend.xml'); // let installSettings = fs.readFileSync('unattend.xml');
// let out_file = `Python-Installer/${filename}` let out_file = `Python-Installer/${filename}`
// await new Promise(resolve => { await new Promise(resolve => {
// request({ request({
// uri: url, uri: url,
// encoding: null encoding: null
// }, function (error, response, body) { }, function (error, response, body) {
// fs.writeFileSync(out_file, body, {}); fs.writeFileSync(out_file, body, {});
// resolve(); resolve();
// }); });
// }); });
// console.log('Download Complete!'); console.log('Download Complete!');
// switch (os.platform()) switch (os.platform())
// { {
// case 'win32': { case 'win32': {
// try { try {
// let installerPath = path.join(__dirname, '..', 'Python-Installer/', filename); let installerPath = path.join(__dirname, '..', 'Python-Installer/', filename);
// let tempPath = path.join(__dirname, '..', 'Temp-Python/'); let tempPath = path.join(__dirname, '..', 'Temp-Python/');
// let targetPath = path.join(__dirname, '..', 'Python/'); let targetPath = path.join(__dirname, '..', 'Python/');
// execSync(`${installerPath} /passive DefaultJustForMeTargetDir=${tempPath}`, { execSync(`${installerPath} /passive DefaultJustForMeTargetDir=${tempPath}`, {
// stdio: "inherit" stdio: "inherit"
// }); });
// console.log("Creating Portable Python Directory"); console.log("Creating Portable Python Directory");
// copydir.sync(tempPath, targetPath); copydir.sync(tempPath, targetPath);
// console.log("Portable Directory Created!"); console.log("Portable Directory Created!");
// console.log("Uninstalling Unnecessary Python Files"); console.log("Uninstalling Unnecessary Python Files");
// execSync(`${installerPath} /passive /uninstall`, { execSync(`${installerPath} /passive /uninstall`, {
// stdio: 'inherit' stdio: 'inherit'
// }); });
// fs.rmdirSync(tempPath); fs.rmdirSync(tempPath);
// console.log("PordaPy Installed!"); console.log("PordaPy Installed!");
// } catch (err) { } catch (err) {
// console.log(err); console.log(err);
// } }
// break; break;
// } }
// } }
} }
download('2.7.14'); download('2.7.14');

View File

@ -18,7 +18,7 @@ async function getDownloadLink(v) {
switch (os.platform()) switch (os.platform())
{ {
case 'darwin': case 'darwin':
extArr = ['.exe','.msi'] // extArr = ['.exe','.msi']
break; break;
case 'linux': case 'linux':
break; break;
@ -29,19 +29,36 @@ async function getDownloadLink(v) {
break; break;
} }
await new Promise(resolve => { let available_download_links = await new Promise(resolve => {
request({ request({
uri: "https://www.python.org/ftp/python/" + v.toString() + "/", uri: "https://www.python.org/ftp/python/" + v.toString() + "/",
}, function(error, response, body) { }, function (error, response, body) {
console.log(body); // const re = /"\n"/g;
resolve(body); tempArr = body.split(/\r?\n/);
let availLinks = [];
tempArr.forEach(function (item) {
if (item.includes('<a href="py')) {
let substr_start = item.indexOf('">', 0) + 2;
let substr_end = item.indexOf('</a>', substr_start);
let substr = item.substring(substr_start, substr_end);
availLinks.push(substr);
}
})
// console.log(availLinks);
resolve(availLinks);
})
});
let py_executable_link = await new Promise(resolve => {
extArr.forEach(function (item) {
let filename = "python-" + v.toString() + item.toString();
if (available_download_links.includes(filename)) {
resolve(filename);
}
}) })
}) })
let i = 0 return "https://www.python.org/ftp/python/" + v.toString() + "/" + py_executable_link.toString();
for(i = 0; i < extArr.length; i++){
}
} }
let versions = new Promise(resolve => { let versions = new Promise(resolve => {