| OLD | NEW |
| 1 # Copyright 2016 The LUCI Authors. All rights reserved. | 1 # Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 # Use of this source code is governed under the Apache License, Version 2.0 | 2 # Use of this source code is governed under the Apache License, Version 2.0 |
| 3 # that can be found in the LICENSE file. | 3 # that can be found in the LICENSE file. |
| 4 | 4 |
| 5 """Fetches CIPD client and installs packages.""" | 5 """Fetches CIPD client and installs packages.""" |
| 6 | 6 |
| 7 import contextlib | 7 import contextlib |
| 8 import hashlib | 8 import hashlib |
| 9 import json | 9 import json |
| 10 import logging | 10 import logging |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 else: | 195 else: |
| 196 logging.info('cipd client: %s', line) | 196 logging.info('cipd client: %s', line) |
| 197 | 197 |
| 198 exit_code = process.wait(timeout=timeoutfn()) | 198 exit_code = process.wait(timeout=timeoutfn()) |
| 199 if exit_code != 0: | 199 if exit_code != 0: |
| 200 raise Error( | 200 raise Error( |
| 201 'Could not install packages; exit code %d\noutput:%s' % ( | 201 'Could not install packages; exit code %d\noutput:%s' % ( |
| 202 exit_code, '\n'.join(output))) | 202 exit_code, '\n'.join(output))) |
| 203 with open(json_file_path) as jfile: | 203 with open(json_file_path) as jfile: |
| 204 result_json = json.load(jfile) | 204 result_json = json.load(jfile) |
| 205 return [(x['package'], x['instance_id']) for x in result_json['result']] | 205 # TEMPORARY(iannucci): this code handles cipd <1.4 and cipd >=1.5 |
| 206 # formatted ensure result formats. Cipd 1.5 added support for subdirs, and |
| 207 # as part of the transition, the result of the ensure command needed to |
| 208 # change. To ease the transition, we always return data as-if we're using |
| 209 # the new format. Once cipd 1.5+ is deployed everywhere, this type switch |
| 210 # can be removed. |
| 211 if isinstance(result_json['result'], dict): |
| 212 # cipd 1.5 |
| 213 return { |
| 214 subdir: [(x['package'], x['instance_id']) for x in pins] |
| 215 for subdir, pins in result_json['result'].iteritems() |
| 216 } |
| 217 else: |
| 218 # cipd 1.4 |
| 219 return { |
| 220 "": [(x['package'], x['instance_id']) for x in result_json['result']], |
| 221 } |
| 206 finally: | 222 finally: |
| 207 fs.remove(list_file_path) | 223 fs.remove(list_file_path) |
| 208 fs.remove(json_file_path) | 224 fs.remove(json_file_path) |
| 209 | 225 |
| 210 | 226 |
| 211 def get_platform(): | 227 def get_platform(): |
| 212 """Returns ${platform} parameter value. | 228 """Returns ${platform} parameter value. |
| 213 | 229 |
| 214 Borrowed from | 230 Borrowed from |
| 215 https://chromium.googlesource.com/infra/infra/+/aaf9586/build/build.py#204 | 231 https://chromium.googlesource.com/infra/infra/+/aaf9586/build/build.py#204 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 """ | 464 """ |
| 449 result = [] | 465 result = [] |
| 450 for pkg in packages: | 466 for pkg in packages: |
| 451 path, name, version = pkg.split(':', 2) | 467 path, name, version = pkg.split(':', 2) |
| 452 if not name: | 468 if not name: |
| 453 raise Error('Invalid package "%s": package name is not specified' % pkg) | 469 raise Error('Invalid package "%s": package name is not specified' % pkg) |
| 454 if not version: | 470 if not version: |
| 455 raise Error('Invalid package "%s": version is not specified' % pkg) | 471 raise Error('Invalid package "%s": version is not specified' % pkg) |
| 456 result.append((path, name, version)) | 472 result.append((path, name, version)) |
| 457 return result | 473 return result |
| OLD | NEW |