summaryrefslogtreecommitdiffstats
path: root/fetch.py
diff options
context:
space:
mode:
authorJack Neus <jackneus@google.com>2021-07-26 23:08:54 +0000
committerJack Neus <jackneus@google.com>2021-09-28 15:40:46 +0000
commitc474c9cba1a8fbe09c219cc588d9ed334d31cd1e (patch)
tree16cfecbac2dcd974c7971536bf2bda15d7296f66 /fetch.py
parent956f7363d100abe6c1f58b36d7aea59b9e41cd04 (diff)
downloadgit-repo-c474c9cba1a8fbe09c219cc588d9ed334d31cd1e.tar.gz
repo: Add support for standalone manifests
Added --standalone_manifest to repo tool. If set, the manifest is downloaded directly from the appropriate source (currently, we only support GS) and used instead of creating a manifest git checkout. The manifests.git repo is still created to keep track of various config but is marked as being for a standalone manifest so that the repo tool doesn't try to run networked git commands in it. BUG=b:192664812 TEST=existing tests (no coverage), manual runs Change-Id: I84378cbc7f8e515eabeccdde9665efc8cd2a9d21 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/312942 Tested-by: Jack Neus <jackneus@google.com> Reviewed-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'fetch.py')
-rw-r--r--fetch.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/fetch.py b/fetch.py
new file mode 100644
index 00000000..5b9997a8
--- /dev/null
+++ b/fetch.py
@@ -0,0 +1,38 @@
1# Copyright (C) 2021 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""This module contains functions used to fetch files from various sources."""
16
17import subprocess
18import sys
19from urllib.parse import urlparse
20
21def fetch_file(url):
22 """Fetch a file from the specified source using the appropriate protocol.
23
24 Returns:
25 The contents of the file as bytes.
26 """
27 scheme = urlparse(url).scheme
28 if scheme == 'gs':
29 cmd = ['gsutil', 'cat', url]
30 try:
31 result = subprocess.run(
32 cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
33 return result.stdout
34 except subprocess.CalledProcessError as e:
35 print('fatal: error running "gsutil": %s' % e.output,
36 file=sys.stderr)
37 sys.exit(1)
38 raise ValueError('unsupported url %s' % url)