-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathbox-downloader
executable file
·35 lines (26 loc) · 1007 Bytes
/
box-downloader
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
#!/usr/bin/env python3
import os
import click
import requests
import yaml
@click.command()
@click.argument('url')
def download(url):
"""Simple program to download Jenkins artifacts"""
session = requests.Session()
response = session.get(url + 'api/json')
response.raise_for_status()
data = response.json()
artifacts = {artifact['fileName']: artifact['relativePath'] for artifact in data['artifacts']
if artifact['fileName'].endswith('.yaml')}
for filename, path in artifacts.items():
response = session.get(url + 'artifact/' + path)
response.raise_for_status()
target = os.path.join('vagrant/boxes.d', filename)
with open(target, 'wb') as fp:
click.echo('Downloading {} to {}'.format(filename, target))
fp.write(response.content)
boxes = yaml.safe_load(response.content)
click.echo('Found boxes: {}'.format(' '.join(boxes.keys())))
if __name__ == '__main__':
download()