Chromium Code Reviews| Index: build/android/pylib/utils/logdog_helper.py |
| diff --git a/build/android/pylib/utils/logdog_helper.py b/build/android/pylib/utils/logdog_helper.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3b19e1640fdf969ef4d90e10c460490d3f5e67af |
| --- /dev/null |
| +++ b/build/android/pylib/utils/logdog_helper.py |
| @@ -0,0 +1,80 @@ |
| +# Copyright 2017 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Helper functions to upload data to logdog.""" |
| + |
| +import os |
| +import sys |
| + |
| +from pylib import constants |
| +from pylib.utils import python_utils |
| + |
| +sys.path.insert(0, os.path.abspath(os.path.join( |
| + constants.DIR_SOURCE_ROOT, 'tools', 'swarming_client'))) |
| +from libs.logdog import bootstrap # pylint: disable=import-error |
| + |
| + |
| +@python_utils.NoRaiseException(default_return_value='') |
|
mikecase (-- gone --)
2017/01/30 23:20:49
Currently, all of the logdog code is surrounded in
|
| +def text(name, data): |
| + """Uploads text to logdog. |
| + |
| + Args: |
| + name: Name of the logdog stream. |
| + data: String with data you want to upload. |
| + |
| + Returns: |
| + Link to view uploaded text in logdog viewer. |
| + """ |
| + with get_logdog_client().text(name) as stream: |
| + stream.write(data) |
| + return stream.get_viewer_url() |
| + |
| + |
| +@python_utils.NoRaiseException(default_return_value=None) |
| +def open_text(name): |
| + """Returns a file like object which you can write to. |
| + |
| + Args: |
| + name: Name of the logdog stream. |
| + |
| + Returns: |
| + A file like object. close() file when done. |
| + """ |
| + return get_logdog_client().open_text(name) |
| + |
| + |
| +@python_utils.NoRaiseException(default_return_value='') |
| +def binary(name, binary_path): |
| + """Uploads binary to logdog. |
| + |
| + Args: |
| + name: Name of the logdog stream. |
| + binary_path: Path to binary you want to upload. |
| + |
| + Returns: |
| + Link to view uploaded binary in logdog viewer. |
| + """ |
| + with get_logdog_client().binary(name) as stream: |
| + with open(binary_path, 'r') as f: |
| + stream.write(f.read()) |
| + return stream.get_viewer_url() |
| + |
| + |
| +@python_utils.NoRaiseException(default_return_value='') |
| +def get_viewer_url(name): |
| + """Get Logdog viewer URL. |
| + |
| + Args: |
| + name: Name of the logdog stream. |
| + |
| + Returns: |
| + Link to view uploaded binary in logdog viewer. |
| + """ |
| + return get_logdog_client().get_viewer_url(name) |
| + |
| + |
| +@python_utils.Memoize |
|
mikecase (-- gone --)
2017/01/30 23:20:49
Pretty sure (99%) you only need to get the stream_
jbudorick
2017/01/31 16:11:53
I'm not sure I like this, though you may be right.
|
| +def get_logdog_client(): |
| + return bootstrap.ButlerBootstrap.probe().stream_client() |
| + |