diff options
author | Gavin Mak <gavinmak@google.com> | 2023-03-11 06:46:20 +0000 |
---|---|---|
committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-03-22 17:46:28 +0000 |
commit | ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1 (patch) | |
tree | dc33ba0e56825b3e007d0589891756724725a465 /fetch.py | |
parent | 1604cf255f8c1786a23388db6d5277ac7949a24a (diff) | |
download | git-repo-ea2e330e43c182dc16b0111ebc69ee5a71ee4ce1.tar.gz |
Format codebase with black and check formatting in CQ
Apply rules set by https://gerrit-review.googlesource.com/c/git-repo/+/362954/ across the codebase and fix any lingering errors caught
by flake8. Also check black formatting in run_tests (and CQ).
Bug: b/267675342
Change-Id: I972d77649dac351150dcfeb1cd1ad0ea2efc1956
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/363474
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Diffstat (limited to 'fetch.py')
-rw-r--r-- | fetch.py | 46 |
1 files changed, 25 insertions, 21 deletions
@@ -21,25 +21,29 @@ from urllib.request import urlopen | |||
21 | 21 | ||
22 | 22 | ||
23 | def fetch_file(url, verbose=False): | 23 | def fetch_file(url, verbose=False): |
24 | """Fetch a file from the specified source using the appropriate protocol. | 24 | """Fetch a file from the specified source using the appropriate protocol. |
25 | 25 | ||
26 | Returns: | 26 | Returns: |
27 | The contents of the file as bytes. | 27 | The contents of the file as bytes. |
28 | """ | 28 | """ |
29 | scheme = urlparse(url).scheme | 29 | scheme = urlparse(url).scheme |
30 | if scheme == 'gs': | 30 | if scheme == "gs": |
31 | cmd = ['gsutil', 'cat', url] | 31 | cmd = ["gsutil", "cat", url] |
32 | try: | 32 | try: |
33 | result = subprocess.run( | 33 | result = subprocess.run( |
34 | cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 34 | cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True |
35 | check=True) | 35 | ) |
36 | if result.stderr and verbose: | 36 | if result.stderr and verbose: |
37 | print('warning: non-fatal error running "gsutil": %s' % result.stderr, | 37 | print( |
38 | file=sys.stderr) | 38 | 'warning: non-fatal error running "gsutil": %s' |
39 | return result.stdout | 39 | % result.stderr, |
40 | except subprocess.CalledProcessError as e: | 40 | file=sys.stderr, |
41 | print('fatal: error running "gsutil": %s' % e.stderr, | 41 | ) |
42 | file=sys.stderr) | 42 | return result.stdout |
43 | sys.exit(1) | 43 | except subprocess.CalledProcessError as e: |
44 | with urlopen(url) as f: | 44 | print( |
45 | return f.read() | 45 | 'fatal: error running "gsutil": %s' % e.stderr, file=sys.stderr |
46 | ) | ||
47 | sys.exit(1) | ||
48 | with urlopen(url) as f: | ||
49 | return f.read() | ||