| """Collection of utility functions for uploading CIPD packages. |
| |
| Note: cipd is included in depot_tools. These utils assume depot_tools has been |
| included in $PATH. |
| """ |
| |
| from __future__ import absolute_import |
| import logging |
| |
| |
| def UploadCIPDPackage(executor, |
| pkg_def, |
| pkg_vars=None, |
| refs=None, |
| tags=None, |
| verification_timeout=None, |
| service_account_json=None, |
| dry_run=False): |
| """Uploads a new CIPD package, defined by pkg-def. |
| |
| Args: |
| executor: Executes the subprocess. |
| pkg_def: Path to cipd pkg-def .yaml file. |
| pkg_vars: A dict of variables to pass to cipd with -pkg-var. |
| refs: A list of refs to be assigned to the uploaded cipd package. |
| tags: A dict of tags to be assigned to the uploaded cipd package. |
| verification_timeout: Time allotted for cipd verification step ('XXmXXs'). |
| service_account_json: Path to service account JSON auth token. |
| dry_run: Boolean, if True skip actual upload. |
| |
| Returns: |
| Tuple of (return code, full stdout output, full stderr output). |
| """ |
| pkg_vars = pkg_vars or {} |
| refs = refs or [] |
| tags = tags or {} |
| cmd = [ |
| 'cipd', 'create', |
| '-pkg-def', pkg_def] |
| for key in pkg_vars.keys(): |
| value = pkg_vars[key] |
| var = ':'.join([str(key), str(value)]) |
| cmd += ['-pkg-var', var] |
| for ref in refs: |
| cmd += ['-ref', ref] |
| for key in tags.keys(): |
| value = tags[key] |
| tag = ':'.join([str(key), str(value)]) |
| cmd += ['-tag', tag] |
| |
| if verification_timeout: |
| cmd += ['-verification-timeout', verification_timeout] |
| |
| if service_account_json: |
| cmd += ['-service-account-json', service_account_json] |
| |
| if dry_run: |
| logging.info('CIPD upload command: %s', cmd) |
| cmd = ['echo'] + cmd |
| return executor.exec_subprocess(cmd) |