| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 '''Utilities used by GRIT. | 6 '''Utilities used by GRIT. |
| 7 ''' | 7 ''' |
| 8 | 8 |
| 9 import codecs | 9 import codecs |
| 10 import htmlentitydefs | 10 import htmlentitydefs |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 def IsVerbose(): | 476 def IsVerbose(): |
| 477 return verbose | 477 return verbose |
| 478 | 478 |
| 479 def IsExtraVerbose(): | 479 def IsExtraVerbose(): |
| 480 return extra_verbose | 480 return extra_verbose |
| 481 | 481 |
| 482 def ParseDefine(define): | 482 def ParseDefine(define): |
| 483 '''Parses a define argument and returns the name and value. | 483 '''Parses a define argument and returns the name and value. |
| 484 | 484 |
| 485 The format is either "NAME=VAL" or "NAME", using True as the default value. | 485 The format is either "NAME=VAL" or "NAME", using True as the default value. |
| 486 Values of "1"/"true" and "0"/"false" are transformed to True and False | 486 Values of "1" and "0" are transformed to True and False respectively. |
| 487 respectively. | |
| 488 | 487 |
| 489 Args: | 488 Args: |
| 490 define: a string of the form "NAME=VAL" or "NAME". | 489 define: a string of the form "NAME=VAL" or "NAME". |
| 491 | 490 |
| 492 Returns: | 491 Returns: |
| 493 A (name, value) pair. name is a string, value a string or boolean. | 492 A (name, value) pair. name is a string, value a string or boolean. |
| 494 ''' | 493 ''' |
| 495 parts = [part.strip() for part in define.split('=', 1)] | 494 parts = [part.strip() for part in define.split('=', 1)] |
| 496 assert len(parts) >= 1 | 495 assert len(parts) >= 1 |
| 497 name = parts[0] | 496 name = parts[0] |
| 498 val = True | 497 val = True |
| 499 if len(parts) > 1: | 498 if len(parts) > 1: |
| 500 val = parts[1] | 499 val = parts[1] |
| 501 if val == "1" or val == "true": val = True | 500 if val == "1": val = True |
| 502 elif val == "0" or val == "false": val = False | 501 elif val == "0": val = False |
| 503 return (name, val) | 502 return (name, val) |
| 504 | 503 |
| 505 | 504 |
| 506 class Substituter(object): | 505 class Substituter(object): |
| 507 '''Finds and substitutes variable names in text strings. | 506 '''Finds and substitutes variable names in text strings. |
| 508 | 507 |
| 509 Given a dictionary of variable names and values, prepares to | 508 Given a dictionary of variable names and values, prepares to |
| 510 search for patterns of the form [VAR_NAME] in a text. | 509 search for patterns of the form [VAR_NAME] in a text. |
| 511 The value will be substituted back efficiently. | 510 The value will be substituted back efficiently. |
| 512 Also applies to tclib.Message objects. | 511 Also applies to tclib.Message objects. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 return self._AsCurrentDirClass(self.GetPath()) | 652 return self._AsCurrentDirClass(self.GetPath()) |
| 654 | 653 |
| 655 class _AsCurrentDirClass(object): | 654 class _AsCurrentDirClass(object): |
| 656 def __init__(self, path): | 655 def __init__(self, path): |
| 657 self.path = path | 656 self.path = path |
| 658 def __enter__(self): | 657 def __enter__(self): |
| 659 self.oldpath = os.getcwd() | 658 self.oldpath = os.getcwd() |
| 660 os.chdir(self.path) | 659 os.chdir(self.path) |
| 661 def __exit__(self, *exc_info): | 660 def __exit__(self, *exc_info): |
| 662 os.chdir(self.oldpath) | 661 os.chdir(self.oldpath) |
| OLD | NEW |