Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: buildbucket.py

Issue 1199963004: Add --changes flag to buildbucket.py's put subcommand (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Tool for interacting with Buildbucket. 6 """Tool for interacting with Buildbucket.
7 7
8 Usage: 8 Usage:
9 $ depot-tools-auth login https://cr-buildbucket.appspot.com 9 $ depot-tools-auth login https://cr-buildbucket.appspot.com
10 $ buildbucket.py \ 10 $ buildbucket.py \
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 put_parser.add_argument( 45 put_parser.add_argument(
46 '-b', 46 '-b',
47 '--bucket', 47 '--bucket',
48 help=( 48 help=(
49 'The bucket to schedule the build on. Typically the master name, e.g.' 49 'The bucket to schedule the build on. Typically the master name, e.g.'
50 ' master.tryserver.chromium.linux.' 50 ' master.tryserver.chromium.linux.'
51 ), 51 ),
52 required=True, 52 required=True,
53 ) 53 )
54 put_parser.add_argument( 54 put_parser.add_argument(
55 '-c',
56 '--changes',
57 help='A flie to load a JSON list of changes dicts from.',
58 )
59 put_parser.add_argument(
55 '-n', 60 '-n',
56 '--builder-name', 61 '--builder-name',
57 help='The builder to schedule the build on.', 62 help='The builder to schedule the build on.',
58 required=True, 63 required=True,
59 ) 64 )
60 put_parser.add_argument( 65 put_parser.add_argument(
61 '-p', 66 '-p',
62 '--properties', 67 '--properties',
63 help='A file to load a JSON dict of properties from.', 68 help='A file to load a JSON dict of properties from.',
64 ) 69 )
65 args = parser.parse_args() 70 args = parser.parse_args()
66 # TODO(smut): When more commands are implemented, refactor this. 71 # TODO(smut): When more commands are implemented, refactor this.
67 assert args.command == 'put' 72 assert args.command == 'put'
68 73
74 changes = []
75 if args.changes:
76 try:
77 with open(args.changes) as fp:
78 changes.extend(json.load(fp))
79 except (TypeError, ValueError):
80 sys.stderr.write('%s contained invalid JSON list.\n' % args.changes)
81 raise
82
69 properties = {} 83 properties = {}
70 if args.properties: 84 if args.properties:
71 try: 85 try:
72 with open(args.properties) as fp: 86 with open(args.properties) as fp:
73 properties.update(json.load(fp)) 87 properties.update(json.load(fp))
74 except (TypeError, ValueError): 88 except (TypeError, ValueError):
75 sys.stderr.write('%s contained invalid JSON dict.\n' % args.properties) 89 sys.stderr.write('%s contained invalid JSON dict.\n' % args.properties)
76 raise 90 raise
77 91
78 authenticator = auth.get_authenticator_for_host( 92 authenticator = auth.get_authenticator_for_host(
79 BUILDBUCKET_URL, 93 BUILDBUCKET_URL,
80 auth.make_auth_config(use_oauth2=True), 94 auth.make_auth_config(use_oauth2=True),
81 ) 95 )
82 http = authenticator.authorize(httplib2.Http()) 96 http = authenticator.authorize(httplib2.Http())
83 http.force_exception_to_status_code = True 97 http.force_exception_to_status_code = True
84 response, content = http.request( 98 response, content = http.request(
85 PUT_BUILD_URL, 99 PUT_BUILD_URL,
86 'PUT', 100 'PUT',
87 body=json.dumps({ 101 body=json.dumps({
88 'bucket': args.bucket, 102 'bucket': args.bucket,
89 'parameters_json': json.dumps({ 103 'parameters_json': json.dumps({
90 'builder_name': args.builder_name, 104 'builder_name': args.builder_name,
105 'changes': changes,
91 'properties': properties, 106 'properties': properties,
92 }), 107 }),
93 }), 108 }),
94 headers={'Content-Type': 'application/json'}, 109 headers={'Content-Type': 'application/json'},
95 ) 110 )
96 111
97 if args.verbose: 112 if args.verbose:
98 print content 113 print content
99 114
100 return response.status != 200 115 return response.status != 200
101 116
102 117
103 if __name__ == '__main__': 118 if __name__ == '__main__':
104 sys.exit(main(sys.argv)) 119 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698