-
Notifications
You must be signed in to change notification settings - Fork 60
/
get-release.py
executable file
·45 lines (34 loc) · 1.18 KB
/
get-release.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
#!/usr/bin/env python
from __future__ import print_function
from clint.textui import progress
import requests
import sys
if len(sys.argv) != 2:
print("Usage: {} release-tag".format(sys.argv[0]))
sys.exit(1)
baseurl = 'https://api.github.com/repos/meta-toolkit/metapy/releases/tags'
r = requests.get('{}/{}'.format(baseurl, sys.argv[1]))
if r.status_code != 200:
print("Error: {}".format(r.status_code))
print(r.text)
sys.exit(1)
json = r.json()
print("Found release {} tagged by {}".format(json['tag_name'],
json['author']['login']))
for asset in json['assets']:
url = asset['browser_download_url']
name = asset['name']
print("Fetching {}...".format(name))
r = requests.get(url, stream=True)
if r.status_code != 200:
print("Error fetching {}: {}".format(name, r.status_code))
print(r.text)
sys.exit(1)
with open('dist/{}'.format(name), 'wb') as f:
total_length = int(r.headers.get('content-length'))
for chunk in progress.bar(r.iter_content(chunk_size = 4096),
expected_size = total_length / 4096 + 1):
if chunk:
f.write(chunk)
f.flush()
print("Done!")