From 452ade007e1d8e98576ceea45c02e576665cc823 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 7 Jan 2020 13:28:11 -0800 Subject: [PATCH] Clean up Shippable scripts in tools directory. --- test/utils/shippable/tools/download.py | 22 ++++++++++++++++++++-- test/utils/shippable/tools/run.py | 12 ++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/test/utils/shippable/tools/download.py b/test/utils/shippable/tools/download.py index 045028914cb..5449ee7e6fb 100755 --- a/test/utils/shippable/tools/download.py +++ b/test/utils/shippable/tools/download.py @@ -26,6 +26,8 @@ import argparse import json import os import re +import sys + import requests try: @@ -36,6 +38,12 @@ except ImportError: def main(): """Main program body.""" + args = parse_args() + download_run(args) + + +def parse_args(): + """Parse and return args.""" api_key = get_api_key() parser = argparse.ArgumentParser(description='Download results from a Shippable run.') @@ -118,6 +126,11 @@ def main(): if not any(selections): parser.error('At least one download option is required.') + return args + + +def download_run(args): + """Download a Shippable run.""" headers = dict( Authorization='apiToken %s' % args.api_key, ) @@ -137,7 +150,7 @@ def main(): if job_number: if args.job_number: - exit('ERROR: job number found in url and specified with --job-number') + sys.exit('ERROR: job number found in url and specified with --job-number') args.job_number = [job_number] @@ -173,7 +186,7 @@ def main(): project = run['projectName'] run_number = run['runNumber'] else: - exit('ERROR: invalid run: %s' % args.run_id) + sys.exit('ERROR: invalid run: %s' % args.run_id) output_dir = '%s/%s/%s' % (account, project, run_number) @@ -199,6 +212,11 @@ def main(): with open(path, 'w') as metadata_fd: metadata_fd.write(contents) + download_jobs(args, jobs, headers, output_dir) + + +def download_jobs(args, jobs, headers, output_dir): + """Download Shippable jobs.""" for j in jobs: job_id = j['id'] job_number = j['jobNumber'] diff --git a/test/utils/shippable/tools/run.py b/test/utils/shippable/tools/run.py index 7ec75903636..310a7f53f00 100755 --- a/test/utils/shippable/tools/run.py +++ b/test/utils/shippable/tools/run.py @@ -25,6 +25,7 @@ __metaclass__ = type import argparse import json import os + import requests try: @@ -35,6 +36,12 @@ except ImportError: def main(): """Main program body.""" + args = parse_args() + start_run(args) + + +def parse_args(): + """Parse and return args.""" api_key = get_api_key() parser = argparse.ArgumentParser(description='Start a new Shippable run.') @@ -69,6 +76,11 @@ def main(): args = parser.parse_args() + return args + + +def start_run(args): + """Start a new Shippable run.""" headers = dict( Authorization='apiToken %s' % args.key, )