Chromium Code Reviews| Index: buildbucket.py |
| diff --git a/buildbucket.py b/buildbucket.py |
| index f00cc8f9d10124abdcf192f8ebf2478045ee00fb..f33787b2999018b7a734f8bb30289b7144d183ee 100755 |
| --- a/buildbucket.py |
| +++ b/buildbucket.py |
| @@ -27,7 +27,7 @@ import auth |
| BUILDBUCKET_URL = 'https://cr-buildbucket.appspot.com' |
| -PUT_BUILD_URL = urlparse.urljoin( |
| +BUILDBUCKET_API_URL = urlparse.urljoin( |
| BUILDBUCKET_URL, |
| '_ah/api/buildbucket/v1/builds', |
| ) |
| @@ -41,6 +41,13 @@ def main(argv): |
| action='store_true', |
| ) |
| subparsers = parser.add_subparsers(dest='command') |
| + get_parser = subparsers.add_parser('get') |
| + get_parser.add_argument( |
| + '-i', |
|
nodir
2015/08/07 21:43:11
IMO: drop this. --id is short and descriptive
smut
2015/08/07 21:46:48
Done.
|
| + '--id', |
| + help='The ID of the build to get the status of.', |
| + required=True, |
| + ) |
| put_parser = subparsers.add_parser('put') |
| put_parser.add_argument( |
| '-b', |
| @@ -68,26 +75,41 @@ def main(argv): |
| help='A file to load a JSON dict of properties from.', |
| ) |
| args = parser.parse_args() |
| - # TODO(smut): When more commands are implemented, refactor this. |
| - assert args.command == 'put' |
| - |
| - changes = [] |
| - if args.changes: |
| - try: |
| - with open(args.changes) as fp: |
| - changes.extend(json.load(fp)) |
| - except (TypeError, ValueError): |
| - sys.stderr.write('%s contained invalid JSON list.\n' % args.changes) |
| - raise |
| - |
| - properties = {} |
| - if args.properties: |
| - try: |
| - with open(args.properties) as fp: |
| - properties.update(json.load(fp)) |
| - except (TypeError, ValueError): |
| - sys.stderr.write('%s contained invalid JSON dict.\n' % args.properties) |
| - raise |
| + |
| + body = None |
| + |
| + if args.command == 'get': |
| + method = 'GET' |
| + url = '%s/%s' % (BUILDBUCKET_API_URL, args.id) |
| + elif args.command == 'put': |
| + changes = [] |
| + if args.changes: |
| + try: |
| + with open(args.changes) as fp: |
| + changes.extend(json.load(fp)) |
| + except (TypeError, ValueError): |
| + sys.stderr.write('%s contained invalid JSON list.\n' % args.changes) |
| + raise |
| + |
| + properties = {} |
| + if args.properties: |
| + try: |
| + with open(args.properties) as fp: |
| + properties.update(json.load(fp)) |
| + except (TypeError, ValueError): |
| + sys.stderr.write('%s contained invalid JSON dict.\n' % args.properties) |
| + raise |
| + |
| + body = json.dumps({ |
| + 'bucket': args.bucket, |
| + 'parameters_json': json.dumps({ |
| + 'builder_name': args.builder_name, |
| + 'changes': changes, |
| + 'properties': properties, |
| + }), |
| + }) |
| + method = 'PUT' |
| + url = BUILDBUCKET_API_URL |
| authenticator = auth.get_authenticator_for_host( |
| BUILDBUCKET_URL, |
| @@ -96,16 +118,9 @@ def main(argv): |
| http = authenticator.authorize(httplib2.Http()) |
| http.force_exception_to_status_code = True |
| response, content = http.request( |
| - PUT_BUILD_URL, |
| - 'PUT', |
| - body=json.dumps({ |
| - 'bucket': args.bucket, |
| - 'parameters_json': json.dumps({ |
| - 'builder_name': args.builder_name, |
| - 'changes': changes, |
| - 'properties': properties, |
| - }), |
| - }), |
| + url, |
| + method, |
| + body=body, |
| headers={'Content-Type': 'application/json'}, |
| ) |