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

Unified Diff: client/cipd.py

Issue 2267363004: Add CIPD pin reporting to swarming. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-py@master
Patch Set: comments and some tests Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: client/cipd.py
diff --git a/client/cipd.py b/client/cipd.py
index 8881ef2ecad75d22fd150ea8733fd230e25d6854..cbee59d1df2db4c6c7f139a401f2501479efe5d6 100644
--- a/client/cipd.py
+++ b/client/cipd.py
@@ -4,11 +4,12 @@
"""Fetches CIPD client and installs packages."""
-__version__ = '0.2'
+__version__ = '0.3'
import collections
import contextlib
import hashlib
+import json
import logging
import optparse
import os
@@ -129,6 +130,10 @@ class CipdClient(object):
tmp_dir (str): if not None, dir for temp files.
timeout (int): if not None, timeout in seconds for this function to run.
+ Returns:
+ Pinned packages in the form of [(package_name, package_id)], which
+ correspond 1:1 with the input packages argument.
+
Raises:
Error if could not install packages or timed out.
"""
@@ -137,6 +142,10 @@ class CipdClient(object):
list_file_handle, list_file_path = tempfile.mkstemp(
dir=tmp_dir, prefix=u'cipd-ensure-list-', suffix='.txt')
+ json_out_file_handle, json_file_path = tempfile.mkstemp(
+ dir=tmp_dir, prefix=u'cipd-ensure-result-', suffix='.json')
+ os.close(json_out_file_handle)
+
try:
try:
for pkg, version in packages:
@@ -150,6 +159,7 @@ class CipdClient(object):
'-root', site_root,
'-list', list_file_path,
'-verbose', # this is safe because cipd-ensure does not print a lot
+ '-json-output', json_file_path,
]
if cache_dir:
cmd += ['-cache-dir', cache_dir]
@@ -180,8 +190,12 @@ class CipdClient(object):
raise Error(
'Could not install packages; exit code %d\noutput:%s' % (
exit_code, '\n'.join(output)))
+ with open(json_file_path) as jfile:
+ result_json = json.load(jfile)
+ return [(x['package'], x['instance_id']) for x in result_json['result']]
finally:
fs.remove(list_file_path)
+ fs.remove(json_file_path)
def get_platform():
@@ -402,21 +416,26 @@ def get_client(
yield CipdClient(binary_path)
-def parse_package_args(packages):
+def parse_package_args(packages, with_index=False):
"""Parses --cipd-package arguments.
Assumes |packages| were validated by validate_cipd_options.
Returns:
- A map {path: [(package, version)]}.
+ A map {path: [(package, version)]}. If with_index is True, the tuples in the
+ map have a third parameter which is the original command line index of that
+ pin.
"""
result = collections.defaultdict(list)
- for pkg in packages:
+ for i, pkg in enumerate(packages):
path, name, version = pkg.split(':', 2)
path = path.replace('/', os.path.sep)
if not name:
raise Error('Invalid package "%s": package name is not specified' % pkg)
if not version:
raise Error('Invalid package "%s": version is not specified' % pkg)
- result[path].append((name, version))
+ if with_index:
+ result[path].append((name, version, i))
+ else:
+ result[path].append((name, version))
return result

Powered by Google App Engine
This is Rietveld 408576698