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

Side by Side Diff: tools/json_schema_compiler/model.py

Issue 22228002: Add optional schema compiler error messages (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Templates. Created 7 years, 4 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
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 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 class ParseException(Exception): 10 class ParseException(Exception):
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 - |unix_name| the unix_name of the namespace 43 - |unix_name| the unix_name of the namespace
44 - |source_file| the file that contained the namespace definition 44 - |source_file| the file that contained the namespace definition
45 - |source_file_dir| the directory component of |source_file| 45 - |source_file_dir| the directory component of |source_file|
46 - |source_file_filename| the filename component of |source_file| 46 - |source_file_filename| the filename component of |source_file|
47 - |platforms| if not None, the list of platforms that the namespace is 47 - |platforms| if not None, the list of platforms that the namespace is
48 available to 48 available to
49 - |types| a map of type names to their model.Type 49 - |types| a map of type names to their model.Type
50 - |functions| a map of function names to their model.Function 50 - |functions| a map of function names to their model.Function
51 - |events| a map of event names to their model.Function 51 - |events| a map of event names to their model.Function
52 - |properties| a map of property names to their model.Property 52 - |properties| a map of property names to their model.Property
53 - |compiler_options| the compiler_options dict, only present if 53 - |compiler_options| the compiler_options dict, only not empty if
54 |include_compiler_options| is True 54 |include_compiler_options| is True
55 """ 55 """
56 def __init__(self, json, source_file, include_compiler_options=False): 56 def __init__(self, json, source_file, include_compiler_options=False):
57 self.name = json['namespace'] 57 self.name = json['namespace']
58 if 'description' not in json: 58 if 'description' not in json:
59 # TODO(kalman): Go back to throwing an error here. 59 # TODO(kalman): Go back to throwing an error here.
60 print('%s must have a "description" field. This will appear ' 60 print('%s must have a "description" field. This will appear '
61 'on the API summary page.' % self.name) 61 'on the API summary page.' % self.name)
62 json['description'] = '' 62 json['description'] = ''
63 self.description = json['description'] 63 self.description = json['description']
64 self.unix_name = UnixName(self.name) 64 self.unix_name = UnixName(self.name)
65 self.source_file = source_file 65 self.source_file = source_file
66 self.source_file_dir, self.source_file_filename = os.path.split(source_file) 66 self.source_file_dir, self.source_file_filename = os.path.split(source_file)
67 self.parent = None 67 self.parent = None
68 self.platforms = _GetPlatforms(json) 68 self.platforms = _GetPlatforms(json)
69 toplevel_origin = Origin(from_client=True, from_json=True) 69 toplevel_origin = Origin(from_client=True, from_json=True)
70 self.types = _GetTypes(self, json, self, toplevel_origin) 70 self.types = _GetTypes(self, json, self, toplevel_origin)
71 self.functions = _GetFunctions(self, json, self) 71 self.functions = _GetFunctions(self, json, self)
72 self.events = _GetEvents(self, json, self) 72 self.events = _GetEvents(self, json, self)
73 self.properties = _GetProperties(self, json, self, toplevel_origin) 73 self.properties = _GetProperties(self, json, self, toplevel_origin)
74 if include_compiler_options: 74 self.compiler_options = (json.get('compiler_options', {})
75 self.compiler_options = json.get('compiler_options', {}) 75 if include_compiler_options else {})
76 76
77 class Origin(object): 77 class Origin(object):
78 """Stores the possible origin of model object as a pair of bools. These are: 78 """Stores the possible origin of model object as a pair of bools. These are:
79 79
80 |from_client| indicating that instances can originate from users of 80 |from_client| indicating that instances can originate from users of
81 generated code (for example, function results), or 81 generated code (for example, function results), or
82 |from_json| indicating that instances can originate from the JSON (for 82 |from_json| indicating that instances can originate from the JSON (for
83 example, function parameters) 83 example, function parameters)
84 84
85 It is possible for model objects to originate from both the client and json, 85 It is possible for model objects to originate from both the client and json,
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 def _GetPlatforms(json): 483 def _GetPlatforms(json):
484 if 'platforms' not in json: 484 if 'platforms' not in json:
485 return None 485 return None
486 platforms = [] 486 platforms = []
487 for platform_name in json['platforms']: 487 for platform_name in json['platforms']:
488 for platform_enum in _Enum.GetAll(Platforms): 488 for platform_enum in _Enum.GetAll(Platforms):
489 if platform_name == platform_enum.name: 489 if platform_name == platform_enum.name:
490 platforms.append(platform_enum) 490 platforms.append(platform_enum)
491 break 491 break
492 return platforms 492 return platforms
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698