1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
6 from recipe_engine import recipe_api
10 class GSUtilApi(recipe_api.RecipeApi):
11 def __call__(self, step_name, *args):
12 """Run gsutil with the given args.
14 This assumes there exists an executable called gsutil on the PATH.
15 This probably only works for Linux/Mac, but those are the only
16 hosts that we try to upload to GCS from anyway.
18 return self.m.step(step_name, cmd=['gsutil'] + list(args))
20 def cp(self, name, src, dst, extra_args=None, multithread=False):
21 """Attempt to upload or download files to/from Google Cloud Storage (GCS).
24 name: string. Will be used to fill out the step name.
25 src: string. Absolute path for a local file or gcs file (e.g. gs://...)
26 dst: string. Same as src.
27 extra_args: optional list of args to be passed to gsutil. e.g. [-Z] asks
28 all files be compressed with gzip after upload and before download.
29 multi_thread: if the -m argument should be used to copy multiple items
30 at once (e.g. gsutil -m cp foo* gs://bar/dir)
32 If the operation fails, it will be retried multiple times.
38 cmd.extend(extra_args)
39 cmd.extend([src, dst])
41 name = 'upload %s' % name
42 for i in range(UPLOAD_ATTEMPTS):
45 step_name += ' (attempt %d)' % (i+1)
49 except self.m.step.StepFailure:
50 if i == UPLOAD_ATTEMPTS - 1: