blob: fcb72e5fc2c3443376bbb56d0dfde339fcbd6088 [file] [log] [blame]
Nobuaki Sukegawa8ccf5a62016-09-28 05:05:02 +09001import urllib.request
2import sys
3
4OUT = 'Win64OpenSSL.exe'
5
6URL_STR = 'https://slproweb.com/download/Win64OpenSSL-%s.exe'
7
8VERSION_MAJOR = 1
9VERSION_MINOR = 0
10VERSION_PATCH = 2
11VERSION_SUFFIX = 'j'
12VERSION_STR = '%d_%d_%d%s'
13
14TRY_COUNT = 4
15
16
17def main():
18 for patch in range(VERSION_PATCH, TRY_COUNT):
19 for suffix in range(TRY_COUNT):
20 if patch == VERSION_PATCH:
21 s = VERSION_SUFFIX
22 else:
23 s = 'a'
24 s = chr(ord(s) + suffix)
25 ver = VERSION_STR % (VERSION_MAJOR, VERSION_MINOR, patch, s)
26 url = URL_STR % ver
27 try:
28 with urllib.request.urlopen(url) as res:
29 if res.getcode() == 200:
30 with open(OUT, 'wb') as out:
31 out.write(res.read())
32 print('successfully downloaded from ' + url)
33 return 0
34 except urllib.error.HTTPError:
35 pass
36 print('failed to download from ' + url, file=sys.stderr)
37 print('could not download openssl', file=sys.stderr)
38 return 1
39
40if __name__ == '__main__':
41 sys.exit(main())