11local http = require (" http" )
22local html = require (" html" )
33
4+ -- get mirror
45local PYTHON_URL = " https://www.python.org/ftp/python/"
6+ local VFOX_PYTHON_MIRROR = os.getenv (" VFOX_PYTHON_MIRROR" )
7+ if VFOX_PYTHON_MIRROR then
8+ PYTHON_URL = VFOX_PYTHON_MIRROR
9+ os .setenv (" PYTHON_BUILD_MIRROR_URL_SKIP_CHECKSUM" , 1 )
10+ os .setenv (" PYTHON_BUILD_MIRROR_URL" , PYTHON_URL )
11+ end
12+
13+ -- request headers
14+ local REQUEST_HEADERS = {
15+ [" User-Agent" ] = " vfox"
16+ }
517
18+ -- download source
619local DOWNLOAD_SOURCE = {
720 --- TODO support zip or web-based installers
8- WEB_BASED = " https://www.python.org/ftp/python/ %s/python-%s%s-webinstall.exe" ,
9- ZIP = " https://www.python.org/ftp/python/ %s/python-%s-embed-%s.zip" ,
21+ WEB_BASED = PYTHON_URL .. " %s/python-%s%s-webinstall.exe" ,
22+ ZIP = PYTHON_URL .. " %s/python-%s-embed-%s.zip" ,
1023 MSI = " " ,
1124 --- Currently only exe installers are supported
12- EXE = " https://www.python.org/ftp/python/ %s/python-%s%s.exe" ,
13- SOURCE = " https://www.python.org/ftp/python/ %s/Python-%s.tar.xz"
25+ EXE = PYTHON_URL .. " %s/python-%s%s.exe" ,
26+ SOURCE = PYTHON_URL .. " %s/Python-%s.tar.xz"
1427}
1528
16- function getMirror ()
17- local mirror = os.getenv (" VFOX_PYTHON_MIRROR" )
18- if mirror == nil then
19- return " https://www.python.org/ftp/python/"
20- end
21- return mirror
22- end
23-
2429function checkIsReleaseVersion (version )
2530 local resp , err = http .head ({
26- url = DOWNLOAD_SOURCE .SOURCE :format (version , version )
31+ url = DOWNLOAD_SOURCE .SOURCE :format (version , version ),
32+ headers = REQUEST_HEADERS
2733 })
2834 if err ~= nil or resp .status_code ~= 200 then
2935 return false
@@ -80,7 +86,8 @@ function checkAvailableReleaseForWindows(version)
8086 --- TODO support zip or web-based installers
8187 local url = DOWNLOAD_SOURCE .EXE :format (version , version , archType )
8288 local resp , err = http .head ({
83- url = url
89+ url = url ,
90+ headers = REQUEST_HEADERS
8491 })
8592 if err ~= nil or resp .status_code ~= 200 then
8693 error (" No available installer found for current version" )
@@ -89,7 +96,8 @@ function checkAvailableReleaseForWindows(version)
8996end
9097function parseVersion ()
9198 local resp , err = http .get ({
92- url = PYTHON_URL
99+ url = PYTHON_URL ,
100+ headers = REQUEST_HEADERS
93101 })
94102 if err ~= nil or resp .status_code ~= 200 then
95103 error (" paring release info failed." .. err )
@@ -144,4 +152,4 @@ function compare_versions(v1, v2)
144152 end
145153
146154 return 0
147- end
155+ end
0 commit comments