summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2015-09-05 07:38:28 -0400
committerNed Batchelder <ned@nedbatchelder.com>2015-09-05 07:38:28 -0400
commitcc1f1bc0920f65e126da6b1764d2fe8af6b36502 (patch)
tree77f88cac010f61f09d653d68cb3cef11ae6e14d2
parent8b54205e2ef06f16601ce682f88afbf944cd76be (diff)
downloadpython-coveragepy-git-cc1f1bc0920f65e126da6b1764d2fe8af6b36502.tar.gz
Make download_appveyor.py nicer
-rw-r--r--Makefile2
-rw-r--r--ci/download_appveyor.py41
2 files changed, 31 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 384aadd5..edfbaad2 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@ clean:
sterile: clean
-rm -rf .tox*
-LINTABLE = coverage igor.py setup.py tests
+LINTABLE = coverage igor.py setup.py tests ci/*.py
lint:
-pylint $(LINTABLE)
diff --git a/ci/download_appveyor.py b/ci/download_appveyor.py
index ecb1a2fb..72488d4e 100644
--- a/ci/download_appveyor.py
+++ b/ci/download_appveyor.py
@@ -2,13 +2,13 @@
import os
import os.path
-import pprint
import zipfile
import requests
def make_auth_headers():
+ """Make the authentication headers needed to use the Appveyor API."""
with open("ci/appveyor.token") as f:
token = f.read().strip()
@@ -18,41 +18,58 @@ def make_auth_headers():
return headers
-def get_project_build(account, project):
- url = "https://ci.appveyor.com/api/projects/{account}/{project}".format(account=account, project=project)
+def make_url(url, **kwargs):
+ """Build an Appveyor API url."""
+ return "https://ci.appveyor.com/api" + url.format(**kwargs)
+
+
+def get_project_build(account_project):
+ """Get the details of the latest Appveyor build."""
+ url = make_url("/projects/{account_project}", account_project=account_project)
response = requests.get(url, headers=make_auth_headers())
return response.json()
-def download_latest_artifacts(account, project):
- build = get_project_build(account, project)
+def download_latest_artifacts(account_project):
+ """Download all the artifacts from the latest build."""
+ build = get_project_build(account_project)
jobs = build['build']['jobs']
print "Build {0[build][version]}, {1} jobs: {0[build][message]}".format(build, len(jobs))
for job in jobs:
name = job['name'].partition(':')[2].split(',')[0].strip()
print " {0}: {1[status]}, {1[artifactsCount]} artifacts".format(name, job)
- url = "https://ci.appveyor.com/api/buildjobs/{jobid}/artifacts".format(jobid=job['jobId'])
+ url = make_url("/buildjobs/{jobid}/artifacts", jobid=job['jobId'])
response = requests.get(url, headers=make_auth_headers())
artifacts = response.json()
for artifact in artifacts:
- type = artifact['type']
+ is_zip = artifact['type'] == "Zip"
filename = artifact['fileName']
print " {0}".format(filename)
- url = "https://ci.appveyor.com/api/buildjobs/{jobid}/artifacts/{filename}".format(jobid=job['jobId'], filename=filename)
+ url = make_url(
+ "/buildjobs/{jobid}/artifacts/{filename}",
+ jobid=job['jobId'],
+ filename=filename
+ )
download_url(url, filename, make_auth_headers())
- if type == "Zip":
+ if is_zip:
unpack_zipfile(filename)
os.remove(filename)
-def download_url(url, filename, headers):
+def ensure_dirs(filename):
+ """Make sure the directories exist for `filename`."""
dirname, _ = os.path.split(filename)
if dirname and not os.path.exists(dirname):
os.makedirs(dirname)
+
+
+def download_url(url, filename, headers):
+ """Download a file from `url` to `filename`."""
+ ensure_dirs(filename)
response = requests.get(url, headers=headers, stream=True)
if response.status_code == 200:
with open(filename, 'wb') as f:
@@ -61,12 +78,14 @@ def download_url(url, filename, headers):
def unpack_zipfile(filename):
+ """Unpack a zipfile, using the names in the zip."""
with open(filename, 'rb') as fzip:
z = zipfile.ZipFile(fzip)
for name in z.namelist():
print " extracting {}".format(name)
+ ensure_dirs(name)
z.extract(name)
if __name__ == "__main__":
- download_latest_artifacts("nedbat", "coveragepy")
+ download_latest_artifacts("nedbat/coveragepy")