Josip Sokcevic | fb12b3f | 2021-04-19 18:09:50 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 2 | # Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 5 | """Run a pinned gsutil.""" |
| 6 | |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 7 | import argparse |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 8 | import base64 |
dnj@chromium.org | 605d81d | 2015-09-18 22:33:53 +0000 | [diff] [blame] | 9 | import contextlib |
primiano@chromium.org | df35176 | 2014-12-18 11:12:34 +0000 | [diff] [blame] | 10 | import hashlib |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 11 | import json |
primiano@chromium.org | df35176 | 2014-12-18 11:12:34 +0000 | [diff] [blame] | 12 | import os |
| 13 | import shutil |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 14 | import subprocess |
primiano@chromium.org | df35176 | 2014-12-18 11:12:34 +0000 | [diff] [blame] | 15 | import sys |
dnj@chromium.org | 605d81d | 2015-09-18 22:33:53 +0000 | [diff] [blame] | 16 | import tempfile |
| 17 | import time |
Gavin Mak | 1c1cc06 | 2023-08-30 15:33:44 +0000 | [diff] [blame] | 18 | import urllib.request |
Raul Tambre | b946b23 | 2019-03-26 14:48:46 +0000 | [diff] [blame] | 19 | |
primiano@chromium.org | df35176 | 2014-12-18 11:12:34 +0000 | [diff] [blame] | 20 | import zipfile |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 21 | |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 22 | GSUTIL_URL = 'https://storage.googleapis.com/pub/' |
| 23 | API_URL = 'https://www.googleapis.com/storage/v1/b/pub/o/' |
| 24 | |
| 25 | THIS_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 26 | DEFAULT_BIN_DIR = os.path.join(THIS_DIR, 'external_bin', 'gsutil') |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 27 | |
Dan Jacques | 509776e | 2017-09-07 18:01:08 -0700 | [diff] [blame] | 28 | IS_WINDOWS = os.name == 'nt' |
| 29 | |
Josip Sokcevic | 1909696 | 2022-03-10 17:56:09 +0000 | [diff] [blame] | 30 | VERSION = '4.68' |
Josip Sokcevic | fa474e8 | 2021-09-17 16:59:49 +0000 | [diff] [blame] | 31 | |
Aravind Vasudevan | 7af6169 | 2023-01-09 23:15:15 +0000 | [diff] [blame] | 32 | # Google OAuth Context required by gsutil. |
| 33 | LUCI_AUTH_SCOPES = [ |
| 34 | 'https://www.googleapis.com/auth/devstorage.full_control', |
| 35 | 'https://www.googleapis.com/auth/userinfo.email', |
| 36 | ] |
| 37 | |
Dan Jacques | 509776e | 2017-09-07 18:01:08 -0700 | [diff] [blame] | 38 | |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 39 | class InvalidGsutilError(Exception): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 40 | pass |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 41 | |
| 42 | |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 43 | def download_gsutil(version, target_dir): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 44 | """Downloads gsutil into the target_dir.""" |
| 45 | filename = 'gsutil_%s.zip' % version |
| 46 | target_filename = os.path.join(target_dir, filename) |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 47 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 48 | # Check if the target exists already. |
| 49 | if os.path.exists(target_filename): |
| 50 | md5_calc = hashlib.md5() |
| 51 | with open(target_filename, 'rb') as f: |
| 52 | while True: |
| 53 | buf = f.read(4096) |
| 54 | if not buf: |
| 55 | break |
| 56 | md5_calc.update(buf) |
| 57 | local_md5 = md5_calc.hexdigest() |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 58 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 59 | metadata_url = '%s%s' % (API_URL, filename) |
| 60 | metadata = json.load(urllib.request.urlopen(metadata_url)) |
| 61 | remote_md5 = base64.b64decode(metadata['md5Hash']).decode('utf-8') |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 62 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 63 | if local_md5 == remote_md5: |
| 64 | return target_filename |
| 65 | os.remove(target_filename) |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 66 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 67 | # Do the download. |
| 68 | url = '%s%s' % (GSUTIL_URL, filename) |
| 69 | u = urllib.request.urlopen(url) |
| 70 | with open(target_filename, 'wb') as f: |
| 71 | while True: |
| 72 | buf = u.read(4096) |
| 73 | if not buf: |
| 74 | break |
| 75 | f.write(buf) |
| 76 | return target_filename |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 77 | |
| 78 | |
dnj@chromium.org | 605d81d | 2015-09-18 22:33:53 +0000 | [diff] [blame] | 79 | @contextlib.contextmanager |
| 80 | def temporary_directory(base): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 81 | tmpdir = tempfile.mkdtemp(prefix='t', dir=base) |
| 82 | try: |
| 83 | yield tmpdir |
| 84 | finally: |
| 85 | if os.path.isdir(tmpdir): |
| 86 | shutil.rmtree(tmpdir) |
dnj@chromium.org | 605d81d | 2015-09-18 22:33:53 +0000 | [diff] [blame] | 87 | |
Quinten Yearsley | d9cbe7a | 2019-09-03 16:49:11 +0000 | [diff] [blame] | 88 | |
dnj@chromium.org | 605d81d | 2015-09-18 22:33:53 +0000 | [diff] [blame] | 89 | def ensure_gsutil(version, target, clean): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 90 | bin_dir = os.path.join(target, 'gsutil_%s' % version) |
| 91 | gsutil_bin = os.path.join(bin_dir, 'gsutil', 'gsutil') |
| 92 | gsutil_flag = os.path.join(bin_dir, 'gsutil', 'install.flag') |
| 93 | # We assume that if gsutil_flag exists, then we have a good version |
| 94 | # of the gsutil package. |
| 95 | if not clean and os.path.isfile(gsutil_flag): |
| 96 | # Everything is awesome! we're all done here. |
| 97 | return gsutil_bin |
| 98 | |
| 99 | if not os.path.exists(target): |
| 100 | try: |
| 101 | os.makedirs(target) |
| 102 | except FileExistsError: |
| 103 | # Another process is prepping workspace, so let's check if |
| 104 | # gsutil_bin is present. If after several checks it's still not, |
| 105 | # continue with downloading gsutil. |
| 106 | delay = 2 # base delay, in seconds |
| 107 | for _ in range(3): # make N attempts |
| 108 | # sleep first as it's not expected to have file ready just yet. |
| 109 | time.sleep(delay) |
| 110 | delay *= 1.5 # next delay increased by that factor |
| 111 | if os.path.isfile(gsutil_bin): |
| 112 | return gsutil_bin |
| 113 | |
| 114 | with temporary_directory(target) as instance_dir: |
| 115 | # Clean up if we're redownloading a corrupted gsutil. |
| 116 | cleanup_path = os.path.join(instance_dir, 'clean') |
| 117 | try: |
| 118 | os.rename(bin_dir, cleanup_path) |
| 119 | except (OSError, IOError): |
| 120 | cleanup_path = None |
| 121 | if cleanup_path: |
| 122 | shutil.rmtree(cleanup_path) |
| 123 | |
| 124 | download_dir = os.path.join(instance_dir, 'd') |
| 125 | target_zip_filename = download_gsutil(version, instance_dir) |
| 126 | with zipfile.ZipFile(target_zip_filename, 'r') as target_zip: |
| 127 | target_zip.extractall(download_dir) |
| 128 | |
| 129 | shutil.move(download_dir, bin_dir) |
| 130 | # Final check that the gsutil bin exists. This should never fail. |
| 131 | if not os.path.isfile(gsutil_bin): |
| 132 | raise InvalidGsutilError() |
| 133 | # Drop a flag file. |
| 134 | with open(gsutil_flag, 'w') as f: |
| 135 | f.write('This flag file is dropped by gsutil.py') |
| 136 | |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 137 | return gsutil_bin |
| 138 | |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 139 | |
Aravind Vasudevan | 7af6169 | 2023-01-09 23:15:15 +0000 | [diff] [blame] | 140 | def _is_luci_context(): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 141 | """Returns True if the script is run within luci-context""" |
| 142 | if os.getenv('SWARMING_HEADLESS') == '1': |
| 143 | return True |
Aravind Vasudevan | 3879bd8 | 2023-02-16 23:09:33 +0000 | [diff] [blame] | 144 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 145 | luci_context_env = os.getenv('LUCI_CONTEXT') |
| 146 | if not luci_context_env: |
| 147 | return False |
Aravind Vasudevan | 7af6169 | 2023-01-09 23:15:15 +0000 | [diff] [blame] | 148 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 149 | try: |
| 150 | with open(luci_context_env) as f: |
| 151 | luci_context_json = json.load(f) |
| 152 | return 'local_auth' in luci_context_json |
| 153 | except (ValueError, FileNotFoundError): |
| 154 | return False |
Aravind Vasudevan | 7af6169 | 2023-01-09 23:15:15 +0000 | [diff] [blame] | 155 | |
| 156 | |
| 157 | def luci_context(cmd): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 158 | """Helper to call`luci-auth context`.""" |
| 159 | p = _luci_auth_cmd('context', wrapped_cmds=cmd) |
Aravind Vasudevan | effdecd | 2023-01-30 17:02:17 +0000 | [diff] [blame] | 160 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 161 | # If luci-auth is not logged in, fallback to normal execution. |
| 162 | if b'Not logged in.' in p.stderr: |
| 163 | return _run_subprocess(cmd, interactive=True) |
Aravind Vasudevan | effdecd | 2023-01-30 17:02:17 +0000 | [diff] [blame] | 164 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 165 | _print_subprocess_result(p) |
| 166 | return p |
Aravind Vasudevan | 7af6169 | 2023-01-09 23:15:15 +0000 | [diff] [blame] | 167 | |
| 168 | |
| 169 | def luci_login(): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 170 | """Helper to run `luci-auth login`.""" |
| 171 | # luci-auth requires interactive shell. |
| 172 | return _luci_auth_cmd('login', interactive=True) |
Aravind Vasudevan | 7af6169 | 2023-01-09 23:15:15 +0000 | [diff] [blame] | 173 | |
| 174 | |
Aravind Vasudevan | 1757677 | 2023-01-13 19:50:51 +0000 | [diff] [blame] | 175 | def _luci_auth_cmd(luci_cmd, wrapped_cmds=None, interactive=False): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 176 | """Helper to call luci-auth command.""" |
| 177 | cmd = ['luci-auth', luci_cmd, '-scopes', ' '.join(LUCI_AUTH_SCOPES)] |
| 178 | if wrapped_cmds: |
| 179 | cmd += ['--'] + wrapped_cmds |
Aravind Vasudevan | 7af6169 | 2023-01-09 23:15:15 +0000 | [diff] [blame] | 180 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 181 | return _run_subprocess(cmd, interactive) |
Aravind Vasudevan | b7d8efd | 2023-01-27 18:46:40 +0000 | [diff] [blame] | 182 | |
| 183 | |
Aravind Vasudevan | 1757677 | 2023-01-13 19:50:51 +0000 | [diff] [blame] | 184 | def _run_subprocess(cmd, interactive=False, env=None): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 185 | """Wrapper to run the given command within a subprocess.""" |
| 186 | kwargs = {'shell': IS_WINDOWS} |
Aravind Vasudevan | 1757677 | 2023-01-13 19:50:51 +0000 | [diff] [blame] | 187 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 188 | if env: |
| 189 | kwargs['env'] = dict(os.environ, **env) |
Aravind Vasudevan | 1757677 | 2023-01-13 19:50:51 +0000 | [diff] [blame] | 190 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 191 | if not interactive: |
| 192 | kwargs['stdout'] = subprocess.PIPE |
| 193 | kwargs['stderr'] = subprocess.PIPE |
Aravind Vasudevan | 1757677 | 2023-01-13 19:50:51 +0000 | [diff] [blame] | 194 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 195 | return subprocess.run(cmd, **kwargs) |
Aravind Vasudevan | 7af6169 | 2023-01-09 23:15:15 +0000 | [diff] [blame] | 196 | |
| 197 | |
Aravind Vasudevan | 3879bd8 | 2023-02-16 23:09:33 +0000 | [diff] [blame] | 198 | def _print_subprocess_result(p): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 199 | """Prints the subprocess result to stdout & stderr.""" |
| 200 | if p.stdout: |
| 201 | sys.stdout.buffer.write(p.stdout) |
Aravind Vasudevan | 3879bd8 | 2023-02-16 23:09:33 +0000 | [diff] [blame] | 202 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 203 | if p.stderr: |
| 204 | sys.stderr.buffer.write(p.stderr) |
Aravind Vasudevan | 3879bd8 | 2023-02-16 23:09:33 +0000 | [diff] [blame] | 205 | |
| 206 | |
Aravind Vasudevan | 7b1f98e | 2023-01-18 17:34:15 +0000 | [diff] [blame] | 207 | def is_boto_present(): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 208 | """Returns true if the .boto file is present in the default path.""" |
| 209 | return os.getenv('BOTO_CONFIG') or os.getenv( |
| 210 | 'AWS_CREDENTIAL_FILE') or os.path.isfile( |
| 211 | os.path.join(os.path.expanduser('~'), '.boto')) |
Aravind Vasudevan | 7b1f98e | 2023-01-18 17:34:15 +0000 | [diff] [blame] | 212 | |
| 213 | |
Josip Sokcevic | fa474e8 | 2021-09-17 16:59:49 +0000 | [diff] [blame] | 214 | def run_gsutil(target, args, clean=False): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 215 | # Redirect gsutil config calls to luci-auth. |
| 216 | if 'config' in args: |
| 217 | return luci_login().returncode |
Aravind Vasudevan | 7af6169 | 2023-01-09 23:15:15 +0000 | [diff] [blame] | 218 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 219 | gsutil_bin = ensure_gsutil(VERSION, target, clean) |
| 220 | args_opt = ['-o', 'GSUtil:software_update_check_period=0'] |
Dan Jacques | 509776e | 2017-09-07 18:01:08 -0700 | [diff] [blame] | 221 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 222 | if sys.platform == 'darwin': |
| 223 | # We are experiencing problems with multiprocessing on MacOS where |
| 224 | # gsutil.py may hang. This behavior is documented in gsutil codebase, |
| 225 | # and recommendation is to set GSUtil:parallel_process_count=1. |
| 226 | # https://github.com/GoogleCloudPlatform/gsutil/blob/06efc9dc23719fab4fd5fadb506d252bbd3fe0dd/gslib/command.py#L1331 |
| 227 | # https://github.com/GoogleCloudPlatform/gsutil/issues/1100 |
| 228 | args_opt.extend(['-o', 'GSUtil:parallel_process_count=1']) |
| 229 | if sys.platform == 'cygwin': |
| 230 | # This script requires Windows Python, so invoke with depot_tools' |
| 231 | # Python. |
| 232 | def winpath(path): |
| 233 | stdout = subprocess.check_output(['cygpath', '-w', path]) |
| 234 | return stdout.strip().decode('utf-8', 'replace') |
Chris Nardi | ab816ce | 2017-10-31 15:45:05 -0400 | [diff] [blame] | 235 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 236 | cmd = ['python.bat', winpath(__file__)] |
| 237 | cmd.extend(args) |
| 238 | sys.exit(subprocess.call(cmd)) |
| 239 | assert sys.platform != 'cygwin' |
Aravind Vasudevan | 7af6169 | 2023-01-09 23:15:15 +0000 | [diff] [blame] | 240 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 241 | cmd = [ |
| 242 | 'vpython3', '-vpython-spec', |
| 243 | os.path.join(THIS_DIR, 'gsutil.vpython3'), '--', gsutil_bin |
| 244 | ] + args_opt + args |
Aravind Vasudevan | 3879bd8 | 2023-02-16 23:09:33 +0000 | [diff] [blame] | 245 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 246 | # When .boto is present, try without additional wrappers and handle specific |
| 247 | # errors. |
| 248 | if is_boto_present(): |
| 249 | p = _run_subprocess(cmd) |
Aravind Vasudevan | 3879bd8 | 2023-02-16 23:09:33 +0000 | [diff] [blame] | 250 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 251 | # Notify user that their .boto file might be outdated. |
| 252 | if b'Your credentials are invalid.' in p.stderr: |
| 253 | # Make sure this error message is visible when invoked by gclient |
| 254 | # runhooks |
| 255 | separator = '*' * 80 |
| 256 | print( |
| 257 | '\n' + separator + '\n' + |
| 258 | 'Warning: You might have an outdated .boto file. If this issue ' |
| 259 | 'persists after running `gsutil.py config`, try removing your ' |
| 260 | '.boto, usually located in your home directory.\n' + separator + |
| 261 | '\n', |
| 262 | file=sys.stderr) |
Aravind Vasudevan | 3879bd8 | 2023-02-16 23:09:33 +0000 | [diff] [blame] | 263 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 264 | _print_subprocess_result(p) |
| 265 | return p.returncode |
Aravind Vasudevan | 7af6169 | 2023-01-09 23:15:15 +0000 | [diff] [blame] | 266 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 267 | # Skip wrapping commands if luci-auth is already being |
| 268 | if _is_luci_context(): |
| 269 | return _run_subprocess(cmd, interactive=True).returncode |
| 270 | |
| 271 | # Wrap gsutil with luci-auth context. |
| 272 | return luci_context(cmd).returncode |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 273 | |
| 274 | |
| 275 | def parse_args(): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 276 | bin_dir = os.environ.get('DEPOT_TOOLS_GSUTIL_BIN_DIR', DEFAULT_BIN_DIR) |
dnj@chromium.org | 605d81d | 2015-09-18 22:33:53 +0000 | [diff] [blame] | 277 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 278 | # Help is disabled as it conflicts with gsutil -h, which controls headers. |
| 279 | parser = argparse.ArgumentParser(add_help=False) |
Josip Sokcevic | fa474e8 | 2021-09-17 16:59:49 +0000 | [diff] [blame] | 280 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 281 | parser.add_argument( |
| 282 | '--clean', |
| 283 | action='store_true', |
| 284 | help='Clear any existing gsutil package, forcing a new download.') |
| 285 | parser.add_argument( |
| 286 | '--target', |
| 287 | default=bin_dir, |
| 288 | help='The target directory to download/store a gsutil version in. ' |
| 289 | '(default is %(default)s).') |
Josip Sokcevic | fa474e8 | 2021-09-17 16:59:49 +0000 | [diff] [blame] | 290 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 291 | # These two args exist for backwards-compatibility but are no-ops. |
| 292 | parser.add_argument('--force-version', |
| 293 | default=VERSION, |
| 294 | help='(deprecated, this flag has no effect)') |
| 295 | parser.add_argument('--fallback', |
| 296 | help='(deprecated, this flag has no effect)') |
Josip Sokcevic | fa474e8 | 2021-09-17 16:59:49 +0000 | [diff] [blame] | 297 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 298 | parser.add_argument('args', nargs=argparse.REMAINDER) |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 299 | |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 300 | args, extras = parser.parse_known_args() |
| 301 | if args.args and args.args[0] == '--': |
| 302 | args.args.pop(0) |
| 303 | if extras: |
| 304 | args.args = extras + args.args |
| 305 | return args |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 306 | |
| 307 | |
| 308 | def main(): |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 309 | args = parse_args() |
| 310 | return run_gsutil(args.target, args.args, clean=args.clean) |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 311 | |
Quinten Yearsley | d9cbe7a | 2019-09-03 16:49:11 +0000 | [diff] [blame] | 312 | |
hinoka@chromium.org | 7a79054 | 2014-12-10 02:04:39 +0000 | [diff] [blame] | 313 | if __name__ == '__main__': |
Mike Frysinger | 124bb8e | 2023-09-06 05:48:55 +0000 | [diff] [blame] | 314 | sys.exit(main()) |