Allow to specify the build to download from Appveyor

This commit is contained in:
Daniele Varrazzo 2021-06-17 03:45:31 +01:00
parent c59ff6a4b7
commit 62490a6bcc

View File

@ -8,6 +8,7 @@ import sys
import logging
import datetime as dt
from pathlib import Path
from argparse import ArgumentParser
import requests
@ -24,6 +25,7 @@ class ScriptError(Exception):
def main():
opt = parse_cmdline()
try:
token = os.environ["APPVEYOR_TOKEN"]
except KeyError:
@ -33,8 +35,13 @@ def main():
s.headers["Content-Type"] = "application/json"
s.headers["Authorization"] = f"Bearer {token}"
if opt.build:
logger.info("fetching build %s", opt.build)
resp = s.get(f"{API_URL}/projects/{REPOS}/build/{opt.build}")
else:
logger.info("fetching last run")
resp = s.get(f"{API_URL}/projects/{REPOS}/")
resp = s.get(f"{API_URL}/projects/{REPOS}")
resp.raise_for_status()
data = resp.json()
@ -52,7 +59,7 @@ def main():
jobs = data["build"]["jobs"]
for job in jobs:
if job["status"] != "success":
raise ScriptError("status for job {job['jobId']} is {job['status']}")
raise ScriptError(f"status for job {job['jobId']} is {job['status']}")
logger.info(f"fetching artifacts info for {job['name']}")
resp = s.get(f"{API_URL}/buildjobs/{job['jobId']}/artifacts/")
@ -77,6 +84,13 @@ def main():
logger.info("now you can run: 'twine upload -s packages/*'")
def parse_cmdline():
parser = ArgumentParser(description=__doc__)
parser.add_argument("--build", help="build version to download [default: latest]")
opt = parser.parse_args()
return opt
def pretty_interval(td):
secs = td.total_seconds()
mins, secs = divmod(secs, 60)