OLD | NEW |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Helper functions to upload data to logdog.""" | 5 """Helper functions to upload data to logdog.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import sys | 9 import sys |
10 | 10 |
11 from pylib import constants | 11 from pylib import constants |
12 from pylib.utils import decorators | 12 from pylib.utils import decorators |
13 | 13 |
14 sys.path.insert(0, os.path.abspath(os.path.join( | 14 sys.path.insert(0, os.path.abspath(os.path.join( |
15 constants.DIR_SOURCE_ROOT, 'tools', 'swarming_client'))) | 15 constants.DIR_SOURCE_ROOT, 'tools', 'swarming_client'))) |
16 from libs.logdog import bootstrap # pylint: disable=import-error | 16 from libs.logdog import bootstrap # pylint: disable=import-error |
17 | 17 |
18 | 18 |
19 @decorators.NoRaiseException(default_return_value='') | 19 @decorators.NoRaiseException(default_return_value='') |
20 def text(name, data): | 20 def text(name, data): |
21 """Uploads text to logdog. | 21 """Uploads text to logdog. |
22 | 22 |
23 Args: | 23 Args: |
24 name: Name of the logdog stream. | 24 name: Name of the logdog stream. |
25 data: String with data you want to upload. | 25 data: String with data you want to upload. |
26 | 26 |
27 Returns: | 27 Returns: |
28 Link to view uploaded text in logdog viewer. | 28 Link to view uploaded text in logdog viewer. |
29 """ | 29 """ |
30 logging.debug('Writing text to logdog stream, %s', name) | 30 logging.info('Writing text to logdog stream, %s', name) |
31 with get_logdog_client().text(name) as stream: | 31 with get_logdog_client().text(name) as stream: |
32 stream.write(data) | 32 stream.write(data) |
33 return stream.get_viewer_url() | 33 return stream.get_viewer_url() |
34 | 34 |
35 | 35 |
36 @decorators.NoRaiseException(default_return_value=None) | 36 @decorators.NoRaiseException(default_return_value=None) |
37 def open_text(name): | 37 def open_text(name): |
38 """Returns a file like object which you can write to. | 38 """Returns a file like object which you can write to. |
39 | 39 |
40 Args: | 40 Args: |
41 name: Name of the logdog stream. | 41 name: Name of the logdog stream. |
42 | 42 |
43 Returns: | 43 Returns: |
44 A file like object. close() file when done. | 44 A file like object. close() file when done. |
45 """ | 45 """ |
46 logging.debug('Opening text logdog stream, %s', name) | 46 logging.info('Opening text logdog stream, %s', name) |
47 return get_logdog_client().open_text(name) | 47 return get_logdog_client().open_text(name) |
48 | 48 |
49 | 49 |
50 @decorators.NoRaiseException(default_return_value='') | 50 @decorators.NoRaiseException(default_return_value='') |
51 def binary(name, binary_path): | 51 def binary(name, binary_path): |
52 """Uploads binary to logdog. | 52 """Uploads binary to logdog. |
53 | 53 |
54 Args: | 54 Args: |
55 name: Name of the logdog stream. | 55 name: Name of the logdog stream. |
56 binary_path: Path to binary you want to upload. | 56 binary_path: Path to binary you want to upload. |
57 | 57 |
58 Returns: | 58 Returns: |
59 Link to view uploaded binary in logdog viewer. | 59 Link to view uploaded binary in logdog viewer. |
60 """ | 60 """ |
61 logging.debug('Writing binary to logdog stream, %s', name) | 61 logging.info('Writing binary to logdog stream, %s', name) |
62 with get_logdog_client().binary(name) as stream: | 62 with get_logdog_client().binary(name) as stream: |
63 with open(binary_path, 'r') as f: | 63 with open(binary_path, 'r') as f: |
64 stream.write(f.read()) | 64 stream.write(f.read()) |
65 return stream.get_viewer_url() | 65 return stream.get_viewer_url() |
66 | 66 |
67 | 67 |
68 @decorators.NoRaiseException(default_return_value='') | 68 @decorators.NoRaiseException(default_return_value='') |
69 def get_viewer_url(name): | 69 def get_viewer_url(name): |
70 """Get Logdog viewer URL. | 70 """Get Logdog viewer URL. |
71 | 71 |
72 Args: | 72 Args: |
73 name: Name of the logdog stream. | 73 name: Name of the logdog stream. |
74 | 74 |
75 Returns: | 75 Returns: |
76 Link to view uploaded binary in logdog viewer. | 76 Link to view uploaded binary in logdog viewer. |
77 """ | 77 """ |
78 return get_logdog_client().get_viewer_url(name) | 78 return get_logdog_client().get_viewer_url(name) |
79 | 79 |
80 | 80 |
81 @decorators.Memoize | 81 @decorators.Memoize |
82 def get_logdog_client(): | 82 def get_logdog_client(): |
83 logging.debug('Getting logdog client.') | 83 logging.debug('Getting logdog client.') |
84 return bootstrap.ButlerBootstrap.probe().stream_client() | 84 return bootstrap.ButlerBootstrap.probe().stream_client() |
85 | |
OLD | NEW |