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

Side by Side Diff: scripts/common/cros_chromite.py

Issue 2108713004: chromite: check response status code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: fix request Created 4 years, 5 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 python2.7 1 #!/usr/bin/env python2.7
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 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 """ 6 """
7 This module wraps ChromeOS's Chromite configuration, providing retrieval 7 This module wraps ChromeOS's Chromite configuration, providing retrieval
8 methods and Infra-aware introspection. 8 methods and Infra-aware introspection.
9 9
10 For any given ChromeOS build, Chromite may be pinned to a specific ChromeOS 10 For any given ChromeOS build, Chromite may be pinned to a specific ChromeOS
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 493
494 Raises: 494 Raises:
495 GitilesError: If there was an unexpected failure with the Gitiles service. 495 GitilesError: If there was an unexpected failure with the Gitiles service.
496 """ 496 """
497 logging.warning('Loading Chromite configuration from: %s', url) 497 logging.warning('Loading Chromite configuration from: %s', url)
498 498
499 try: 499 try:
500 # Force no authentication. Chromite is public! By default, 'requests' will 500 # Force no authentication. Chromite is public! By default, 'requests' will
501 # use 'netrc' for authentication. This can cause the load to fail if 501 # use 'netrc' for authentication. This can cause the load to fail if
502 # the '.netrc' has an invalid entry, failing authentication. 502 # the '.netrc' has an invalid entry, failing authentication.
503 return requests.get( 503 res = requests.get(
504 url, 504 url,
505 verify=True, 505 verify=True,
506 auth=lambda r: r).text 506 auth=lambda r: r)
507 if res.status_code != 200:
508 raise GitilesError(
509 url, 'Unexpected HTTP status code %d; body: %s' % (
510 res.status_code, res.text))
511 return res.text
507 except requests.exceptions.RequestException as e: 512 except requests.exceptions.RequestException as e:
508 raise GitilesError(url, 'Request raised exception: %s' % (e,)) 513 raise GitilesError(url, 'Request raised exception: %s' % (e,))
509 514
510 def __call__(self, name, version): 515 def __call__(self, name, version):
511 """Returns: (str) the contents of a specified file from Gitiles. 516 """Returns: (str) the contents of a specified file from Gitiles.
512 517
513 Args: 518 Args:
514 name: (str) The artifact name. In this case, it's the pinned branch. 519 name: (str) The artifact name. In this case, it's the pinned branch.
515 version: (str) The requested version. In this case, it's a Git commit. 520 version: (str) The requested version. In this case, it's a Git commit.
516 If None, the pinned Git commit of the 'name' branch will be used. 521 If None, the pinned Git commit of the 'name' branch will be used.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 634
630 # Allow this script to be used as a bootstrap to fetch/cache Chromite 635 # Allow this script to be used as a bootstrap to fetch/cache Chromite
631 # artifacts (gclient runhooks). 636 # artifacts (gclient runhooks).
632 if __name__ == '__main__': 637 if __name__ == '__main__':
633 logging.basicConfig() 638 logging.basicConfig()
634 try: 639 try:
635 sys.exit(main(sys.argv[1:], DefaultChromitePinManager)) 640 sys.exit(main(sys.argv[1:], DefaultChromitePinManager))
636 except Exception as e: 641 except Exception as e:
637 logging.exception("Uncaught execption: %s", e) 642 logging.exception("Uncaught execption: %s", e)
638 sys.exit(1) 643 sys.exit(1)
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