Nobuaki Sukegawa | 8ccf5a6 | 2016-09-28 05:05:02 +0900 | [diff] [blame] | 1 | import urllib.request |
| 2 | import sys |
| 3 | |
| 4 | OUT = 'Win64OpenSSL.exe' |
| 5 | |
| 6 | URL_STR = 'https://slproweb.com/download/Win64OpenSSL-%s.exe' |
| 7 | |
| 8 | VERSION_MAJOR = 1 |
| 9 | VERSION_MINOR = 0 |
| 10 | VERSION_PATCH = 2 |
| 11 | VERSION_SUFFIX = 'j' |
| 12 | VERSION_STR = '%d_%d_%d%s' |
| 13 | |
| 14 | TRY_COUNT = 4 |
| 15 | |
| 16 | |
| 17 | def 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 | |
| 40 | if __name__ == '__main__': |
| 41 | sys.exit(main()) |