OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Wrapper for adding logdog streaming support to swarming tasks.""" | 6 """Wrapper for adding logdog streaming support to swarming tasks.""" |
7 | 7 |
8 import argparse | 8 import argparse |
9 import logging | 9 import logging |
10 import os | 10 import os |
(...skipping 28 matching lines...) Expand all Loading... |
39 return 'https://%s/v/?s=%s' % (server, urllib.quote_plus(stream_name)) | 39 return 'https://%s/v/?s=%s' % (server, urllib.quote_plus(stream_name)) |
40 | 40 |
41 | 41 |
42 def main(): | 42 def main(): |
43 parser = CommandParser() | 43 parser = CommandParser() |
44 args, test_cmd = parser.parse_known_args(sys.argv[1:]) | 44 args, test_cmd = parser.parse_known_args(sys.argv[1:]) |
45 logging.basicConfig(level=logging.INFO) | 45 logging.basicConfig(level=logging.INFO) |
46 if not test_cmd: | 46 if not test_cmd: |
47 parser.error('Must specify command to run after the logdog flags') | 47 parser.error('Must specify command to run after the logdog flags') |
48 result = subprocess.call(test_cmd) | 48 result = subprocess.call(test_cmd) |
49 if '${SWARMING_TASK_ID}' in args.prefix: | 49 # Only excute logdog tasks if binary is downloaded |
50 args.prefix = args.prefix.replace('${SWARMING_TASK_ID}', | |
51 os.environ.get('SWARMING_TASK_ID')) | |
52 url = CreateUrl('luci-logdog.appspot.com', args.project, args.prefix, | |
53 args.name) | |
54 logdog_cmd = [args.logdog_bin_cmd, '-project', args.project, | |
55 '-output', 'logdog,host=%s' % args.logdog_server, | |
56 '-prefix', args.prefix, | |
57 '-service-account-json', args.service_account_json, | |
58 'stream', '-source', args.source, | |
59 '-stream', '-name=%s' % args.name] | |
60 if os.path.exists(args.logdog_bin_cmd): | 50 if os.path.exists(args.logdog_bin_cmd): |
| 51 if '${SWARMING_TASK_ID}' in args.prefix: |
| 52 swarming_id = os.environ.get('SWARMING_TASK_ID') |
| 53 print type(swarming_id) |
| 54 print sys.getsizeof(swarming_id) |
| 55 print swarming_id |
| 56 # Subtract swarming_id by 1 to match display in recipes |
| 57 swarmingId = format(int(swarming_id, 16) - 1, 'x') |
| 58 print swarming_id |
| 59 args.prefix = args.prefix.replace('${SWARMING_TASK_ID}', swarmingId) |
| 60 url = CreateUrl('luci-logdog.appspot.com', args.project, args.prefix, |
| 61 args.name) |
| 62 logdog_cmd = [args.logdog_bin_cmd, '-project', args.project, |
| 63 '-output', 'logdog,host=%s' % args.logdog_server, |
| 64 '-prefix', args.prefix, |
| 65 '-service-account-json', args.service_account_json, |
| 66 'stream', '-source', args.source, |
| 67 '-stream', '-name=%s' % args.name] |
61 subprocess.call(logdog_cmd) | 68 subprocess.call(logdog_cmd) |
62 logging.info('Logcats are located at: %s', url) | 69 logging.info('Logcats are located at: %s', url) |
63 return result | 70 return result |
64 | 71 |
65 | 72 |
66 if __name__ == '__main__': | 73 if __name__ == '__main__': |
67 sys.exit(main()) | 74 sys.exit(main()) |
OLD | NEW |