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

Side by Side Diff: build/android/pylib/utils/google_storage_helper.py

Issue 2701473003: Add failure screenshots and render test images to results detail. (Closed)
Patch Set: Add failure screenshots and render test images to results detail. Created 3 years, 10 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
OLDNEW
(Empty)
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.
4
5 """Helper functions to upload data to Google Storage.
6
7 Text data should be streamed to logdog using |logdog_helper| module.
8 Due to logdog not having image or HTML viewer, those instead should be uploaded
9 to Google Storage directly using this module.
10 """
11
12 import logging
13 import os
14 import sys
15 import time
16
17 from devil.utils import cmd_helper
18 from pylib.constants import host_paths
19 from pylib.utils import decorators
20
21 sys.path.append(os.path.join(host_paths.DIR_SOURCE_ROOT, 'build'))
22 import find_depot_tools # pylint: disable=import-error
23
24 _URL_TEMPLATE = 'https://storage.googleapis.com/%s/'
25
26
27 @decorators.NoRaiseException(default_return_value='')
28 def upload(name, filepath, bucket):
29 """Uploads data to Google Storage.
30
31 Args:
32 name: Name of the file on Google Storage.
33 filepath: Path to file you want to upload.
34 bucket: Bucket to upload file to.
35 """
36 gs_path = os.path.join('gs://%s/' % bucket, name)
37 logging.info('Uploading %s to %s', filepath, gs_path)
38 cmd_helper.RunCmd(
39 [os.path.join(find_depot_tools.DEPOT_TOOLS_PATH, 'gsutil.py'), 'cp',
40 filepath, gs_path])
41
42 return os.path.join(_URL_TEMPLATE % bucket, name)
43
44
45 def unique_name(basename, timestamp=True, device=None):
46 """Helper function for creating a unique name for a logdog stream.
47
48 Args:
49 basename: Base of the unique name.
50 timestamp: Whether or not to add a timestamp to name.
51 device: Device to add device serial of to name.
52 """
53 return '%s%s%s' % (
54 basename,
55 '_%s' % time.strftime('%Y%m%dT%H%M%S', time.localtime())
56 if timestamp else '',
57 '_%s' % device.serial if device else '')
OLDNEW
« no previous file with comments | « build/android/pylib/local/device/local_device_instrumentation_test_run.py ('k') | build/android/pylib/utils/logdog_helper.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698