diff --git a/util/downloadpython.js b/util/downloadpython.js index a515390..959c76c 100644 --- a/util/downloadpython.js +++ b/util/downloadpython.js @@ -12,7 +12,7 @@ const pyversion = require('./getpythonversions.js'); async function download(ver) { - let url = ""; + let url = "-"; let version = ""; if (ver === undefined) { @@ -28,73 +28,74 @@ async function download(ver) { if (version !== "") { console.log(version); - pyversion.getDownloadLink(version).then(value => { - console.log(value); + await pyversion.getDownloadLink(version).then(value => { + url = value; + console.log(url); }); } // console.log(url); - // 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" - // }); + 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"); + 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; + } + } } download('2.7.14'); diff --git a/util/getpythonversions.js b/util/getpythonversions.js index 16ef975..3e04efe 100644 --- a/util/getpythonversions.js +++ b/util/getpythonversions.js @@ -18,7 +18,7 @@ async function getDownloadLink(v) { switch (os.platform()) { case 'darwin': - extArr = ['.exe','.msi'] + // extArr = ['.exe','.msi'] break; case 'linux': break; @@ -29,19 +29,36 @@ async function getDownloadLink(v) { break; } - await new Promise(resolve => { + let available_download_links = await new Promise(resolve => { request({ uri: "https://www.python.org/ftp/python/" + v.toString() + "/", - }, function(error, response, body) { - console.log(body); - resolve(body); + }, function (error, response, body) { + // const re = /"\n"/g; + tempArr = body.split(/\r?\n/); + let availLinks = []; + tempArr.forEach(function (item) { + if (item.includes('', 0) + 2; + let substr_end = item.indexOf('', 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 - for(i = 0; i < extArr.length; i++){ - - } + return "https://www.python.org/ftp/python/" + v.toString() + "/" + py_executable_link.toString(); } let versions = new Promise(resolve => {