summaryrefslogtreecommitdiff
path: root/scripts/artifacts.py
blob: 4b821cf2052df49875d8709f54159fc8701ed43f (plain)
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
try:
    from urllib.request import urlopen
except ImportError:
    from urllib import urlopen

import io
import json
import subprocess


def get_json(url):
    return json.loads(urlopen(url).read().decode('utf-8'))


def download_file(src_url, dest_path):
    print(dest_path)
    subprocess.call(
        ['curl', '-L', '-#', '-o', dest_path, src_url])


def download_appveyor_artifacts():
    api_url = 'https://ci.appveyor.com/api'
    builds = get_json(
        '{}/projects/etrepum/simplejson'.format(api_url))

    for job in builds['build']['jobs']:
        url = '{api_url}/buildjobs/{jobId}/artifacts'.format(
            api_url=api_url, **job)
        for artifact in get_json(url):
            download_file(
                '{url}/{fileName}'.format(url=url, **artifact),
                artifact['fileName'])


def download_github_artifacts():
    release = get_json(
        'https://api.github.com/repos/simplejson/simplejson/releases/latest')
    for asset in release['assets']:
        download_file(asset['browser_download_url'], 'dist/{name}'.format(**asset))


def main():
    download_appveyor_artifacts()
    download_github_artifacts()


if __name__ == '__main__':
    main()