-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_helper.py
executable file
·51 lines (41 loc) · 1.49 KB
/
install_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
import json
import platform
import sys
# install_helper reads the JSON payload from stdin and prints the URL for the
# zipfile for the correct OS/architecture. Exits with 0 if a URL was found, 1
# otherwise. This script expects data in the format found at:
# https://api.github.com/repos/google/protobuf/releases/latest.
if __name__ == '__main__':
my_uname_data = platform.uname()
my_os = my_uname_data[0] # Darwin, Linux, Windows, etc.
my_arch = my_uname_data[4] # x86_64, etc.
search_os = ''
search_arch = my_arch
# Need to set the search OS (and possibly architecture) depending on the
# given results from the platform package.
if my_os == 'Darwin':
search_os = 'osx-'
elif my_os == 'Linux':
search_os = 'linux-'
elif my_os == 'Windows':
search_os = 'win32'
search_arch = ''
# Exit if we don't know what to search for.
if not search_os:
sys.stderr.write('Unknown OS "%s"\n' % my_os)
exit(1)
# Read the JSON payload from stdin; we only care about the assets for
# zipfile downloads.
payload = json.load(sys.stdin)
assets = payload['assets']
search_str = '%s%s.zip' % (search_os, search_arch)
zip_url = ''
for asset in assets:
name = asset['name']
if 'protoc' in name and search_str in name:
zip_url = asset['browser_download_url']
break
sys.stdout.write(zip_url)
exit_status = 0 if zip_url else 1
exit(exit_status)