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

Side by Side Diff: appengine/swarming/message_conversion.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: Rename to cipd_pins Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 # Copyright 2015 The LUCI Authors. All rights reserved. 1 # Copyright 2015 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 """This module facilitates conversion from dictionaries to ProtoRPC messages. 5 """This module facilitates conversion from dictionaries to ProtoRPC messages.
6 6
7 Given a dictionary whose keys' names and values' types comport with the 7 Given a dictionary whose keys' names and values' types comport with the
8 fields defined for a protorpc.messages.Message subclass, this module tries to 8 fields defined for a protorpc.messages.Message subclass, this module tries to
9 generate a Message instance that corresponds to the provided dictionary. The 9 generate a Message instance that corresponds to the provided dictionary. The
10 "normal" use case is for ndb.Models which need to be represented as a 10 "normal" use case is for ndb.Models which need to be represented as a
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 properties=properties) 193 properties=properties)
194 194
195 195
196 def task_result_to_rpc(entity, send_stats): 196 def task_result_to_rpc(entity, send_stats):
197 """"Returns a swarming_rpcs.TaskResult from a task_result.TaskResultSummary or 197 """"Returns a swarming_rpcs.TaskResult from a task_result.TaskResultSummary or
198 task_result.TaskRunResult. 198 task_result.TaskRunResult.
199 """ 199 """
200 outputs_ref = ( 200 outputs_ref = (
201 _ndb_to_rpc(swarming_rpcs.FilesRef, entity.outputs_ref) 201 _ndb_to_rpc(swarming_rpcs.FilesRef, entity.outputs_ref)
202 if entity.outputs_ref else None) 202 if entity.outputs_ref else None)
203 cipd_pins = None
204 if entity.cipd_pins:
205 cipd_pins = swarming_rpcs.CipdPins(
206 client_package=(
207 _ndb_to_rpc(swarming_rpcs.CipdPackage,
208 entity.cipd_pins.client_package)
209 if entity.cipd_pins.client_package else None
210 ),
211 packages=[
212 _ndb_to_rpc(swarming_rpcs.CipdPackage, pkg)
213 for pkg in entity.cipd_pins.packages
M-A Ruel 2016/08/26 23:19:51 for pkg in entity.cipd_pins.packages or () would
214 ] if entity.cipd_pins.packages else None
215 )
203 performance_stats = None 216 performance_stats = None
204 if send_stats and entity.performance_stats.is_valid: 217 if send_stats and entity.performance_stats.is_valid:
205 def op(entity): 218 def op(entity):
206 if entity: 219 if entity:
207 return _ndb_to_rpc(swarming_rpcs.OperationStats, entity) 220 return _ndb_to_rpc(swarming_rpcs.OperationStats, entity)
208 221
209 performance_stats = _ndb_to_rpc( 222 performance_stats = _ndb_to_rpc(
210 swarming_rpcs.PerformanceStats, 223 swarming_rpcs.PerformanceStats,
211 entity.performance_stats, 224 entity.performance_stats,
212 isolated_download=op(entity.performance_stats.isolated_download), 225 isolated_download=op(entity.performance_stats.isolated_download),
213 isolated_upload=op(entity.performance_stats.isolated_upload)) 226 isolated_upload=op(entity.performance_stats.isolated_upload))
214 kwargs = { 227 kwargs = {
215 'bot_dimensions': _string_list_pairs_from_dict(entity.bot_dimensions or {}), 228 'bot_dimensions': _string_list_pairs_from_dict(entity.bot_dimensions or {}),
229 'cipd_pins': cipd_pins,
230 'outputs_ref': outputs_ref,
216 'performance_stats': performance_stats, 231 'performance_stats': performance_stats,
217 'outputs_ref': outputs_ref,
218 'state': swarming_rpcs.StateField(entity.state), 232 'state': swarming_rpcs.StateField(entity.state),
219 } 233 }
220 if entity.__class__ is task_result.TaskRunResult: 234 if entity.__class__ is task_result.TaskRunResult:
221 kwargs['costs_usd'] = [] 235 kwargs['costs_usd'] = []
222 if entity.cost_usd is not None: 236 if entity.cost_usd is not None:
223 kwargs['costs_usd'].append(entity.cost_usd) 237 kwargs['costs_usd'].append(entity.cost_usd)
224 kwargs['properties_hash'] = None 238 kwargs['properties_hash'] = None
225 kwargs['tags'] = [] 239 kwargs['tags'] = []
226 kwargs['user'] = None 240 kwargs['user'] = None
227 else: 241 else:
228 assert entity.__class__ is task_result.TaskResultSummary, entity 242 assert entity.__class__ is task_result.TaskResultSummary, entity
229 kwargs['properties_hash'] = ( 243 kwargs['properties_hash'] = (
230 entity.properties_hash.encode('hex') 244 entity.properties_hash.encode('hex')
231 if entity.properties_hash else None) 245 if entity.properties_hash else None)
232 return _ndb_to_rpc(swarming_rpcs.TaskResult, entity, **kwargs) 246 return _ndb_to_rpc(swarming_rpcs.TaskResult, entity, **kwargs)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698