summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-05-14 19:59:07 -0400
committerGiampaolo Rodola <g.rodola@gmail.com>2016-05-14 19:59:07 -0400
commit8ce2c7b9c2e056d60c4f80e11e30b8f38559eec0 (patch)
tree69d750d2e99b934d8fb12ae996e2736d292b02d8
parentf6da2ec3c59219c7193c12fff502b9880a758e32 (diff)
downloadpsutil-8ce2c7b9c2e056d60c4f80e11e30b8f38559eec0.tar.gz
#817: add script to download exes/whels from appveyor
-rwxr-xr-x.ci/appveyor/download_exes.py89
-rw-r--r--Makefile6
2 files changed, 95 insertions, 0 deletions
diff --git a/.ci/appveyor/download_exes.py b/.ci/appveyor/download_exes.py
new file mode 100755
index 00000000..d72cbf32
--- /dev/null
+++ b/.ci/appveyor/download_exes.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+# Copyright (c) 2009 Giampaolo Rodola'. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""
+Script which downloads exe and wheel files hosted on AppVeyor:
+https://ci.appveyor.com/project/giampaolo/psutil
+Copied and readapted from the original recipe of Ibarra Corretge'
+<saghul@gmail.com>:
+http://code.saghul.net/index.php/2015/09/09/
+"""
+
+from __future__ import print_function
+import argparse
+import errno
+import multiprocessing
+import os
+import requests
+import shutil
+
+from concurrent.futures import ThreadPoolExecutor
+
+
+BASE_URL = 'https://ci.appveyor.com/api'
+
+
+def safe_makedirs(path):
+ try:
+ os.makedirs(path)
+ except OSError, err:
+ if err.errno == errno.EEXIST:
+ if not os.path.isdir(path):
+ raise
+ else:
+ raise
+
+
+def safe_rmtree(path):
+ def onerror(fun, path, excinfo):
+ exc = excinfo[1]
+ if exc.errno != errno.ENOENT:
+ raise
+
+ shutil.rmtree(path, onerror=onerror)
+
+
+def download_file(url):
+ local_filename = url.split('/')[-1]
+ local_filename = os.path.join('dist', local_filename)
+ print(local_filename)
+ safe_makedirs('dist')
+ r = requests.get(url, stream=True)
+ with open(local_filename, 'wb') as f:
+ for chunk in r.iter_content(chunk_size=1024):
+ if chunk: # filter out keep-alive new chunks
+ f.write(chunk)
+
+
+def get_file_urls(options):
+ session = requests.Session()
+ data = session.get(
+ BASE_URL + '/projects/' + options.user + '/' + options.project)
+ data = data.json()
+
+ for job in (job['jobId'] for job in data['build']['jobs']):
+ job_url = BASE_URL + '/buildjobs/' + job + '/artifacts'
+ data = session.get(job_url)
+ data = data.json()
+ for item in data:
+ file_url = job_url + '/' + item['fileName']
+ yield file_url
+
+
+def main(options):
+ safe_rmtree('dist')
+ with ThreadPoolExecutor(max_workers=multiprocessing.cpu_count()) as e:
+ for url in get_file_urls(options):
+ e.submit(download_file, url)
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(
+ description='AppVeyor artifact downloader')
+ parser.add_argument('--user', required=True)
+ parser.add_argument('--project', required=True)
+ args = parser.parse_args()
+ main(args)
diff --git a/Makefile b/Makefile
index 3e6995d6..bc8dbf00 100644
--- a/Makefile
+++ b/Makefile
@@ -52,6 +52,7 @@ setup-dev-env: install-git-hooks
nose \
pep8 \
pyflakes \
+ requests \
sphinx \
sphinx-pypi-upload \
unittest2 \
@@ -126,3 +127,8 @@ git-tag-release:
install-git-hooks:
ln -sf ../../.git-pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
+
+
+# download exes/wheels hosted on appveyor
+win-download-exes:
+ $(PYTHON) .ci/appveyor/download_exes.py --user giampaolo --project psutil