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

Unified Diff: tools/json_schema_compiler/idl_schema.py

Issue 9617010: Move chrome.downloads out of experimental to dev (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: tools/json_schema_compiler/idl_schema.py
diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py
index d65746a210af0d24649677719f8291107a474fa6..071011bb2b46f7493e29726db1c24d1ea4b1bbd2 100644
--- a/tools/json_schema_compiler/idl_schema.py
+++ b/tools/json_schema_compiler/idl_schema.py
@@ -37,7 +37,7 @@ def ProcessComment(comment):
}
)
'''
- # Find all the parameter comments of the form "|name|: comment".
+ # Find all the parameter comments of the form '|name|: comment'.
parameter_comments = re.findall(r'\n *\|([^|]*)\| *: *(.*)', comment)
# Get the parent comment (everything before the first parameter comment.
parent_comment = re.sub(r'\n *\|.*', '', comment)
@@ -104,19 +104,35 @@ class Enum(object):
'''
def __init__(self, enum_node):
not at google - send to devlin 2012/06/04 04:16:49 please get asargent@ to look at the contents of th
benjhayden 2012/06/04 20:33:15 Done.
self.node = enum_node
+ self.description = ''
def process(self, callbacks):
enum = []
+ enum_type = 'integer'
for node in self.node.children:
if node.cls == 'EnumItem':
- name = node.GetName()
- enum.append(name)
+ value = node.GetProperty('VALUE')
+ if value:
+ try:
+ value = int(value)
+ except ValueError:
+ try:
+ value = float(value)
+ enum_type = 'double'
+ except ValueError:
+ enum_type = 'string'
+ else:
+ value = node.GetName()
+ enum_type = 'string'
+ enum.append(value)
+ elif node.cls == 'Comment':
+ self.description = ProcessComment(node.GetName())[0]
else:
- sys.exit("Did not process %s %s" % (node.cls, node))
- return { "id" : self.node.GetName(),
- 'enum': enum,
- 'type': 'string' }
-
+ sys.exit('Did not process %s %s' % (node.cls, node))
+ return {'id' : self.node.GetName(),
+ 'description': self.description,
+ 'type': enum_type,
+ 'enum': enum}
class Member(object):
@@ -216,36 +232,44 @@ class Namespace(object):
dictionary that the JSON schema compiler expects to see.
'''
- def __init__(self, namespace_node, nodoc=False):
+ def __init__(self, namespace_node, description='', nodoc=False,
+ permissions=None):
self.namespace = namespace_node
self.nodoc = nodoc
+ self.description = description
self.events = []
self.functions = []
self.types = []
self.callbacks = {}
+ self.permissions = permissions or []
def process(self):
for node in self.namespace.children:
cls = node.cls
- if cls == "Dictionary":
+ if cls == 'Dictionary':
self.types.append(Dictionary(node).process(self.callbacks))
- elif cls == "Callback":
+ elif cls == 'Callback':
k, v = Member(node).process(self.callbacks)
self.callbacks[k] = v
- elif cls == "Interface" and node.GetName() == "Functions":
+ elif cls == 'Interface' and node.GetName() == 'Functions':
self.functions = self.process_interface(node)
- elif cls == "Interface" and node.GetName() == "Events":
+ elif cls == 'Interface' and node.GetName() == 'Events':
self.events = self.process_interface(node)
- elif cls == "Enum":
+ elif cls == 'Enum':
self.types.append(Enum(node).process(self.callbacks))
+ elif cls == 'Member':
+ name, properties = Member(node).process(self.callbacks)
+ self.functions.append(properties)
else:
- sys.exit("Did not process %s %s" % (node.cls, node))
+ sys.exit('Did not process %s %s' % (node.cls, node))
- return { 'events': self.events,
- 'functions': self.functions,
- 'types': self.types,
- 'namespace': self.namespace.GetName(),
- 'nodoc': self.nodoc }
+ return {'namespace': self.namespace.GetName(),
+ 'documentation_permissions_required': self.permissions,
+ 'nodoc': self.nodoc,
+ 'description': self.description,
+ 'types': self.types,
+ 'events': self.events,
+ 'functions': self.functions}
def process_interface(self, node):
members = []
@@ -266,23 +290,28 @@ class IDLSchema(object):
def process(self):
namespaces = []
+ description = ''
+ nodoc = False
+ permissions = None
for node in self.idl:
- nodoc = False
cls = node.cls
if cls == 'Namespace':
- namespace = Namespace(node, nodoc)
+ namespace = Namespace(node, description, nodoc, permissions)
namespaces.append(namespace.process())
elif cls == 'Copyright':
continue
elif cls == 'Comment':
+ description = ProcessComment(node.GetName())[0]
continue
elif cls == 'ExtAttribute':
if node.name == 'nodoc':
nodoc = bool(node.value)
+ elif node.name == 'permissions':
+ permissions = node.value.split(',')
else:
continue
else:
- sys.exit("Did not process %s %s" % (node.cls, node))
+ sys.exit('Did not process %s %s' % (node.cls, node))
schema_util.PrefixSchemasWithNamespace(namespaces)
return namespaces

Powered by Google App Engine
This is Rietveld 408576698