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 exception_message='Ignore this exception.') | |
mikecase (-- gone --)
2017/04/26 20:59:49
nit: I would link a crbug here with some context.
BigBossZhiling
2017/04/26 21:24:07
Done.
| |
20 def text(name, data): | 21 def text(name, data): |
21 """Uploads text to logdog. | 22 """Uploads text to logdog. |
22 | 23 |
23 Args: | 24 Args: |
24 name: Name of the logdog stream. | 25 name: Name of the logdog stream. |
25 data: String with data you want to upload. | 26 data: String with data you want to upload. |
26 | 27 |
27 Returns: | 28 Returns: |
28 Link to view uploaded text in logdog viewer. | 29 Link to view uploaded text in logdog viewer. |
29 """ | 30 """ |
30 logging.info('Writing text to logdog stream, %s', name) | 31 logging.info('Writing text to logdog stream, %s', name) |
31 with get_logdog_client().text(name) as stream: | 32 with get_logdog_client().text(name) as stream: |
32 stream.write(data) | 33 stream.write(data) |
33 return stream.get_viewer_url() | 34 return stream.get_viewer_url() |
34 | 35 |
35 | 36 |
36 @decorators.NoRaiseException(default_return_value=None) | 37 @decorators.NoRaiseException(default_return_value=None, |
38 exception_message='Ignore this exception.') | |
37 def open_text(name): | 39 def open_text(name): |
38 """Returns a file like object which you can write to. | 40 """Returns a file like object which you can write to. |
39 | 41 |
40 Args: | 42 Args: |
41 name: Name of the logdog stream. | 43 name: Name of the logdog stream. |
42 | 44 |
43 Returns: | 45 Returns: |
44 A file like object. close() file when done. | 46 A file like object. close() file when done. |
45 """ | 47 """ |
46 logging.info('Opening text logdog stream, %s', name) | 48 logging.info('Opening text logdog stream, %s', name) |
47 return get_logdog_client().open_text(name) | 49 return get_logdog_client().open_text(name) |
48 | 50 |
49 | 51 |
50 @decorators.NoRaiseException(default_return_value='') | 52 @decorators.NoRaiseException(default_return_value='', |
53 exception_message='Ignore this exception.') | |
51 def binary(name, binary_path): | 54 def binary(name, binary_path): |
52 """Uploads binary to logdog. | 55 """Uploads binary to logdog. |
53 | 56 |
54 Args: | 57 Args: |
55 name: Name of the logdog stream. | 58 name: Name of the logdog stream. |
56 binary_path: Path to binary you want to upload. | 59 binary_path: Path to binary you want to upload. |
57 | 60 |
58 Returns: | 61 Returns: |
59 Link to view uploaded binary in logdog viewer. | 62 Link to view uploaded binary in logdog viewer. |
60 """ | 63 """ |
61 logging.info('Writing binary to logdog stream, %s', name) | 64 logging.info('Writing binary to logdog stream, %s', name) |
62 with get_logdog_client().binary(name) as stream: | 65 with get_logdog_client().binary(name) as stream: |
63 with open(binary_path, 'r') as f: | 66 with open(binary_path, 'r') as f: |
64 stream.write(f.read()) | 67 stream.write(f.read()) |
65 return stream.get_viewer_url() | 68 return stream.get_viewer_url() |
66 | 69 |
67 | 70 |
68 @decorators.NoRaiseException(default_return_value='') | 71 @decorators.NoRaiseException(default_return_value='', |
72 exception_message='Ignore this exception.') | |
69 def get_viewer_url(name): | 73 def get_viewer_url(name): |
70 """Get Logdog viewer URL. | 74 """Get Logdog viewer URL. |
71 | 75 |
72 Args: | 76 Args: |
73 name: Name of the logdog stream. | 77 name: Name of the logdog stream. |
74 | 78 |
75 Returns: | 79 Returns: |
76 Link to view uploaded binary in logdog viewer. | 80 Link to view uploaded binary in logdog viewer. |
77 """ | 81 """ |
78 return get_logdog_client().get_viewer_url(name) | 82 return get_logdog_client().get_viewer_url(name) |
79 | 83 |
80 | 84 |
81 @decorators.Memoize | 85 @decorators.Memoize |
82 def get_logdog_client(): | 86 def get_logdog_client(): |
83 logging.info('Getting logdog client.') | 87 logging.info('Getting logdog client.') |
84 return bootstrap.ButlerBootstrap.probe().stream_client() | 88 return bootstrap.ButlerBootstrap.probe().stream_client() |
85 | 89 |
OLD | NEW |