OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """Wrapper for adding logdog streaming support to swarming tasks.""" | |
7 | |
8 import argparse | |
9 import sys | |
10 import os | |
11 import subprocess | |
12 import logging | |
13 import urllib | |
14 | |
15 | |
16 def CommandParser(): | |
17 # Parses the command line arguments being passed in | |
18 parser = argparse.ArgumentParser() | |
19 parser.add_argument('--logdog-bin-cmd', required=True, | |
20 help='Command for running logdog butler binary') | |
21 parser.add_argument('--project', required=True, | |
22 help='Name of logdog project') | |
23 parser.add_argument('--logdog-server', | |
24 default='services-dot-luci-logdog.appspot.com', | |
25 help='URL of logdog server, https:// is assumed.') | |
26 parser.add_argument('--service-account-json', required=True, | |
27 help='Location of authentication json') | |
28 parser.add_argument('--prefix', required=True, | |
29 help='Prefix to be used for logdog stream') | |
30 parser.add_argument('--source', required=True, | |
31 help='Location of file for logdog to stream') | |
32 parser.add_argument('--name', required=True, | |
33 help='Name to be used for logdog stream') | |
34 return parser | |
35 | |
36 | |
37 def CreateUrl(server, project, prefix, name): | |
38 stream_name = '%s/%s/+/%s' % (project, prefix, name) | |
39 return 'https://%s/v/?s=%s' % (server, urllib.quote_plus(stream_name)) | |
40 | |
41 | |
42 def main(): | |
43 parser = CommandParser() | |
44 args, test_cmd = parser.parse_known_args(sys.argv[1:]) | |
45 if not test_cmd: | |
46 parser.error('Must specify command to run after the logdog flags') | |
47 result = subprocess.call(test_cmd) | |
48 if '${SWARMING_TASK_ID}' in args.prefix: | |
49 args.prefix = args.prefix.replace('${SWARMING_TASK_ID}', | |
50 os.environ.get('SWARMING_TASK_ID')) | |
51 url = CreateUrl('luci-logdog.appspot.com', args.project, args.prefix, | |
ghost stip (do not use)
2016/08/04 23:46:48
nit: would be nice to link this to --logdog-server
nicholaslin
2016/08/09 17:32:19
My guess is once Dan puts together the logdog CL -
| |
52 args.name) | |
53 logging.basicConfig(level=logging.INFO) | |
54 logging.info('Logcats are located at: %s', url) | |
55 logdog_cmd = [args.logdog_bin_cmd, '-project', args.project, | |
56 '-output', 'logdog,host=%s' % args.logdog_server, | |
57 '-prefix', args.prefix, | |
58 '-service-account-json', args.service_account_json, | |
59 'stream', '-source', args.source, | |
60 '-stream', '-name=%s' % args.name] | |
61 subprocess.call(logdog_cmd) | |
62 return result | |
63 | |
64 | |
65 if __name__ == '__main__': | |
66 sys.exit(main()) | |
OLD | NEW |