2020-01-04 21:47:03 -05:00
|
|
|
// module.exports = { THIS IS AT THE BOTTOM SO NO ERROREROS WHILE TESTING
|
|
|
|
|
// versions
|
|
|
|
|
// }
|
2018-10-30 21:42:14 -04:00
|
|
|
const request = require('request');
|
2020-01-04 21:47:03 -05:00
|
|
|
const os = require('os');
|
2018-10-30 21:42:14 -04:00
|
|
|
|
2018-11-21 20:42:39 -05:00
|
|
|
// let matches = [];
|
|
|
|
|
|
2020-01-04 21:47:03 -05:00
|
|
|
async function validateVersion(v) {
|
|
|
|
|
let availVer = await versions;
|
|
|
|
|
return availVer.includes(v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function getDownloadLink(v) {
|
2020-01-05 10:02:01 -05:00
|
|
|
|
|
|
|
|
let extArr = [];
|
|
|
|
|
|
2020-01-04 21:47:03 -05:00
|
|
|
switch (os.platform())
|
|
|
|
|
{
|
|
|
|
|
case 'darwin':
|
2020-01-05 10:02:01 -05:00
|
|
|
extArr = ['.exe','.msi']
|
2020-01-04 21:47:03 -05:00
|
|
|
break;
|
|
|
|
|
case 'linux':
|
|
|
|
|
break;
|
|
|
|
|
case 'win32':
|
2020-01-05 10:02:01 -05:00
|
|
|
extArr = ['.exe','.msi']
|
|
|
|
|
break;
|
2020-01-04 21:47:03 -05:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-01-05 10:02:01 -05:00
|
|
|
|
|
|
|
|
await new Promise(resolve => {
|
|
|
|
|
request({
|
|
|
|
|
uri: "https://www.python.org/ftp/python/" + v.toString() + "/",
|
|
|
|
|
}, function(error, response, body) {
|
|
|
|
|
console.log(body);
|
|
|
|
|
resolve(body);
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
let i = 0
|
|
|
|
|
for(i = 0; i < extArr.length; i++){
|
|
|
|
|
|
|
|
|
|
}
|
2020-01-04 21:47:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let versions = new Promise(resolve => {
|
2018-10-30 21:42:14 -04:00
|
|
|
request({
|
|
|
|
|
uri: "https://www.python.org/ftp/python/",
|
|
|
|
|
}, function (error, response, body) {
|
|
|
|
|
const re = /"[0-9]{1,}\.[0-9]{1,}(\.[0-9]{1,})*\/"/g;
|
2018-11-21 20:42:39 -05:00
|
|
|
matches = body.match(re)
|
2018-10-30 21:42:14 -04:00
|
|
|
matches = matches.map((value) => {
|
2018-11-21 20:42:39 -05:00
|
|
|
return value.slice(1, -2);
|
2018-10-30 21:42:14 -04:00
|
|
|
});
|
2020-01-04 21:47:03 -05:00
|
|
|
|
2018-11-21 20:42:39 -05:00
|
|
|
resolve(matches);
|
2018-10-30 21:42:14 -04:00
|
|
|
});
|
2020-01-04 21:47:03 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
let current = new Promise(resolve => {
|
|
|
|
|
request({
|
|
|
|
|
uri: "https://www.python.org/downloads/",
|
|
|
|
|
}, function (error, response, body) {
|
|
|
|
|
let current_os = '';
|
|
|
|
|
switch (os.platform())
|
|
|
|
|
{
|
|
|
|
|
case 'darwin':
|
|
|
|
|
current_os = "download-os-mac-osx";
|
|
|
|
|
break;
|
|
|
|
|
case 'linux':
|
|
|
|
|
current_os = "download-os-source";
|
|
|
|
|
break;
|
|
|
|
|
case 'win32':
|
|
|
|
|
current_os = "download-os-windows";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
current_os = "download-os-source";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let current_download_start = body.indexOf("Download Python ",body.indexOf(current_os)) + 16;
|
|
|
|
|
let current_download_end = body.indexOf('</a>', current_download_start);
|
|
|
|
|
let current_download = body.substring(current_download_start, current_download_end);
|
|
|
|
|
|
|
|
|
|
let ver = current_download;
|
|
|
|
|
|
|
|
|
|
resolve(ver);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2020-01-05 10:02:01 -05:00
|
|
|
// current.then(value => {
|
|
|
|
|
// console.log(value);
|
|
|
|
|
// })
|
2020-01-04 21:47:03 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// versions.then(value => {
|
|
|
|
|
|
|
|
|
|
// let i = 0;
|
|
|
|
|
// for (i = 0; i < value.length; i++){
|
|
|
|
|
// console.log(value[i]);
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
versions,
|
|
|
|
|
current,
|
|
|
|
|
validateVersion,
|
|
|
|
|
getDownloadLink
|
|
|
|
|
}
|