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

Side by Side Diff: model.py

Issue 25536018: Support revisions with str type for try jobs. Base URL: https://src.chromium.org/chrome/trunk/tools/commit-queue/
Patch Set: Created 7 years, 2 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
« no previous file with comments | « no previous file | pending_manager.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Defines the PersistentMixIn utility class to easily convert classes to and 5 """Defines the PersistentMixIn utility class to easily convert classes to and
6 from dict for serialization. 6 from dict for serialization.
7 7
8 This class is aimed at json-compatible serialization, so it supports the limited 8 This class is aimed at json-compatible serialization, so it supports the limited
9 set of structures supported by json; strings, numbers as int or float, list and 9 set of structures supported by json; strings, numbers as int or float, list and
10 dictionaries. 10 dictionaries.
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 for item in dir(cls): 233 for item in dir(cls):
234 if item.startswith('_'): 234 if item.startswith('_'):
235 continue 235 continue
236 item_value = getattr(cls, item) 236 item_value = getattr(cls, item)
237 if isinstance(item_value, type): 237 if isinstance(item_value, type):
238 item_value = (item_value,) 238 item_value = (item_value,)
239 if not isinstance(item_value, tuple): 239 if not isinstance(item_value, tuple):
240 continue 240 continue
241 if not all(i is None or i.__class__ == type for i in item_value): 241 if not all(i is None or i.__class__ == type for i in item_value):
242 continue 242 continue
243 if any(i is str for i in item_value):
244 raise TypeError(
245 '%s is type \'str\' which is currently not supported' % item)
246 item_value = tuple( 243 item_value = tuple(
247 f if f is not None else None.__class__ for f in item_value) 244 f if f is not None else None.__class__ for f in item_value)
248 persistent_members_cache[item] = item_value 245 persistent_members_cache[item] = item_value
249 return persistent_members_cache 246 return persistent_members_cache
250 247
251 @staticmethod 248 @staticmethod
252 def _get_subclass(typename): 249 def _get_subclass(typename):
253 """Returns the PersistentMixIn subclass with the name |typename|.""" 250 """Returns the PersistentMixIn subclass with the name |typename|."""
254 subclass = None 251 subclass = None
255 if PersistentMixIn.__persistent_classes_cache is not None: 252 if PersistentMixIn.__persistent_classes_cache is not None:
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 def save_to_json_file(filename, obj): 394 def save_to_json_file(filename, obj):
398 """Save one object in a JSON file.""" 395 """Save one object in a JSON file."""
399 try: 396 try:
400 old = filename + '.old' 397 old = filename + '.old'
401 if os.path.exists(filename): 398 if os.path.exists(filename):
402 os.rename(filename, old) 399 os.rename(filename, old)
403 finally: 400 finally:
404 with open(filename, 'wb') as f: 401 with open(filename, 'wb') as f:
405 json.dump(obj.as_dict(), f, sort_keys=True, indent=2) 402 json.dump(obj.as_dict(), f, sort_keys=True, indent=2)
406 f.write('\n') 403 f.write('\n')
OLDNEW
« no previous file with comments | « no previous file | pending_manager.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698