Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 import os.path | 5 import os.path |
| 6 | 6 |
| 7 from json_parse import OrderedDict | 7 from json_parse import OrderedDict |
| 8 from memoize import memoize | 8 from memoize import memoize |
| 9 | 9 |
| 10 | 10 |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 - |description| a description of the property (if provided) | 403 - |description| a description of the property (if provided) |
| 404 """ | 404 """ |
| 405 def __init__(self, json): | 405 def __init__(self, json): |
| 406 if isinstance(json, dict): | 406 if isinstance(json, dict): |
| 407 self.name = json['name'] | 407 self.name = json['name'] |
| 408 self.description = json.get('description') | 408 self.description = json.get('description') |
| 409 else: | 409 else: |
| 410 self.name = json | 410 self.name = json |
| 411 self.description = None | 411 self.description = None |
| 412 | 412 |
| 413 | |
|
not at google - send to devlin
2014/05/14 16:18:14
no blank line
David Tseng
2014/05/14 18:11:31
Done.
| |
| 414 def CamelName(self): | |
| 415 return CamelName(self.name) | |
| 416 | |
| 413 class _Enum(object): | 417 class _Enum(object): |
| 414 """Superclass for enum types with a "name" field, setting up repr/eq/ne. | 418 """Superclass for enum types with a "name" field, setting up repr/eq/ne. |
| 415 Enums need to do this so that equality/non-equality work over pickling. | 419 Enums need to do this so that equality/non-equality work over pickling. |
| 416 """ | 420 """ |
| 417 @staticmethod | 421 @staticmethod |
| 418 def GetAll(cls): | 422 def GetAll(cls): |
| 419 """Yields all _Enum objects declared in |cls|. | 423 """Yields all _Enum objects declared in |cls|. |
| 420 """ | 424 """ |
| 421 for prop_key in dir(cls): | 425 for prop_key in dir(cls): |
| 422 prop_value = getattr(cls, prop_key) | 426 prop_value = getattr(cls, prop_key) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 475 # Replace ACMEWidgets with ACME_Widgets | 479 # Replace ACMEWidgets with ACME_Widgets |
| 476 elif i + 1 < len(name) and name[i + 1].islower(): | 480 elif i + 1 < len(name) and name[i + 1].islower(): |
| 477 unix_name.append('_') | 481 unix_name.append('_') |
| 478 if c == '.': | 482 if c == '.': |
| 479 # Replace hello.world with hello_world. | 483 # Replace hello.world with hello_world. |
| 480 unix_name.append('_') | 484 unix_name.append('_') |
| 481 else: | 485 else: |
| 482 # Everything is lowercase. | 486 # Everything is lowercase. |
| 483 unix_name.append(c.lower()) | 487 unix_name.append(c.lower()) |
| 484 return ''.join(unix_name) | 488 return ''.join(unix_name) |
| 485 | 489 |
|
not at google - send to devlin
2014/05/14 16:18:14
extra blank line
(the pep8 rule is 2 blank lines
David Tseng
2014/05/14 18:11:31
Done.
| |
| 490 @memoize | |
| 491 def CamelName(snake): | |
| 492 ''' Converts a snake_cased_string to a camelCasedOne. ''' | |
| 493 camel = [] | |
| 494 i = 0 | |
| 495 while i < len(snake): | |
| 496 if snake[i] == '_' and (i + 1) < len(snake): | |
| 497 camel.append(snake[i + 1].upper()) | |
| 498 i += 2 | |
| 499 else: | |
| 500 camel.append(snake[i]) | |
| 501 i += 1 | |
| 502 return ''.join(camel) | |
| 503 | |
| 486 | 504 |
| 487 def _StripNamespace(name, namespace): | 505 def _StripNamespace(name, namespace): |
| 488 if name.startswith(namespace.name + '.'): | 506 if name.startswith(namespace.name + '.'): |
| 489 return name[len(namespace.name + '.'):] | 507 return name[len(namespace.name + '.'):] |
| 490 return name | 508 return name |
| 491 | 509 |
| 492 | 510 |
| 493 def _GetModelHierarchy(entity): | 511 def _GetModelHierarchy(entity): |
| 494 """Returns the hierarchy of the given model entity.""" | 512 """Returns the hierarchy of the given model entity.""" |
| 495 hierarchy = [] | 513 hierarchy = [] |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 # Sanity check: platforms should not be an empty list. | 588 # Sanity check: platforms should not be an empty list. |
| 571 if not json['platforms']: | 589 if not json['platforms']: |
| 572 raise ValueError('"platforms" cannot be an empty list') | 590 raise ValueError('"platforms" cannot be an empty list') |
| 573 platforms = [] | 591 platforms = [] |
| 574 for platform_name in json['platforms']: | 592 for platform_name in json['platforms']: |
| 575 for platform_enum in _Enum.GetAll(Platforms): | 593 for platform_enum in _Enum.GetAll(Platforms): |
| 576 if platform_name == platform_enum.name: | 594 if platform_name == platform_enum.name: |
| 577 platforms.append(platform_enum) | 595 platforms.append(platform_enum) |
| 578 break | 596 break |
| 579 return platforms | 597 return platforms |
| OLD | NEW |