Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """Generates Python source files from a mojom.Module.""" | 5 """Generates Python source files from a mojom.Module.""" |
| 6 | 6 |
| 7 import re | 7 import re |
| 8 from itertools import ifilter | 8 from itertools import ifilter |
| 9 | 9 |
| 10 import mojom.generate.generator as generator | 10 import mojom.generate.generator as generator |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 def GenerateFiles(self, args): | 304 def GenerateFiles(self, args): |
| 305 import_path = MojomToPythonImport(self.module.name) | 305 import_path = MojomToPythonImport(self.module.name) |
| 306 self.Write(self.GeneratePythonModule(), | 306 self.Write(self.GeneratePythonModule(), |
| 307 self.MatchMojomFilePath('%s.py' % import_path)) | 307 self.MatchMojomFilePath('%s.py' % import_path)) |
| 308 | 308 |
| 309 def GetImports(self): | 309 def GetImports(self): |
| 310 for each in self.module.imports: | 310 for each in self.module.imports: |
| 311 each['python_module'] = MojomToPythonImport(each['module_name']) | 311 each['python_module'] = MojomToPythonImport(each['module_name']) |
| 312 return self.module.imports | 312 return self.module.imports |
| 313 | 313 |
| 314 def GetGlobals(self): | |
|
qsr
2015/01/15 20:47:33
Do you need Globas? Can you put this in GeneratePy
etiennej
2015/01/15 20:48:45
I used GetGlobals to do the same as in mojom_java_
etiennej
2015/01/16 00:38:44
Done.
| |
| 315 """Returns a dictionnary of global variables.""" | |
| 316 return { | |
| 317 "namespace": self.module.namespace | |
| 318 } | |
| 319 | |
| 314 def GetQualifiedInterfaces(self): | 320 def GetQualifiedInterfaces(self): |
| 315 """ | 321 """ |
| 316 Returns the list of interfaces of the module. Each interface that has a | 322 Returns the list of interfaces of the module. Each interface that has a |
| 317 client will have a reference to the representation of the client interface | 323 client will have a reference to the representation of the client interface |
| 318 in the 'qualified_client' field. | 324 in the 'qualified_client' field. |
| 319 """ | 325 """ |
| 320 interfaces = self.module.interfaces | 326 interfaces = self.module.interfaces |
| 321 all_interfaces = [] + interfaces | 327 all_interfaces = [] + interfaces |
| 322 for each in self.GetImports(): | 328 for each in self.GetImports(): |
| 323 all_interfaces += [data.KindFromImport(x, each) for x in | 329 all_interfaces += [data.KindFromImport(x, each) for x in |
| 324 each['module'].interfaces]; | 330 each['module'].interfaces]; |
| 325 interfaces_by_name = dict((x.name, x) for x in all_interfaces) | 331 interfaces_by_name = dict((x.name, x) for x in all_interfaces) |
| 326 for interface in interfaces: | 332 for interface in interfaces: |
| 327 if interface.client: | 333 if interface.client: |
| 328 assert interface.client in interfaces_by_name, ( | 334 assert interface.client in interfaces_by_name, ( |
| 329 'Unable to find interface %s declared as client of %s.' % | 335 'Unable to find interface %s declared as client of %s.' % |
| 330 (interface.client, interface.name)) | 336 (interface.client, interface.name)) |
| 331 interface.qualified_client = interfaces_by_name[interface.client] | 337 interface.qualified_client = interfaces_by_name[interface.client] |
| 332 return sorted(interfaces, key=lambda i: (bool(i.client), i.name)) | 338 return sorted(interfaces, key=lambda i: (bool(i.client), i.name)) |
| 333 | 339 |
| 334 def GetJinjaParameters(self): | 340 def GetJinjaParameters(self): |
| 335 return { | 341 return { |
| 336 'lstrip_blocks': True, | 342 'lstrip_blocks': True, |
| 337 'trim_blocks': True, | 343 'trim_blocks': True, |
| 338 } | 344 } |
| OLD | NEW |