summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler/model.py
diff options
context:
space:
mode:
authorDHNishi@gmail.com <DHNishi@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-06 05:14:33 +0000
committerDHNishi@gmail.com <DHNishi@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-06 05:14:33 +0000
commit0853bcff70fc4f5991ec79be034bf7ac4883b2e0 (patch)
treedd61594aba54eed2b28ac516b7e040def8df25fb /tools/json_schema_compiler/model.py
parente06ebb979295a3f36f619f88f8d66b1bc92a5a5a (diff)
downloadchromium_src-0853bcff70fc4f5991ec79be034bf7ac4883b2e0.zip
chromium_src-0853bcff70fc4f5991ec79be034bf7ac4883b2e0.tar.gz
chromium_src-0853bcff70fc4f5991ec79be034bf7ac4883b2e0.tar.bz2
This is a preliminary patch to auto-generate the ID enum in APIPermission.
_permission_features.h: https://gist.github.com/DHNishi/2014be18e7912916ea25 _permission_features.cc: https://gist.github.com/DHNishi/b78bc9588b2d7a46331d BUG=280286 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=226826 Review URL: https://codereview.chromium.org/23594008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233214 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler/model.py')
-rw-r--r--tools/json_schema_compiler/model.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/json_schema_compiler/model.py b/tools/json_schema_compiler/model.py
index 3de975c..741a1b5 100644
--- a/tools/json_schema_compiler/model.py
+++ b/tools/json_schema_compiler/model.py
@@ -7,6 +7,7 @@ import os.path
from json_parse import OrderedDict
from memoize import memoize
+
class ParseException(Exception):
"""Thrown when data in the model is invalid.
"""
@@ -16,6 +17,7 @@ class ParseException(Exception):
Exception.__init__(
self, 'Model parse exception at:\n' + '\n'.join(hierarchy))
+
class Model(object):
"""Model of all namespaces that comprise an API.
@@ -34,6 +36,45 @@ class Model(object):
self.namespaces[namespace.name] = namespace
return namespace
+
+def CreateFeature(name, model):
+ if isinstance(model, dict):
+ return SimpleFeature(name, model)
+ return ComplexFeature(name, [SimpleFeature(name, child) for child in model])
+
+
+class ComplexFeature(object):
+ """A complex feature which may be made of several simple features.
+
+ Properties:
+ - |name| the name of the feature
+ - |unix_name| the unix_name of the feature
+ - |feature_list| a list of simple features which make up the feature
+ """
+ def __init__(self, feature_name, features):
+ self.name = feature_name
+ self.unix_name = UnixName(self.name)
+ self.feature_list = features
+
+class SimpleFeature(object):
+ """A simple feature, which can make up a complex feature, as specified in
+ files such as chrome/common/extensions/api/_permission_features.json.
+
+ Properties:
+ - |name| the name of the feature
+ - |unix_name| the unix_name of the feature
+ - |channel| the channel where the feature is released
+ - |extension_types| the types which can use the feature
+ - |whitelist| a list of extensions allowed to use the feature
+ """
+ def __init__(self, feature_name, feature_def):
+ self.name = feature_name
+ self.unix_name = UnixName(self.name)
+ self.channel = feature_def['channel']
+ self.extension_types = feature_def['extension_types']
+ self.whitelist = feature_def.get('whitelist')
+
+
class Namespace(object):
"""An API namespace.
@@ -75,6 +116,7 @@ class Namespace(object):
if include_compiler_options else {})
self.documentation_options = json.get('documentation_options', {})
+
class Origin(object):
"""Stores the possible origin of model object as a pair of bools. These are:
@@ -93,6 +135,7 @@ class Origin(object):
self.from_client = from_client
self.from_json = from_json
+
class Type(object):
"""A Type defined in the json.
@@ -199,6 +242,7 @@ class Type(object):
else:
raise ParseException(self, 'Unsupported JSON type %s' % json_type)
+
class Function(object):
"""A Function defined in the API.
@@ -272,6 +316,7 @@ class Function(object):
namespace,
origin)
+
class Property(object):
"""A property of a type OR a parameter to a function.
Properties:
@@ -384,11 +429,13 @@ class _Enum(object):
def __str__(self):
return repr(self)
+
class _PropertyTypeInfo(_Enum):
def __init__(self, is_fundamental, name):
_Enum.__init__(self, name)
self.is_fundamental = is_fundamental
+
class PropertyType(object):
"""Enum of different types of properties/parameters.
"""
@@ -406,6 +453,7 @@ class PropertyType(object):
REF = _PropertyTypeInfo(False, "ref")
STRING = _PropertyTypeInfo(True, "string")
+
@memoize
def UnixName(name):
'''Returns the unix_style name for a given lowerCamelCase string.
@@ -427,11 +475,13 @@ def UnixName(name):
unix_name.append(c.lower())
return ''.join(unix_name)
+
def _StripNamespace(name, namespace):
if name.startswith(namespace.name + '.'):
return name[len(namespace.name + '.'):]
return name
+
def _GetModelHierarchy(entity):
"""Returns the hierarchy of the given model entity."""
hierarchy = []
@@ -443,6 +493,7 @@ def _GetModelHierarchy(entity):
hierarchy.reverse()
return hierarchy
+
def _GetTypes(parent, json, namespace, origin):
"""Creates Type objects extracted from |json|.
"""
@@ -452,6 +503,7 @@ def _GetTypes(parent, json, namespace, origin):
types[type_.name] = type_
return types
+
def _GetFunctions(parent, json, namespace):
"""Creates Function objects extracted from |json|.
"""
@@ -465,6 +517,7 @@ def _GetFunctions(parent, json, namespace):
functions[function.name] = function
return functions
+
def _GetEvents(parent, json, namespace):
"""Creates Function objects generated from the events in |json|.
"""
@@ -478,6 +531,7 @@ def _GetEvents(parent, json, namespace):
events[event.name] = event
return events
+
def _GetProperties(parent, json, namespace, origin):
"""Generates Property objects extracted from |json|.
"""
@@ -486,10 +540,12 @@ def _GetProperties(parent, json, namespace, origin):
properties[name] = Property(parent, name, property_json, namespace, origin)
return properties
+
class _PlatformInfo(_Enum):
def __init__(self, name):
_Enum.__init__(self, name)
+
class Platforms(object):
"""Enum of the possible platforms.
"""
@@ -499,6 +555,7 @@ class Platforms(object):
MAC = _PlatformInfo("mac")
WIN = _PlatformInfo("win")
+
def _GetPlatforms(json):
if 'platforms' not in json or json['platforms'] == None:
return None