| 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 '''Miscellaneous node types. | 6 '''Miscellaneous node types. |
| 7 ''' | 7 ''' |
| 8 | 8 |
| 9 import os.path | 9 import os.path |
| 10 import re | 10 import re |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 print '-' * 78 | 426 print '-' * 78 |
| 427 raise e | 427 raise e |
| 428 | 428 |
| 429 try: | 429 try: |
| 430 node.attrs['first_id'] = str(id_list.pop(0)) | 430 node.attrs['first_id'] = str(id_list.pop(0)) |
| 431 except IndexError, e: | 431 except IndexError, e: |
| 432 raise Exception('Please update %s and add a first id for %s (%s).' | 432 raise Exception('Please update %s and add a first id for %s (%s).' |
| 433 % (first_ids_filename, filename, node.name)) | 433 % (first_ids_filename, filename, node.name)) |
| 434 | 434 |
| 435 def RunGatherers(self, recursive=0, debug=False): | 435 def RunGatherers(self, recursive=0, debug=False): |
| 436 '''Gathers information for the structure nodes, then apply substitutions. | 436 '''Gathers information for the top-level nodes, then apply substitutions, |
| 437 then gather the <translations> node (all substitutions must be done before |
| 438 it is gathered so that they can match up correctly). |
| 437 | 439 |
| 438 The substitutions step requires that the OutputContext has been set. | 440 The substitutions step requires that the OutputContext has been set. |
| 439 Locally, get the Substitution messages | 441 Locally, get the Substitution messages |
| 440 and add them to the substituter. Also add substitutions for language codes | 442 and add them to the substituter. Also add substitutions for language codes |
| 441 in the Rc. | 443 in the Rc. |
| 442 | 444 |
| 445 Gatherers for <translations> child nodes will always be run after all other |
| 446 child nodes have been gathered. |
| 447 |
| 443 Args: | 448 Args: |
| 444 recursive: will call RunGatherers() recursively on all child nodes first. | 449 recursive: will call RunGatherers() recursively on all child nodes first. |
| 445 debug: will print information while running gatherers. | 450 debug: will print information while running gatherers. |
| 446 ''' | 451 ''' |
| 447 base.Node.RunGatherers(self, recursive, False) | 452 if recursive: |
| 448 assert self.output_language | 453 process_last = [] |
| 449 self.SubstituteMessages(self.substituter) | 454 for child in self.children: |
| 455 if child.name == 'translations': |
| 456 process_last.append(child) |
| 457 else: |
| 458 child.RunGatherers(recursive=recursive, debug=debug) |
| 459 |
| 460 assert self.output_language |
| 461 self.SubstituteMessages(self.substituter) |
| 462 |
| 463 for child in process_last: |
| 464 child.RunGatherers(recursive=recursive, debug=debug) |
| 450 | 465 |
| 451 | 466 |
| 452 class IdentifierNode(base.Node): | 467 class IdentifierNode(base.Node): |
| 453 '''A node for specifying identifiers that should appear in the resource | 468 '''A node for specifying identifiers that should appear in the resource |
| 454 header file, and be unique amongst all other resource identifiers, but don't | 469 header file, and be unique amongst all other resource identifiers, but don't |
| 455 have any other attributes or reference any resources. | 470 have any other attributes or reference any resources. |
| 456 ''' | 471 ''' |
| 457 | 472 |
| 458 def MandatoryAttributes(self): | 473 def MandatoryAttributes(self): |
| 459 return ['name'] | 474 return ['name'] |
| (...skipping 24 matching lines...) Expand all Loading... |
| 484 by parameters of the same name. | 499 by parameters of the same name. |
| 485 ''' | 500 ''' |
| 486 node = IdentifierNode() | 501 node = IdentifierNode() |
| 487 node.StartParsing('identifier', parent) | 502 node.StartParsing('identifier', parent) |
| 488 node.HandleAttribute('name', name) | 503 node.HandleAttribute('name', name) |
| 489 node.HandleAttribute('id', id) | 504 node.HandleAttribute('id', id) |
| 490 node.HandleAttribute('comment', comment) | 505 node.HandleAttribute('comment', comment) |
| 491 node.HandleAttribute('systemid', systemid) | 506 node.HandleAttribute('systemid', systemid) |
| 492 node.EndParsing() | 507 node.EndParsing() |
| 493 return node | 508 return node |
| OLD | NEW |