@@ -0,0 +1,2464 @@
+#!/usr/bin/env python%0A# Copyright (c) 2015 The Chromium Authors. All rights reserved.%0A# Use of this source code is governed by a BSD-style license that can be%0A# found in the LICENSE file.%0A%0A%22%22%22Tool for interacting with Buildbucket.%0A%0AUsage:%0A  $ depot-tools-auth login https://cr-buildbucket.appspot.com%0A  $ buildbucket.py %5C%0A    put %5C%0A    --bucket master.tryserver.chromium.linux %5C%0A    --builder my-builder %5C%0A%0A  Puts a build into buildbucket for my-builder on tryserver.chromium.linux.%0A%22%22%22%0A%0Aimport argparse%0Aimport json%0Aimport urlparse%0Aimport os%0Aimport sys%0A%0Afrom third_party import httplib2%0A%0Aimport auth%0A%0A%0ABUILDBUCKET_URL = 'https://cr-buildbucket.appspot.com'%0APUT_BUILD_URL = urlparse.urljoin(%0A  BUILDBUCKET_URL,%0A  '_ah/api/buildbucket/v1/builds',%0A)%0A%0A%0Adef main(argv):%0A  parser = argparse.ArgumentParser()%0A  parser.add_argument(%0A    '-v',%0A    '--verbose',%0A    action='store_true',%0A  )%0A  subparsers = parser.add_subparsers(dest='command')%0A  put_parser = subparsers.add_parser('put')%0A  put_parser.add_argument(%0A    '--bucket',%0A    help=(%0A      'The bucket to schedule the build on. Typically the master name, e.g.'%0A      ' master.tryserver.chromium.linux.'%0A    ),%0A    required=True,%0A  )%0A  put_parser.add_argument(%0A    '-n',%0A    '--builder-name',%0A    help='The builder to schedule the build on.',%0A    required=True,%0A  )%0A  put_parser.add_argument(%0A    '-p',%0A    '--properties',%0A    help='A file to load a JSON dict of properties from.',%0A  )%0A  args = parser.parse_args()%0A  # TODO(smut): When more commands are implemented, refactor this.%0A  assert args.command == 'put'%0A%0A  properties = %7B%7D%0A  if args.properties:%0A    try:%0A      with open(args.properties) as fp:%0A        properties.update(json.load(fp))%0A    except (TypeError, ValueError):%0A      sys.stderr.write('%25s contained invalid JSON dict.%5Cn' %25 args.properties)%0A      raise%0A%0A  authenticator = auth.get_authenticator_for_host(%0A    BUILDBUCKET_URL,%0A    auth.make_auth_config(use_oauth2=True),%0A  )%0A  http = authenticator.authorize(httplib2.Http())%0A  http.force_exception_to_status_code = True%0A  response, content = http.request(%0A    PUT_BUILD_URL,%0A    'PUT',%0A    body=json.dumps(%7B%0A      'bucket': args.bucket,%0A      'parameters_json': json.dumps(%7B%0A        'builder_name': args.builder_name,%0A        'properties': properties,%0A      %7D),%0A    %7D),%0A    headers=%7B'Content-Type': 'application/json'%7D,%0A  )%0A%0A  if args.verbose:%0A    print content%0A%0A  return response.status != 200%0A%0A%0Aif __name__ == '__main__':%0A  sys.exit(main(sys.argv))%0A

Add script for triggering Buildbucket builds