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

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

Issue 2664873002: Add logdog_helper script. (Closed)
Patch Set: Add logdog_helper script. 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 logdog."""
6
7 import os
8 import sys
9
10 from pylib import constants
11 from pylib.utils import decorators
12
13 sys.path.insert(0, os.path.abspath(os.path.join(
14 constants.DIR_SOURCE_ROOT, 'tools', 'swarming_client')))
15 from libs.logdog import bootstrap # pylint: disable=import-error
16
17
18 @decorators.NoRaiseException(default_return_value='')
19 def text(name, data):
20 """Uploads text to logdog.
21
22 Args:
23 name: Name of the logdog stream.
24 data: String with data you want to upload.
25
26 Returns:
27 Link to view uploaded text in logdog viewer.
28 """
29 with get_logdog_client().text(name) as stream:
30 stream.write(data)
31 return stream.get_viewer_url()
32
33
34 @decorators.NoRaiseException(default_return_value=None)
35 def open_text(name):
36 """Returns a file like object which you can write to.
37
38 Args:
39 name: Name of the logdog stream.
40
41 Returns:
42 A file like object. close() file when done.
43 """
44 return get_logdog_client().open_text(name)
45
46
47 @decorators.NoRaiseException(default_return_value='')
48 def binary(name, binary_path):
49 """Uploads binary to logdog.
50
51 Args:
52 name: Name of the logdog stream.
53 binary_path: Path to binary you want to upload.
54
55 Returns:
56 Link to view uploaded binary in logdog viewer.
57 """
58 with get_logdog_client().binary(name) as stream:
59 with open(binary_path, 'r') as f:
60 stream.write(f.read())
61 return stream.get_viewer_url()
62
63
64 @decorators.NoRaiseException(default_return_value='')
65 def get_viewer_url(name):
66 """Get Logdog viewer URL.
67
68 Args:
69 name: Name of the logdog stream.
70
71 Returns:
72 Link to view uploaded binary in logdog viewer.
73 """
74 return get_logdog_client().get_viewer_url(name)
75
76
77 @decorators.Memoize
78 def get_logdog_client():
jbudorick 2017/02/03 01:30:30 +dnj is it ok to memoize a stream client?
dnj 2017/02/03 01:33:55 It's intended to be a singleton, so this seems fin
jbudorick 2017/02/03 01:35:42 Great. Thanks for the quick response!
79 return bootstrap.ButlerBootstrap.probe().stream_client()
80
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698