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

Side by Side Diff: chrome/common/extensions/docs/build/directory.py

Issue 10639020: Switch the downloads API over to IDL/json_schema_compiler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 5 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 | Annotate | Revision Log
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 """Class for parsing metadata about extension samples.""" 5 """Class for parsing metadata about extension samples."""
6 6
7 import locale 7 import locale
8 import os 8 import os
9 import os.path 9 import os.path
10 import re 10 import re
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 def parse_idl_file(path): 77 def parse_idl_file(path):
78 """ Load the specified file and parse it as IDL. 78 """ Load the specified file and parse it as IDL.
79 79
80 Args: 80 Args:
81 path: Path to a file containing JSON-encoded data. 81 path: Path to a file containing JSON-encoded data.
82 """ 82 """
83 api_def = idl_schema.Load(path) 83 api_def = idl_schema.Load(path)
84 for namespace_def in api_def: 84 for namespace_def in api_def:
85 namespace_dot = namespace_def['namespace'] + '.' 85 namespace_dot = namespace_def['namespace'] + '.'
86 types = dict((type_['id'], type_) 86 inline_types = dict((type_['id'], type_)
87 for type_ in namespace_def.get('types', []) 87 for type_ in namespace_def.get('types', [])
88 if type_) 88 if type_ and type_.get('inline_doc', False))
89 def SubstituteInlineDoc(prop): 89 def SubstituteInlineDoc(prop):
90 prop_ref_type = prop.get('$ref', '') 90 prop_ref_type = prop.get('$ref', '')
91 type_obj = types.get(namespace_dot + prop_ref_type, 91 type_obj = inline_types.get(namespace_dot + prop_ref_type,
92 types.get(prop_ref_type, {})) 92 inline_types.get(prop_ref_type, {}))
93 if not type_obj: 93 if not type_obj:
94 return 94 return
95 if 'properties' in type_obj: 95 if 'properties' in type_obj:
96 del prop['$ref'] 96 del prop['$ref']
97 prop['properties'] = dict(type_obj['properties']) 97 prop['properties'] = dict(type_obj['properties'])
98 prop['type'] = 'object' 98 prop['type'] = 'object'
99 for sub_prop in prop['properties'].values(): 99 for sub_prop in prop['properties'].values():
100 if isinstance(sub_prop, dict): 100 if isinstance(sub_prop, dict):
101 if 'nodoc' in sub_prop: 101 if 'nodoc' in sub_prop:
102 del sub_prop['nodoc'] 102 del sub_prop['nodoc']
103 if 'name' in sub_prop: 103 if 'name' in sub_prop:
104 del sub_prop['name'] 104 del sub_prop['name']
105 elif 'enum' in type_obj and 'type' in type_obj: 105 elif 'enum' in type_obj and 'type' in type_obj:
106 del prop['$ref'] 106 del prop['$ref']
107 prop['type'] = type_obj['type'] 107 prop['type'] = type_obj['type']
108 prop['enum'] = type_obj['enum'] 108 prop['enum'] = type_obj['enum']
109 def FixReferences(prop): 109 def FixReferences(prop):
110 # Strip namespace_dot from $ref names. 110 # Strip namespace_dot from $ref names.
111 if prop.get('$ref', '').startswith(namespace_dot): 111 if prop.get('$ref', '').startswith(namespace_dot):
112 prop['$ref'] = prop['$ref'][len(namespace_dot):] 112 prop['$ref'] = prop['$ref'][len(namespace_dot):]
113 if (prop.get('type', '') == 'array' and 113 if (prop.get('type', '') == 'array' and
114 prop.get('items', {}).get('$ref', '').startswith(namespace_dot)): 114 prop.get('items', {}).get('$ref', '').startswith(namespace_dot)):
115 prop['items']['$ref'] = prop['items']['$ref'][len(namespace_dot):] 115 prop['items']['$ref'] = prop['items']['$ref'][len(namespace_dot):]
116 if prop.get('inline_doc', False): 116 SubstituteInlineDoc(prop)
117 del prop['inline_doc'] 117 if 'items' in prop:
118 SubstituteInlineDoc(prop) 118 SubstituteInlineDoc(prop['items'])
119 if 'items' in prop:
120 SubstituteInlineDoc(prop['items'])
121 119
122 for type_ in namespace_def.get('types', []): 120 for type_ in namespace_def.get('types', []):
123 if type_.get('id', '').startswith(namespace_dot): 121 if type_.get('id', '').startswith(namespace_dot):
124 type_['id'] = type_['id'][len(namespace_dot):] 122 type_['id'] = type_['id'][len(namespace_dot):]
125 for prop in type_.get('properties', {}).values(): 123 for prop in type_.get('properties', {}).values():
126 FixReferences(prop) 124 FixReferences(prop)
125 if type_.get('inline_doc', False):
126 del type_['inline_doc']
127 type_['nodoc'] = True
127 for func in namespace_def.get('functions', []): 128 for func in namespace_def.get('functions', []):
128 for param in func.get('parameters', []): 129 for param in func.get('parameters', []):
129 FixReferences(param) 130 FixReferences(param)
130 for cb_param in param.get('parameters', []): 131 for cb_param in param.get('parameters', []):
131 FixReferences(cb_param) 132 FixReferences(cb_param)
132 for event in namespace_def.get('events', []): 133 for event in namespace_def.get('events', []):
133 for param in event.get('parameters', []): 134 for param in event.get('parameters', []):
134 FixReferences(param) 135 FixReferences(param)
135 return api_def 136 return api_def
136 137
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 zip_file.write(abspath, relpath) 862 zip_file.write(abspath, relpath)
862 if file == 'manifest.json': 863 if file == 'manifest.json':
863 info = zip_file.getinfo(zip_manifest_path) 864 info = zip_file.getinfo(zip_manifest_path)
864 info.comment = self['source_hash'] 865 info.comment = self['source_hash']
865 except RuntimeError, msg: 866 except RuntimeError, msg:
866 raise Exception("Could not write zip at %s: %s" % (zip_path, msg)) 867 raise Exception("Could not write zip at %s: %s" % (zip_path, msg))
867 finally: 868 finally:
868 zip_file.close() 869 zip_file.close()
869 870
870 return self._get_relative_zip_path() 871 return self._get_relative_zip_path()
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/extension_api.cc ('k') | chrome/common/extensions/docs/extensions/downloads.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698